int lengthOfTask = maxEstimation / delay; // タスクの長さ = 最大予想時間 / 割り込み間隔
String message = "ログイン";
String note = "認証中...";
Task task = new Task<UserModel>(view, message, note, maxEstimation) {
@Override
protected UserModel doInBackground() throws Exception {
// ログイン手順開始
String pk = principal.getFacilityId() + ":" + principal.getUserId();
// LoginContext, SecurityAssociation は廃止されて,EJBClientContext を使うようになった
Properties props = new Properties();
props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
props.put("remote.connections", "default");
props.put("remote.connection.default.host", Project.getHostAddress());
props.put("remote.connection.default.port", String.valueOf(Project.getHostPort()));
props.put("remote.connection.default.username", pk);
props.put("remote.connection.default.password", password.toString());
//props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
// create client configuration
final EJBClientConfiguration clientConfiguration = new PropertiesBasedEJBClientConfiguration(props);
// create a context selector
final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(clientConfiguration);
// set the selector for use
EJBClientContext.setSelector(contextSelector);
return userDlg.getUser(pk);
}
@Override
protected void succeeded(UserModel userModel) {
part11Logger.debug("Task succeeded");
if (userModel != null) {
Project.UserType userType = Project.UserType.valueOf(userModel.getMemberType());
part11Logger.info("User Type = " + userType.toString());
// 認証成功
String time = ModelUtils.getDateTimeAsString(new Date());
part11Logger.info(time + ": " + userModel.getUserId() + " がログインしました");
// ユーザID、施設ID、ユーザモデルを rojectStub へ保存する
Project.getProjectStub().setUserId(principal.getUserId());
Project.getProjectStub().setUserModel(userModel);
Project.getProjectStub().setDolphinPrincipal(principal);
Project.getProjectStub().setUserPassword(password);
result = LoginStatus.AUTHENTICATED;
notifyClose(result);
} else {
part11Logger.warn("User == null, this never ocuured");
}
}
@Override
protected void failed(java.lang.Throwable cause) {
part11Logger.warn("Task failed");
part11Logger.warn(cause.getCause());
part11Logger.warn(cause.getMessage());
if (tryCount <= maxTryCount && cause instanceof Exception) {
userDlg.processError((Exception) cause);
String errMsg = userDlg.getErrorMessage();
showMessageDialog(errMsg);
} else {
StringBuilder sb = new StringBuilder();
userDlg.processError((Exception) cause);
sb.append(userDlg.getErrorMessage());
sb.append("\n");
sb.append(ClientContext.getString("loginDialog.forceClose"));
String msg = sb.toString();
showMessageDialog(msg);
result = LoginStatus.NOT_AUTHENTICATED;
notifyClose(result);
}
}
};
task.setInputBlocker(new Blocker());
task.setMillisToDecidePopup(3000);
task.execute();
}