use of org.restlet.resource.Post in project OpenAM by OpenRock.
the class AuthorizeResource method authorize.
/**
* Handles POST requests to the OAuth2 authorize endpoint.
* <br/>
* This method will be called when a user has given their consent for an authorization request.
*
* @param entity The entity on the request.
* @return The body to be sent in the response to the user agent.
* @throws OAuth2RestletException If a OAuth2 error occurs whilst processing the authorization request.
*/
@Post
public Representation authorize(Representation entity) throws OAuth2RestletException {
final OAuth2Request request = requestFactory.create(getRequest());
for (AuthorizeRequestHook hook : hooks) {
hook.beforeAuthorizeHandling(request, getRequest(), getResponse());
}
final boolean consentGiven = "allow".equalsIgnoreCase(request.<String>getParameter("decision"));
final boolean saveConsent = "on".equalsIgnoreCase(request.<String>getParameter("save_consent"));
try {
final AuthorizationToken authorizationToken = authorizationService.authorize(request, consentGiven, saveConsent);
final String redirectUri = request.getParameter("redirect_uri");
Representation response = representation.toRepresentation(getContext(), getRequest(), getResponse(), authorizationToken, redirectUri);
for (AuthorizeRequestHook hook : hooks) {
hook.afterAuthorizeSuccess(request, getRequest(), getResponse());
}
return response;
} catch (ResourceOwnerAuthenticationRequired e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), e.getRedirectUri().toString(), null);
} catch (InvalidClientException e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), request.<String>getParameter("state"));
} catch (RedirectUriMismatchException e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), request.<String>getParameter("state"));
} catch (OAuth2Exception e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), request.<String>getParameter("redirect_uri"), request.<String>getParameter("state"), e.getParameterLocation());
}
}
use of org.restlet.resource.Post in project netxms by netxms.
the class AbstractHandler method onPost.
/**
* Process POST requests
*
* @param entity
* @return
*/
@Post
public Representation onPost(Representation entity) throws Exception {
if (entity == null) {
log.warn("No POST data in call");
return new StringRepresentation(createErrorResponse(RCC.ACCESS_DENIED).toString(), MediaType.APPLICATION_JSON);
}
JSONObject data = new JsonRepresentation(entity).getJsonObject();
log.debug("POST: data = " + data);
if (attachToSession()) {
return new StringRepresentation(JsonTools.jsonFromObject(create(data), null), MediaType.APPLICATION_JSON);
} else {
return new StringRepresentation(createErrorResponse(RCC.ACCESS_DENIED).toString(), MediaType.APPLICATION_JSON);
}
}
use of org.restlet.resource.Post in project netxms by netxms.
the class AccessIntegrationTools method onPost.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#onPost(org.restlet.representation.Representation)
*/
@Override
@Post
public Representation onPost(Representation entity) throws Exception {
int rc = RCC.ACCESS_DENIED;
if (entity != null) {
JSONObject request = new JsonRepresentation(entity).getJsonObject();
String login = request.getString("login");
String password = request.getString("password");
if ((login != null) || (password != null)) {
NXCSession session = new NXCSession(properties.getServerAddress(), properties.getServerPort());
session.connect();
session.login(login, (password == null) ? "" : password);
if ((session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_EXTERNAL_INTEGRATION) != 0)
rc = RCC.SUCCESS;
session.disconnect();
} else {
log.debug("Login or password not specified in login call");
rc = RCC.INVALID_REQUEST;
}
} else {
log.debug("No POST data in login call");
rc = RCC.INVALID_REQUEST;
}
return new StringRepresentation(createErrorResponse(rc).toString(), MediaType.APPLICATION_JSON);
}
use of org.restlet.resource.Post in project vcell by virtualcell.
the class OptimizationRunServerResource method run.
@Override
@Post
public Representation run(Representation optProblemJson) {
OptSocketStreams optSocketStreams = (OptSocketStreams) doOP(optProblemJson, this);
getResponse().setStatus(Status.SUCCESS_OK);
Representation representation = new StringRepresentation(optSocketStreams.optID, MediaType.TEXT_PLAIN);
return representation;
}
use of org.restlet.resource.Post in project vcell by virtualcell.
the class PublicationServerResource method handleForm.
@Post
public Representation handleForm(Representation entity) {
try {
String myHost = getHostRef().getHostDomain();
String allowedPublicationHost = PropertyLoader.getProperty(PropertyLoader.vcellPublicationHost, "");
if (!allowedPublicationHost.equals(myHost)) {
throw new PermissionException("Host '" + myHost + "' not allowed to edit publications");
}
Form form = new Form(entity);
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
if (vcellUser == null) {
throw new PermissionException("must be authenticated to edit publication info");
}
// The form contains input with names "user" and "password"
String pubop = form.getFirstValue("pubop");
// String password = form.getFirstValue("password");
Map<String, Object> dataModel = new HashMap<String, Object>();
if (pubop == null) {
return new StringRepresentation(("value of publication 'operation' cannot be null"));
} else if (pubop.equals("editNew")) {
PublicationRepresentation value = new PublicationRepresentation();
value.pubKey = AUTOMATICALLY_GENERATED;
dataModel.put("publicationRepr", value);
} else if (pubop.equals("editWithKey")) {
Object pubidObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
PublicationRepresentation publication = getPublicationRepresentation(((VCellApiApplication) getApplication()).getRestDatabaseService(), vcellUser, new KeyValue(pubidObj.toString()));
dataModel.put("publicationRepr", publication);
} else if (pubop.equals("applyEdit")) {
SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM/dd/yyyy", java.util.Locale.US);
// PublicationRepresentation publication = getPublicationRepresentation(((VCellApiApplication)getApplication()).getRestDatabaseService(),vcellUser,new KeyValue(form.getFirstValue("pubid")));
String[] authors = StringUtils.split(form.getFirstValue("authors"), ";");
for (int i = 0; i < authors.length; i++) {
authors[i] = authors[i].trim();
}
String thePubID = form.getFirstValue("pubId");
BioModelReferenceRep[] bioModelReferenceReps = (BioModelReferenceRep[]) convertToReferenceRep(form.getFirstValue("biomodelReferences"), BioModelReferenceRep.class);
MathModelReferenceRep[] mathModelReferenceReps = (MathModelReferenceRep[]) convertToReferenceRep(form.getFirstValue("mathmodelReferences"), MathModelReferenceRep.class);
PublicationRep publicationRep = new PublicationRep((thePubID == null || thePubID.equals(AUTOMATICALLY_GENERATED) ? null : new KeyValue(Integer.valueOf(thePubID).toString())), form.getFirstValue("title"), authors, (form.getFirstValue("year") == null || form.getFirstValue("year").trim().length() == 0 ? null : Integer.valueOf(form.getFirstValue("year"))), form.getFirstValue("citation"), form.getFirstValue("pubmedid"), form.getFirstValue("doi"), form.getFirstValue("endnoteid"), form.getFirstValue("url"), bioModelReferenceReps, mathModelReferenceReps, form.getFirstValue("wittid"), (form.getFirstValue("pubdate") == null || form.getFirstValue("pubdate").trim().length() == 0 ? null : sdf.parse(form.getFirstValue("pubdate"))));
KeyValue savedOrEditedPubID = ((VCellApiApplication) getApplication()).getRestDatabaseService().savePublicationRep(publicationRep, vcellUser);
// String address = getRequest().getClientInfo().getAddress();
// int port = getRequest().getClientInfo().getPort();
StringRepresentation s = getPubInfoHtml(myHost, savedOrEditedPubID);
return s;
} else if (pubop.equals("makepublic")) {
String[] bmKeys = form.getValuesArray("bmpublic");
KeyValue[] publishTheseBiomodels = new KeyValue[(bmKeys == null ? 0 : bmKeys.length)];
for (int i = 0; i < publishTheseBiomodels.length; i++) {
publishTheseBiomodels[i] = new KeyValue(bmKeys[i]);
}
String[] mmKeys = form.getValuesArray("mmpublic");
KeyValue[] publishTheseMathmodels = new KeyValue[(mmKeys == null ? 0 : mmKeys.length)];
for (int i = 0; i < publishTheseMathmodels.length; i++) {
publishTheseMathmodels[i] = new KeyValue(mmKeys[i]);
}
if (publishTheseBiomodels.length > 0 || publishTheseMathmodels.length > 0) {
((VCellApiApplication) getApplication()).getRestDatabaseService().publishDirectly(publishTheseBiomodels, publishTheseMathmodels, vcellUser);
}
Object pubidObj = getRequestAttributes().get(VCellApiApplication.PUBLICATIONID);
StringRepresentation s = getPubInfoHtml(myHost, new KeyValue(pubidObj.toString()));
return s;
} else {
return new StringRepresentation(("value of pubop=" + pubop + " not expected").toCharArray());
}
Configuration templateConfiguration = application.getTemplateConfiguration();
Representation myRepresentation = new ClientResource(LocalReference.createClapReference("/newpublication.ftl")).get();
TemplateRepresentation templateRepresentation = new TemplateRepresentation(myRepresentation, templateConfiguration, dataModel, MediaType.TEXT_HTML);
return templateRepresentation;
} catch (Exception e) {
return new StringRepresentation(e.getClass().getName() + " " + e.getMessage());
}
}
Aggregations