use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class EndSession method handleRedirect.
private Representation handleRedirect(OAuth2Request request, String idToken, String redirectUri) throws RedirectUriMismatchException, InvalidClientException, RelativeRedirectUriException, NotFoundException {
validateRedirect(request, idToken, redirectUri);
Response response = getResponse();
new Redirector(getContext(), new Reference(redirectUri).toString(), Redirector.MODE_CLIENT_FOUND).handle(getRequest(), response);
return response == null ? null : response.getEntity();
}
use of org.restlet.data.Reference in project lucene-solr by apache.
the class TestRestManager method testResolveResourceId.
@Test
public void testResolveResourceId() throws Exception {
Request testRequest = new Request();
Reference rootRef = new Reference("http://solr.apache.org/");
testRequest.setRootRef(rootRef);
Reference resourceRef = new Reference("http://solr.apache.org/schema/analysis/synonyms/de");
testRequest.setResourceRef(resourceRef);
String resourceId = RestManager.ManagedEndpoint.resolveResourceId(testRequest);
assertEquals(resourceId, "/schema/analysis/synonyms/de");
}
use of org.restlet.data.Reference 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.restlet.data.Reference in project vcell by virtualcell.
the class LoginFormRestlet method handle.
@Override
public void handle(Request request, Response response) {
org.restlet.data.Reference reference = request.getReferrerRef();
if (reference == null) {
reference = new Reference(request.getResourceRef().getHostIdentifier() + "/" + VCellApiApplication.BIOMODEL);
}
String html = "<html>" + "<form name='login' action='" + "/" + VCellApiApplication.LOGIN + "' method='post'>" + "VCell userid <input type='text' name='" + VCellApiApplication.IDENTIFIER_FORMNAME + "' value=''/><br/>" + "VCell password <input type='password' name='" + VCellApiApplication.SECRET_FORMNAME + "' value=''/><br/>" + "<input type='hidden' name='" + VCellApiApplication.REDIRECTURL_FORMNAME + "' value='" + reference + "'>" + "<input type='submit' value='sign in'/>" + "</form>" + "</html>";
response.setEntity(html, MediaType.TEXT_HTML);
}
use of org.restlet.data.Reference 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);
}
}
Aggregations