use of org.vcell.util.document.UserLoginInfo.DigestedPassword in project vcell by virtualcell.
the class NewUserRestlet method handle.
@Override
public void handle(Request request, Response response) {
if (request.getMethod().equals(Method.POST)) {
Representation entity = request.getEntity();
if (entity.getMediaType().equals(MediaType.APPLICATION_JSON)) {
handleJsonRequest(request, response);
return;
}
String content = request.getEntityAsText();
System.out.println(content);
Form form = new Form(entity);
String userid = form.getFirstValue(VCellApiApplication.NEWUSERID_FORMNAME, "");
String password1 = form.getFirstValue(VCellApiApplication.NEWPASSWORD1_FORMNAME, "");
String password2 = form.getFirstValue(VCellApiApplication.NEWPASSWORD2_FORMNAME, "");
String email = form.getFirstValue(VCellApiApplication.NEWEMAIL_FORMNAME, "");
String firstName = form.getFirstValue(VCellApiApplication.NEWFIRSTNAME_FORMNAME, "");
String lastName = form.getFirstValue(VCellApiApplication.NEWLASTNAME_FORMNAME, "");
String institute = form.getFirstValue(VCellApiApplication.NEWINSTITUTE_FORMNAME, "");
String country = form.getFirstValue(VCellApiApplication.NEWCOUNTRY_FORMNAME, "");
String notify = form.getFirstValue(VCellApiApplication.NEWNOTIFY_FORMNAME, "on");
String formprocessing = form.getFirstValue(VCellApiApplication.NEWFORMPROCESSING_FORMNAME, null);
Status status = null;
String errorMessage = "";
// validate
if (!password1.equals(password2)) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "passwords dont match";
}
int MIN_PASSWORD_LENGTH = 5;
if (password1.length() < MIN_PASSWORD_LENGTH || password1.contains(" ") || password1.contains("'") || password1.contains("\"") || password1.contains(",")) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "password must be at least " + MIN_PASSWORD_LENGTH + " characters, and must not contains spaces, commas, or quotes";
}
if (email.length() < 4) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "valid email required";
}
if (userid.length() < 4 || !userid.equals(org.vcell.util.TokenMangler.fixTokenStrict(userid))) {
status = Status.CLIENT_ERROR_FORBIDDEN;
errorMessage = "userid must be at least 4 characters and contain only alpha-numeric characters";
}
if (errorMessage.length() > 0 && formprocessing != null) {
Form newform = new Form();
newform.add(VCellApiApplication.NEWERRORMESSAGE_FORMNAME, errorMessage);
newform.add(VCellApiApplication.NEWUSERID_FORMNAME, userid);
newform.add(VCellApiApplication.NEWPASSWORD1_FORMNAME, password1);
newform.add(VCellApiApplication.NEWPASSWORD2_FORMNAME, password2);
newform.add(VCellApiApplication.NEWEMAIL_FORMNAME, email);
newform.add(VCellApiApplication.NEWFIRSTNAME_FORMNAME, firstName);
newform.add(VCellApiApplication.NEWLASTNAME_FORMNAME, lastName);
newform.add(VCellApiApplication.NEWINSTITUTE_FORMNAME, institute);
newform.add(VCellApiApplication.NEWCOUNTRY_FORMNAME, country);
newform.add(VCellApiApplication.NEWNOTIFY_FORMNAME, notify);
Reference redirectRef;
try {
redirectRef = new Reference(request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.REGISTRATIONFORM + "?" + newform.encode());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
response.redirectSeeOther(redirectRef);
return;
}
// form new UnverifiedUserInfo
UserInfo newUserInfo = new UserInfo();
newUserInfo.company = institute;
newUserInfo.country = country;
newUserInfo.digestedPassword0 = new DigestedPassword(password1);
newUserInfo.email = email;
newUserInfo.wholeName = firstName + " " + lastName;
newUserInfo.notify = notify.equals("on");
newUserInfo.title = " ";
newUserInfo.userid = userid;
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);
}
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);
}
}
use of org.vcell.util.document.UserLoginInfo.DigestedPassword in project vcell by virtualcell.
the class UserVerifier method authenticateUser.
public User authenticateUser(String userid, char[] secret) {
DigestedPassword digestedPassword = UserLoginInfo.DigestedPassword.createAlreadyDigested(new String(secret));
AuthenticationInfo authInfo = useridMap.get(userid);
if (authInfo != null) {
if (authInfo.digestedPassword.equals(digestedPassword)) {
return authInfo.user;
}
}
if ((System.currentTimeMillis() - lastQueryTimestampMS) > MIN_QUERY_TIME_MS) {
synchronized (adminDbTopLevel) {
User user = null;
try {
user = adminDbTopLevel.getUser(userid, digestedPassword, true, false);
} catch (ObjectNotFoundException e) {
e.printStackTrace();
} catch (DataAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
// refresh stored list of user infos (for authentication)
if (user != null) {
useridMap.put(userid, new AuthenticationInfo(user, digestedPassword));
}
lastQueryTimestampMS = System.currentTimeMillis();
return user;
}
} else {
return null;
}
}
use of org.vcell.util.document.UserLoginInfo.DigestedPassword in project vcell by virtualcell.
the class VCellClient method login.
public static void login(final RequestManager requestManager, final ClientServerInfo clientServerInfo, final DocumentWindowManager currWindowManager) {
final LoginManager loginManager = new LoginManager();
LoginDelegate loginDelegate = new LoginDelegate() {
public void login(final String userid, final UserLoginInfo.DigestedPassword digestedPassword) {
AsynchClientTask task1 = new AsynchClientTask("connect to server", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ClientServerInfo newClientServerInfo = createClientServerInfo(clientServerInfo, userid, digestedPassword);
requestManager.connectToServer(currWindowManager, newClientServerInfo);
}
};
AsynchClientTask task2 = new AsynchClientTask("logging in", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ConnectionStatus connectionStatus = requestManager.getConnectionStatus();
loginManager.close();
if (connectionStatus.getStatus() != ConnectionStatus.CONNECTED) {
VCellClient.login(requestManager, clientServerInfo, currWindowManager);
} else {
ErrorUtils.setLoginInfo(clientServerInfo.getUserLoginInfo());
}
}
};
ClientTaskDispatcher.dispatch(currWindowManager.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
public void registerRequest() {
loginManager.close();
try {
UserRegistrationManager.registrationOperationGUI(requestManager, currWindowManager, clientServerInfo, LoginManager.USERACTION_REGISTER, null);
} catch (UserCancelException e) {
// do nothing
} catch (Exception e) {
e.printStackTrace();
PopupGenerator.showErrorDialog(currWindowManager, "New user Registration error:\n" + e.getMessage());
}
}
public void lostPasswordRequest(String userid) {
try {
ClientServerInfo newClientServerInfo = createClientServerInfo(clientServerInfo, userid, null);
UserRegistrationManager.registrationOperationGUI(requestManager, currWindowManager, newClientServerInfo, LoginManager.USERACTION_LOSTPASSWORD, null);
} catch (UserCancelException e) {
// do nothing
} catch (Exception e) {
e.printStackTrace();
PopupGenerator.showErrorDialog(currWindowManager, "New user Registration error:\n" + e.getMessage());
}
}
public void userCancel() {
loginManager.close();
PopupGenerator.showInfoDialog(currWindowManager, "Note: The Login dialog can be accessed any time under the 'Server' main menu as 'Change User...'");
}
};
loginManager.showLoginDialog(currWindowManager.getComponent(), currWindowManager, loginDelegate);
}
use of org.vcell.util.document.UserLoginInfo.DigestedPassword in project vcell by virtualcell.
the class ClientFactory method createRemoteClientServerManager.
public static ClientServerManager createRemoteClientServerManager(String apihost, Integer apiport, String username, String password) {
DigestedPassword digestedPassword = new DigestedPassword(password);
ClientServerInfo csInfo = ClientServerInfo.createRemoteServerInfo(apihost, apiport, username, digestedPassword);
InteractiveContextDefaultProvider defaultInteractiveContextProvider = new VCellGuiInteractiveContextDefaultProvider();
ClientServerManager clientServerManager = new ClientServerManager(csInfo, defaultInteractiveContextProvider);
RequestManagerAdapter requestManager = new RequestManagerAdapter();
TopLevelWindowManager windowManager = new TopLevelWindowManager(requestManager) {
@Override
public Component getComponent() {
return null;
}
@Override
public String getManagerID() {
return null;
}
@Override
public boolean isRecyclable() {
return false;
}
};
InteractiveContext requester = new VCellGuiInteractiveContext(windowManager);
clientServerManager.connect(requester);
return clientServerManager;
}
use of org.vcell.util.document.UserLoginInfo.DigestedPassword in project vcell by virtualcell.
the class ClientFactory method createLocalClientServerManager.
public static ClientServerManager createLocalClientServerManager(String userid, String password) {
DigestedPassword digestedPassword = new DigestedPassword(password);
ClientServerInfo csInfo = ClientServerInfo.createLocalServerInfo(userid, digestedPassword);
InteractiveContextDefaultProvider defaultInteractiveContextProvider = new VCellGuiInteractiveContextDefaultProvider();
ClientServerManager clientServerManager = new ClientServerManager(csInfo, defaultInteractiveContextProvider);
clientServerManager.connect(null);
return clientServerManager;
}
Aggregations