use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.
the class TestRestServerBlinov method getVCellApiApplication.
public static VCellApiApplication getVCellApiApplication() throws DataAccessException {
return new VCellApiApplication(getRestDatabaseService(), null, null, null, null, new Configuration(), null, null) {
@Override
public Restlet createInboundRoot() {
// TODO Auto-generated method stub
Router rootRouter = new Router(getContext());
// rootRouter.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
rootRouter.attach("/" + BIOMODEL, BiomodelsServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}", BiomodelServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SBML_DOWNLOAD, BiomodelSBMLServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + VCML_DOWNLOAD, BiomodelVCMLServerResource.class);
return rootRouter;
}
@Override
public User getVCellUser(ChallengeResponse response, AuthenticationPolicy authPolicy) {
// TODO Auto-generated method stub
return new User("gsoc", new KeyValue("0"));
}
};
}
use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.
the class LostPasswordRestlet method handle.
@Override
public void handle(Request request, Response response) {
if (request.getMethod().equals(Method.POST)) {
System.out.println("in LostPasswordRestlet.handle()");
String userid = request.getEntityAsText();
if (userid == null || userid.length() == 0) {
response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
response.setEntity("expecting username in body", MediaType.TEXT_PLAIN);
return;
}
// first line of defense against sql insertion attacks.
if (!TokenMangler.fixTokenStrict(userid).equals(userid)) {
response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
response.setEntity("unexpected characters in userid '" + userid + "'", MediaType.TEXT_PLAIN);
return;
}
try {
VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
vcellApiApplication.getRestDatabaseService().sendLostPassword(userid);
} catch (Exception e) {
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("we failed to send a verification email for account '" + userid + "': " + e.getMessage(), MediaType.TEXT_PLAIN);
return;
}
response.setStatus(Status.SUCCESS_ACCEPTED);
response.setEntity("we sent you a lost password email, please follow the link in that email", MediaType.TEXT_PLAIN);
}
}
use of org.vcell.rest.VCellApiApplication in project vcell by virtualcell.
the class SimulationTasksServerResource method getSimulationTaskRepresentations.
private SimulationTaskRepresentation[] getSimulationTaskRepresentations(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
ArrayList<SimulationTaskRepresentation> simTaskReps = new ArrayList<SimulationTaskRepresentation>();
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
SimpleJobStatus[] simJobStatusList = restDatabaseService.query(this, vcellUser);
for (SimpleJobStatus simpleJobStatus : simJobStatusList) {
SimulationTaskRepresentation simTaskRep = new SimulationTaskRepresentation(simpleJobStatus);
simTaskReps.add(simTaskRep);
}
} catch (PermissionException ee) {
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (DataAccessException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
}
return simTaskReps.toArray(new SimulationTaskRepresentation[0]);
// }
}
use of org.vcell.rest.VCellApiApplication 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.rest.VCellApiApplication in project vcell by virtualcell.
the class LoginRestlet method handle.
@Override
public void handle(Request request, Response response) {
// String html =
// "<html>" +
// "/login ... should have been redirected."+
// "</html>";
// response.setEntity(html, MediaType.TEXT_HTML);
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(request.getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
String jsonString = "{}";
if (vcellUser != null) {
jsonString = "{user: \"" + vcellUser.getName() + "\"}";
}
response.setEntity(new JsonRepresentation(jsonString));
}
Aggregations