Search in sources :

Example 11 with VCellApiApplication

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"));
        }
    };
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Configuration(freemarker.template.Configuration) VCellApiApplication(org.vcell.rest.VCellApiApplication) Router(org.restlet.routing.Router) ChallengeResponse(org.restlet.data.ChallengeResponse)

Example 12 with VCellApiApplication

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);
    }
}
Also used : VCellApiApplication(org.vcell.rest.VCellApiApplication) IOException(java.io.IOException)

Example 13 with VCellApiApplication

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]);
// }
}
Also used : SimulationTaskRepresentation(org.vcell.rest.common.SimulationTaskRepresentation) PermissionException(org.vcell.util.PermissionException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) VCellApiApplication(org.vcell.rest.VCellApiApplication) ResourceException(org.restlet.resource.ResourceException) DataAccessException(org.vcell.util.DataAccessException) SimpleJobStatus(cbit.vcell.server.SimpleJobStatus)

Example 14 with VCellApiApplication

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);
        }
    }
}
Also used : Form(org.restlet.data.Form) SQLException(java.sql.SQLException) Reference(org.restlet.data.Reference) VCellApiApplication(org.vcell.rest.VCellApiApplication) UseridIDExistsException(org.vcell.util.UseridIDExistsException) IOException(java.io.IOException) Date(java.util.Date) DataAccessException(org.vcell.util.DataAccessException)

Example 15 with VCellApiApplication

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));
}
Also used : User(org.vcell.util.document.User) VCellApiApplication(org.vcell.rest.VCellApiApplication) JsonRepresentation(org.restlet.ext.json.JsonRepresentation)

Aggregations

VCellApiApplication (org.vcell.rest.VCellApiApplication)53 User (org.vcell.util.document.User)34 ResourceException (org.restlet.resource.ResourceException)21 PermissionException (org.vcell.util.PermissionException)20 Gson (com.google.gson.Gson)14 Representation (org.restlet.representation.Representation)14 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)14 HashMap (java.util.HashMap)13 Configuration (freemarker.template.Configuration)12 TemplateRepresentation (org.restlet.ext.freemarker.TemplateRepresentation)11 ClientResource (org.restlet.resource.ClientResource)11 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)9 Form (org.restlet.data.Form)8 StringRepresentation (org.restlet.representation.StringRepresentation)8 BioModel (cbit.vcell.biomodel.BioModel)6 XMLSource (cbit.vcell.xml.XMLSource)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 BiomodelRepresentation (org.vcell.rest.common.BiomodelRepresentation)6 PublicationRepresentation (org.vcell.rest.common.PublicationRepresentation)6