use of org.vcell.util.UseridIDExistsException in project vcell by virtualcell.
the class EmailTokenVerifyRestlet method handle.
@Override
public void handle(Request request, Response response) {
if (request.getMethod().equals(Method.GET)) {
Form form = request.getResourceRef().getQueryAsForm();
String emailverify_token = form.getFirstValue(VCellApiApplication.EMAILVERIFYTOKEN_FORMNAME);
VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
UnverifiedUser unverifiedUser = vcellApiApplication.getUserVerifier().getUnverifiedUser(emailverify_token);
if (unverifiedUser != null) {
if (unverifiedUser.verificationTimeoutDate.after(new Date())) {
//
try {
vcellApiApplication.getRestDatabaseService().addUser(unverifiedUser.submittedUserInfo);
} catch (SQLException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
} catch (DataAccessException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
} catch (UseridIDExistsException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
}
//
// make default redirect after login (/biomodel).
//
Reference successRedirectRef = new Reference(request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.BIOMODEL);
//
// redirect to login page for user to log in
//
Form newform = new Form();
newform.add(VCellApiApplication.REDIRECTURL_FORMNAME, successRedirectRef.toUrl().toString());
newform.add(VCellApiApplication.IDENTIFIER_FORMNAME, unverifiedUser.submittedUserInfo.userid);
newform.add(VCellApiApplication.SECRET_FORMNAME, "");
Reference redirectRef;
try {
redirectRef = new Reference(request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.LOGINFORM + "?" + newform.encode());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
response.redirectSeeOther(redirectRef);
return;
} else {
response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
response.setEntity("email verification expired, please register again at " + request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.REGISTRATIONFORM, MediaType.TEXT_PLAIN);
}
} else {
response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
response.setEntity("email verification not found, please register again at " + request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.REGISTRATIONFORM, MediaType.TEXT_PLAIN);
}
}
}
use of org.vcell.util.UseridIDExistsException in project vcell by virtualcell.
the class AdminDBTopLevel method insertUserInfo.
/**
* This method was created in VisualAge.
* @return cbit.sql.UserInfo
* @param newUserInfo cbit.sql.UserInfo
*/
KeyValue insertUserInfo(UserInfo newUserInfo, boolean bEnableRetry) throws SQLException, UseridIDExistsException {
Object lock = new Object();
Connection con = conFactory.getConnection(lock);
try {
if (userDB.getUserFromUserid(con, newUserInfo.userid) != null) {
throw new UseridIDExistsException("Insert new user failed: username '" + newUserInfo.userid + "' already exists");
}
KeyValue key = userDB.insertUserInfo(con, conFactory.getKeyFactory(), newUserInfo);
con.commit();
return key;
} catch (Throwable e) {
lg.error("failure in insertUserInfo()", e);
if (e instanceof UseridIDExistsException) {
throw (UseridIDExistsException) e;
}
try {
con.rollback();
} catch (Throwable rbe) {
lg.error("exception during rollback, bEnableRetry = " + bEnableRetry, rbe);
}
if (bEnableRetry && isBadConnection(con)) {
conFactory.failed(con, lock);
return insertUserInfo(newUserInfo, false);
} else {
handle_SQLException(e);
// never gets here;
return null;
}
} finally {
conFactory.release(con, lock);
}
}
use of org.vcell.util.UseridIDExistsException in project vcell by virtualcell.
the class UserRegistrationManager method registrationOperationGUI.
public static void registrationOperationGUI(final RequestManager requestManager, final DocumentWindowManager currWindowManager, final ClientServerInfo currentClientServerInfo, final String userAction, final ClientServerManager clientServerManager) throws Exception {
if (!(userAction.equals(LoginManager.USERACTION_REGISTER) || userAction.equals(LoginManager.USERACTION_EDITINFO) || userAction.equals(LoginManager.USERACTION_LOSTPASSWORD))) {
throw new IllegalArgumentException(UserRegistrationOP.class.getName() + ".registrationOperationGUI: Only New registration, Edit UserInfo or Lost Password allowed.");
}
if ((userAction.equals(LoginManager.USERACTION_REGISTER) || userAction.equals(LoginManager.USERACTION_LOSTPASSWORD)) && clientServerManager != null) {
throw new IllegalArgumentException(UserRegistrationOP.class.getName() + ".registrationOperationGUI: Register New User Info requires clientServerManager null.");
}
if (userAction.equals(LoginManager.USERACTION_EDITINFO) && clientServerManager == null) {
throw new IllegalArgumentException(UserRegistrationOP.class.getName() + ".registrationOperationGUI: Edit User Info requires clientServerManager not null.");
}
RegistrationService registrationService = null;
if (clientServerManager != null) {
registrationService = clientServerManager.getRegistrationProvider();
} else {
registrationService = VCellServiceHelper.getInstance().loadService(RegistrationService.class);
}
if (userAction.equals(LoginManager.USERACTION_LOSTPASSWORD)) {
if (currentClientServerInfo.getUsername() == null || currentClientServerInfo.getUsername().length() == 0) {
throw new IllegalArgumentException("Lost Password requires a VCell User Name.");
}
String result = PopupGenerator.showWarningDialog(currWindowManager, null, new UserMessage("Sending Password via email for user '" + currentClientServerInfo.getUsername() + "'\nusing currently registered email address.", new String[] { "OK", "Cancel" }, "OK"), null);
if (!result.equals("OK")) {
throw UserCancelException.CANCEL_GENERIC;
}
registrationService.sendLostPassword(currentClientServerInfo.getUsername());
return;
}
final RegistrationService finalRegistrationProvider = registrationService;
final String ORIGINAL_USER_INFO_HOLDER = "originalUserInfoHolder";
// final String DIGESTED_USERIDS_KEY = "DIGESTED_USERIDS_KEY";
AsynchClientTask gatherInfoTask = new AsynchClientTask("gathering user info for updating", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (userAction.equals(LoginManager.USERACTION_EDITINFO)) {
UserInfo originalUserInfoHolder = finalRegistrationProvider.getUserInfo(clientServerManager.getUser().getID());
hashTable.put(ORIGINAL_USER_INFO_HOLDER, originalUserInfoHolder);
}
}
};
final String NEW_USER_INFO_KEY = "NEW_USER_INFO_KEY";
AsynchClientTask showPanelTask = new AsynchClientTask("please fill the user registration form", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (registrationPanel == null) {
registrationPanel = new RegistrationPanel();
} else {
if (currentClientServerInfo.getUsername() != null) {
// another user already connected
registrationPanel.reset();
}
}
UserInfo originalUserInfoHolder = (UserInfo) hashTable.get(ORIGINAL_USER_INFO_HOLDER);
;
if (userAction.equals(LoginManager.USERACTION_EDITINFO) && originalUserInfoHolder != null) {
registrationPanel.setUserInfo(originalUserInfoHolder, true);
}
do {
int result = DialogUtils.showComponentOKCancelDialog(currWindowManager.getComponent(), registrationPanel, (userAction.equals(LoginManager.USERACTION_REGISTER) ? "Create New User Registration" : "Update Registration Information (" + clientServerManager.getUser().getName() + ")"));
if (result != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
UserRegistrationOP.NewPasswordUserInfo newUserInfo = registrationPanel.getUserInfo();
if (userAction.equals(LoginManager.USERACTION_EDITINFO)) {
// set existing digestPassword
if (newUserInfo.digestedPassword0 == null && originalUserInfoHolder.digestedPassword0 != null) {
newUserInfo.digestedPassword0 = originalUserInfoHolder.digestedPassword0;
}
if (newUserInfo.otherDigestedPassword == null && originalUserInfoHolder.digestedPassword0 != null) {
newUserInfo.otherDigestedPassword = originalUserInfoHolder.digestedPassword0;
}
}
try {
if (!checkUserInfo(currWindowManager, originalUserInfoHolder, newUserInfo, userAction)) {
PopupGenerator.showInfoDialog(currWindowManager, "No registration information has changed.");
continue;
}
} catch (UserCancelException ex) {
continue;
} catch (Exception ex) {
PopupGenerator.showErrorDialog(currWindowManager, ex.getMessage());
continue;
}
hashTable.put(NEW_USER_INFO_KEY, newUserInfo);
break;
} while (true);
}
};
// final String USERID_NOT_UNIQUE = "USERID_NOT_UNIQUE";
AsynchClientTask updateDbTask = new AsynchClientTask(userAction.equals(LoginManager.USERACTION_REGISTER) ? "registering new user" : "updating user info", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
UserInfo newUserInfo = (UserInfo) hashTable.get(NEW_USER_INFO_KEY);
// }
try {
UserInfo registeredUserInfo = finalRegistrationProvider.insertUserInfo(newUserInfo, (userAction.equals(LoginManager.USERACTION_EDITINFO) ? true : false));
hashTable.put("registeredUserInfo", registeredUserInfo);
} catch (UseridIDExistsException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Error " + (userAction.equals(LoginManager.USERACTION_REGISTER) ? "registering new user" : "updating user info ") + " (" + newUserInfo.userid + "), " + e.getMessage());
}
}
};
AsynchClientTask connectTask = new AsynchClientTask("user logging in", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
UserInfo registeredUserInfo = (UserInfo) hashTable.get("registeredUserInfo");
try {
if (userAction.equals(LoginManager.USERACTION_REGISTER)) {
try {
ClientServerInfo newClientServerInfo = VCellClient.createClientServerInfo(currentClientServerInfo, registeredUserInfo.userid, registeredUserInfo.digestedPassword0);
requestManager.connectToServer(currWindowManager, newClientServerInfo);
} finally {
ConnectionStatus connectionStatus = requestManager.getConnectionStatus();
if (connectionStatus.getStatus() != ConnectionStatus.CONNECTED) {
PopupGenerator.showErrorDialog(currWindowManager, "Automatic login of New user '" + registeredUserInfo.userid + "' failed.\n" + "Restart VCell and login as '" + registeredUserInfo.userid + "' to use new VCell account.");
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Error logging in user " + " (" + registeredUserInfo.userid + "), " + e.getMessage());
}
}
};
AsynchClientTask useridErrorTask = new AsynchClientTask("re-enter userid...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {
@Override
public void run(final Hashtable<String, Object> hashTable) throws Exception {
if (hashTable.containsKey(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR)) {
// retry if requested
if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) instanceof UseridIDExistsException) {
// Exception handled here, suppress ClientTaskDispatcher error dialog.
hashTable.remove(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR);
UserInfo newUserInfo = (UserInfo) hashTable.get(NEW_USER_INFO_KEY);
PopupGenerator.showErrorDialog(currWindowManager, "Login ID '" + newUserInfo.userid + "' cannot be used, enter a different one.");
// Use thread to restart registration process again
new Thread(new Runnable() {
@Override
public void run() {
try {
registrationOperationGUI(requestManager, currWindowManager, currentClientServerInfo, userAction, clientServerManager);
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(currWindowManager.getComponent(), e.getMessage());
}
}
}).start();
}
}
}
};
ClientTaskDispatcher.dispatch(currWindowManager.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { gatherInfoTask, showPanelTask, updateDbTask, connectTask, useridErrorTask }, false);
}
use of org.vcell.util.UseridIDExistsException in project vcell by virtualcell.
the class NewUserRestlet method handleJsonRequest.
private void handleJsonRequest(Request request, Response response) {
String content = request.getEntityAsText();
Gson gson = new Gson();
org.vcell.api.common.UserInfo userinfo = gson.fromJson(content, org.vcell.api.common.UserInfo.class);
if (userinfo.email.length() < 4) {
response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
response.setEntity("valid email required", MediaType.TEXT_PLAIN);
return;
}
if (userinfo.userid.length() < 4 || !userinfo.userid.equals(org.vcell.util.TokenMangler.fixTokenStrict(userinfo.userid))) {
response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
response.setEntity("userid must be at least 4 characters and contain only alpha-numeric characters", MediaType.TEXT_PLAIN);
return;
}
// form new UnverifiedUserInfo
UserInfo newUserInfo = new UserInfo();
newUserInfo.company = userinfo.company;
newUserInfo.country = userinfo.country;
newUserInfo.digestedPassword0 = DigestedPassword.createAlreadyDigested(userinfo.digestedPassword0);
newUserInfo.email = userinfo.email;
newUserInfo.wholeName = userinfo.wholeName;
newUserInfo.notify = userinfo.notify;
newUserInfo.title = userinfo.title;
newUserInfo.userid = userinfo.userid;
boolean bEmailVerification = false;
if (!bEmailVerification) {
// add Unverified UserInfo and send email
VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
try {
UserInfo insertedUserInfo = vcellApiApplication.getRestDatabaseService().addUser(newUserInfo);
org.vcell.api.common.UserInfo inserted = insertedUserInfo.getApiUserInfo();
String userInfoJson = gson.toJson(inserted);
JsonRepresentation userRep = new JsonRepresentation(userInfoJson);
response.setStatus(Status.SUCCESS_CREATED);
response.setEntity(userRep);
return;
} catch (SQLException | DataAccessException | UseridIDExistsException e) {
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("failed to add user " + newUserInfo.userid + ": " + e.getMessage(), MediaType.TEXT_PLAIN);
return;
}
} else {
Date submitDate = new Date();
// one hour
long timeExpiresMS = 1000 * 60 * 60 * 1;
Date expirationDate = new Date(System.currentTimeMillis() + timeExpiresMS);
DigestedPassword emailVerifyToken = new DigestedPassword(Long.toString(System.currentTimeMillis()));
UnverifiedUser unverifiedUser = new UnverifiedUser(newUserInfo, submitDate, expirationDate, emailVerifyToken.getString());
// add Unverified UserInfo and send email
VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
vcellApiApplication.getUserVerifier().addUnverifiedUser(unverifiedUser);
try {
// Send new password to user
PropertyLoader.loadProperties();
BeanUtils.sendSMTP(PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPHostName), new Integer(PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPPort)).intValue(), PropertyLoader.getRequiredProperty(PropertyLoader.vcellSMTPEmailAddress), newUserInfo.email, "new VCell account verification", "You have received this email to verify that a Virtual Cell account has been associated " + "with this email address. To activate this account, please follow this link: " + request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.NEWUSER_VERIFY + "?" + VCellApiApplication.EMAILVERIFYTOKEN_FORMNAME + "=" + emailVerifyToken.getString());
} catch (Exception e) {
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("we failed to send a verification email to " + newUserInfo.email, MediaType.TEXT_PLAIN);
return;
}
response.setStatus(Status.SUCCESS_CREATED);
response.setEntity("we sent you a verification email at " + newUserInfo.email + ", please follow the link in that email", MediaType.TEXT_PLAIN);
}
}
Aggregations