use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class UserDbDriver method getUserInfos.
/**
* getModel method comment.
*/
public UserInfo[] getUserInfos(Connection con) throws SQLException, DataAccessException, ObjectNotFoundException {
if (lg.isTraceEnabled()) {
lg.trace("UserDbDriver.getUserInfos()");
}
String sql;
sql = " SELECT " + " * " + " FROM " + userTable.getTableName();
// System.out.println(sql);
// Connection con = conFact.getConnection();
Statement stmt = con.createStatement();
java.util.Vector<UserInfo> userList = null;
try {
ResultSet rset = stmt.executeQuery(sql);
// ResultSetMetaData metaData = rset.getMetaData();
// for (int i=1;i<=metaData.getColumnCount();i++){
// System.out.println("column("+i+") = "+metaData.getColumnName(i));
// }
userList = new java.util.Vector<UserInfo>();
UserInfo userInfo;
while (rset.next()) {
userInfo = userTable.getUserInfo(rset);
userList.addElement(userInfo);
}
} finally {
// Release resources include resultset
stmt.close();
}
if (userList.size() > 0) {
UserInfo[] users = new UserInfo[userList.size()];
userList.copyInto(users);
return users;
} else {
return null;
}
}
use of org.vcell.util.document.UserInfo in project vcell by virtualcell.
the class VCDatabaseScanner method getAllUsers.
public User[] getAllUsers() throws DataAccessException {
if (allUsers == null) {
UserInfo[] allUserInfos = localAdminDbServer.getUserInfos();
allUsers = new User[allUserInfos.length];
for (int i = 0; i < allUserInfos.length; i++) {
allUsers[i] = new User(allUserInfos[i].userid, allUserInfos[i].id);
}
}
return allUsers;
}
use of org.vcell.util.document.UserInfo 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.document.UserInfo in project vcell by virtualcell.
the class VCellApiMain method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
if (args.length != 2) {
System.out.println("usage: VCellApiMain javascriptDir port");
System.exit(1);
}
File javascriptDir = new File(args[0]);
if (!javascriptDir.isDirectory()) {
throw new RuntimeException("javascriptDir '" + args[0] + "' is not a directory");
}
// don't validate
PropertyLoader.loadProperties();
lg.debug("properties loaded");
String portString = args[1];
// was hard-coded at 8080
Integer port = null;
try {
port = Integer.parseInt(portString);
} catch (NumberFormatException e) {
e.printStackTrace();
throw new RuntimeException("failed to parse port argument '" + portString + "'", e);
}
lg.trace("connecting to database");
lg.trace("oracle factory (next)");
ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
KeyFactory keyFactory = conFactory.getKeyFactory();
lg.trace("database impl (next)");
DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
lg.trace("local db server (next)");
LocalAdminDbServer localAdminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
lg.trace("admin db server (next)");
AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
lg.trace("messaging service (next)");
VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new VCMessagingDelegate() {
@Override
public void onTraceEvent(String string) {
System.out.println("Trace: " + string);
}
@Override
public void onRpcRequestSent(VCRpcRequest vcRpcRequest, UserLoginInfo userLoginInfo, VCMessage vcRpcRequestMessage) {
System.out.println("request sent:");
}
@Override
public void onRpcRequestProcessed(VCRpcRequest vcRpcRequest, VCMessage rpcVCMessage) {
System.out.println("request processed:");
}
@Override
public void onMessageSent(VCMessage message, VCDestination desintation) {
System.out.println("message sent:");
}
@Override
public void onMessageReceived(VCMessage vcMessage, VCDestination vcDestination) {
System.out.println("message received");
}
@Override
public void onException(Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}
});
lg.trace("rest database service (next)");
RestDatabaseService restDatabaseService = new RestDatabaseService(databaseServerImpl, localAdminDbServer, vcMessagingService);
lg.trace("rest event service (next)");
RestEventService restEventService = new RestEventService(vcMessagingService);
lg.trace("use verifier (next)");
UserVerifier userVerifier = new UserVerifier(adminDbTopLevel);
lg.trace("mongo (next)");
VCMongoMessage.enabled = true;
VCMongoMessage.serviceStartup(ServiceName.unknown, port, args);
System.out.println("setting up server configuration");
lg.trace("register engine (next)");
Engine.register(true);
WadlComponent component = new WadlComponent();
// Server httpServer = component.getServers().add(Protocol.HTTP, 80);
// Server httpsServer = component.getServers().add(Protocol.HTTPS, 443);
// Client httpsClient = component.getClients().add(Protocol.HTTPS);
// Client httpClient = component.getClients().add(Protocol.HTTP);
lg.trace("adding FILE protcol");
@SuppressWarnings("unused") Client httpClient = component.getClients().add(Protocol.FILE);
lg.trace("adding CLAP protcol");
@SuppressWarnings("unused") Client clapClient = component.getClients().add(Protocol.CLAP);
lg.trace("adding CLAP https");
File keystorePath = new File(PropertyLoader.getRequiredProperty(PropertyLoader.vcellapiKeystoreFile));
String keystorePassword = PropertyLoader.getSecretValue(PropertyLoader.vcellapiKeystorePswd, PropertyLoader.vcellapiKeystorePswdFile);
try {
//
// keystorePassword may be encrypted with dbPassword, if it is decypt it.
//
String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = kf.generateSecret(new PBEKeySpec(dbPassword.toCharArray()));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(new byte[] { 32, 11, 55, 121, 01, 42, 89, 11 }, 20));
keystorePassword = new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(keystorePassword)));
} catch (Exception e) {
System.out.println("password unhashing didn't work - trying clear text password");
e.printStackTrace();
}
Server httpsServer = component.getServers().add(Protocol.HTTPS, port);
Series<Parameter> parameters = httpsServer.getContext().getParameters();
parameters.add("keystorePath", keystorePath.toString());
parameters.add("keystorePassword", keystorePassword);
parameters.add("keystoreType", "JKS");
parameters.add("keyPassword", keystorePassword);
parameters.add("disabledCipherSuites", "SSL_RSA_WITH_3DES_EDE_CBC_SHA " + "SSL_DHE_RSA_WITH_DES_CBC_SHA " + "SSL_DHE_DSS_WITH_DES_CBC_SHA");
parameters.add("enabledCipherSuites", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA " + "TLS_RSA_WITH_AES_128_CBC_SHA " + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA " + "TLS_RSA_WITH_AES_256_CBC_SHA");
lg.trace("create config");
Configuration templateConfiguration = new Configuration();
templateConfiguration.setObjectWrapper(new DefaultObjectWrapper());
lg.trace("verify python installation");
PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.COPASI, PythonPackage.LIBSBML, PythonPackage.THRIFT });
lg.trace("start Optimization Service");
OptServerImpl optServerImpl = new OptServerImpl();
optServerImpl.start();
lg.trace("create app");
boolean bIgnoreHostProblems = true;
boolean bIgnoreCertProblems = true;
User testUser = localAdminDbServer.getUser(TEST_USER);
// lookup hashed auth credentials in database.
UserInfo testUserInfo = localAdminDbServer.getUserInfo(testUser.getID());
HealthService healthService = new HealthService(restEventService, "localhost", port, bIgnoreCertProblems, bIgnoreHostProblems, testUserInfo.userid, testUserInfo.digestedPassword0);
AdminService adminService = new AdminService(adminDbTopLevel, databaseServerImpl);
RpcService rpcService = new RpcService(vcMessagingService);
WadlApplication app = new VCellApiApplication(restDatabaseService, userVerifier, optServerImpl, rpcService, restEventService, adminService, templateConfiguration, healthService, javascriptDir);
lg.trace("attach app");
component.getDefaultHost().attach(app);
System.out.println("component start()");
lg.trace("start component");
component.start();
System.out.println("component ended.");
lg.trace("component started");
lg.trace("start VCell Health Monitoring service");
healthService.start();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of org.vcell.util.document.UserInfo 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