use of org.vcell.rest.users.EmailTokenVerifyRestlet in project vcell by virtualcell.
the class VCellApiApplication method createInboundRoot.
@Override
public Restlet createInboundRoot() {
System.setProperty("java.net.preferIPv4Stack", "true");
/**
* curl --insecure
* "https://nrcamdev5.cam.uchc.edu:8080/access_token?user_id=schaff&user_password=056F4508E0DE1ED22D4D6F541E91460694A00E16&client_id=85133f8d-26f7-4247-8356-d175399fc2e6"
*
* {"token":"9002b7ba-004f-40aa-a639-9136364850a6","creationDateSeconds"
* :1376586968,"expireDateSeconds":1376673368,"userId":"schaff",
* "userKey":"17"}
*
* curl --verbose --insecure -H
* "Authorization: CUSTOM access_token=9002b7ba-004f-40aa-a639-9136364850a6"
* https://nrcamdev5.cam.uchc.edu:8080/simtask?running=on
*
* [{"simKey":"83642386","simName":"Simulation5","userName":"schaff",
* "userKey"
* :"17","htcJobId":"SGE:283488","status":"running","startdate":
* 1375408007000
* ,"jobIndex":0,"taskId":0,"message":"0.7202440000182919","site"
* :"REL","computeHost"
* :"compute-2-0.local","schedulerStatus":"running","hasData"
* :true,"scanCount"
* :1,"bioModelLink":{"bioModelKey":"83642503","bioModelBranchId"
* :"83640470"
* ,"bioModelName":"CSHL 2011 Exercise 6_Jim_2013","simContextKey"
* :"83642357","simContextBranchId":"83642358","simContextName":
* "smoldyn_repressor_activator_oscillations"
* }},{"simKey":"38442198","simName"
* :"Simulation0","userName":"schaff","userKey"
* :"17","status":"running","startdate"
* :1264828384000,"jobIndex":0,"taskId"
* :0,"message":"processing geometry..."
* ,"site":"SCHAFF_WSAD","computeHost"
* :"\u003c\u003clocal\u003e\u003e","schedulerStatus"
* :"running","hasData"
* :false,"scanCount":1,"mathModelLink":{"mathModelKey"
* :"38442201","mathModelBranchId"
* :"38442202","mathModelName":"tempMath77"}}]
*/
// Attach a guard to secure access to user parts of the api
boolean bCookieOptional = true;
final VCellCookieAuthenticator cookieAuthenticator = new VCellCookieAuthenticator(this, bCookieOptional, "My cookie realm", "MyExtraSecretKey".getBytes());
cookieAuthenticator.setLoginPath("/" + LOGIN);
cookieAuthenticator.setLogoutPath("/" + LOGOUT);
cookieAuthenticator.setCookieName("org.vcell.auth");
cookieAuthenticator.setLoginFormPath("/" + LOGINFORM);
cookieAuthenticator.setIdentifierFormName(IDENTIFIER_FORMNAME);
cookieAuthenticator.setSecretFormName(SECRET_FORMNAME);
cookieAuthenticator.setRedirectQueryName(REDIRECTURL_FORMNAME);
cookieAuthenticator.setVerifier(userVerifier);
// 15 minutes (in units of seconds).
cookieAuthenticator.setMaxCookieAge(15 * 60);
String ROOT_URI = javascriptDir.toURI().toString();
String WEBAPP_URI = new File(javascriptDir.getParentFile(), "webapp").toURI().toString();
System.out.println("using uri=" + ROOT_URI + " for scripts directory");
String SCRIPTS = "scripts";
Router rootRouter = new Router(getContext());
rootRouter.attach("/" + SCRIPTS, new Directory(getContext(), ROOT_URI));
rootRouter.attach("/" + ACCESSTOKENRESOURCE, AccessTokenServerResource.class);
rootRouter.attach("/" + WEBAPP, new Directory(getContext(), WEBAPP_URI));
rootRouter.attach("/" + OPTIMIZATION, OptimizationRunServerResource.class);
rootRouter.attach("/" + OPTIMIZATION + "/{" + OPTIMIZATIONID + "}", OptimizationServerResource.class);
rootRouter.attach("/" + PUBLICATION, PublicationsServerResource.class);
rootRouter.attach("/" + PUBLICATION + "/{" + PUBLICATIONID + "}", PublicationServerResource.class);
rootRouter.attach("/" + BIOMODEL, BiomodelsServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}", BiomodelServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + VCML_DOWNLOAD, BiomodelVCMLServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + DIAGRAM_DOWNLOAD, BiomodelDiagramServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}", BiomodelSimulationServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}/" + SAVESIMULATION, BiomodelSimulationSaveServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}/" + STARTSIMULATION, BiomodelSimulationStartServerResource.class);
rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}/" + STOPSIMULATION, BiomodelSimulationStopServerResource.class);
rootRouter.attach("/" + SIMSTATUS, SimulationStatusServerResource.class);
rootRouter.attach("/" + SIMTASK, SimulationTasksServerResource.class);
rootRouter.attach("/" + SIMTASK + "/{" + SIMTASKID + "}", SimulationTaskServerResource.class);
rootRouter.attach("/" + SIMDATA + "/{" + SIMDATAID + "}", SimDataServerResource.class);
rootRouter.attach("/" + SIMDATA + "/{" + SIMDATAID + "}/jobindex/{" + JOBINDEX + "}", SimDataValuesServerResource.class);
rootRouter.attach("/" + LOGIN, new LoginRestlet(getContext()));
rootRouter.attach("/" + LOGINFORM, new LoginFormRestlet(getContext()));
rootRouter.attach("/" + REGISTRATIONFORM, new RegistrationFormRestlet(getContext()));
rootRouter.attach("/" + NEWUSER, new NewUserRestlet(getContext()));
rootRouter.attach("/" + NEWUSER_VERIFY, new EmailTokenVerifyRestlet(getContext()));
rootRouter.attach("/" + LOSTPASSWORD, new LostPasswordRestlet(getContext()));
rootRouter.attach("/" + SWVERSION, new SWVersionRestlet(getContext()));
rootRouter.attach("/" + RPC, new RpcRestlet(getContext()));
rootRouter.attach("/" + EVENTS, new EventsRestlet(getContext()));
rootRouter.attach("/" + HEALTH, new HealthRestlet(getContext()));
rootRouter.attach("/" + ADMIN + "/" + ADMIN_JOBS, new AdminJobsRestlet(getContext()));
rootRouter.attach("/auth/user", new Restlet(getContext()) {
@Override
public void handle(Request request, Response response) {
if (request.getMethod().equals(Method.GET)) {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(request.getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
String jsonString = "{}";
if (vcellUser != null) {
jsonString = "{user: \"" + vcellUser.getName() + "\"}";
}
response.setEntity(new StringRepresentation(jsonString));
}
}
});
cookieAuthenticator.setNext(rootRouter);
return cookieAuthenticator;
}
Aggregations