use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class ConsentRequiredResource method getDataModel.
/**
* Gets the data model to use when rendering the error page.
*
* @param consentRequired The details for requesting consent.
* @param request The OAuth2 request.
* @return The data model.
*/
protected Map<String, Object> getDataModel(ResourceOwnerConsentRequired consentRequired, OAuth2Request request) {
String displayName = consentRequired.getClientName();
String displayDescription = consentRequired.getClientDescription();
String userDisplayName = consentRequired.getUserDisplayName();
Map<String, Object> data = new HashMap<>(getRequest().getAttributes());
data.putAll(getQuery().getValuesMap());
Reference resRef = getRequest().getResourceRef();
String target = resRef.getPath();
String query = resRef.getQuery();
if (!StringUtils.isBlank(query)) {
target = target + "?" + query;
}
data.put("target", target);
data.put("display_name", ESAPI.encoder().encodeForHTML(displayName));
data.put("display_description", ESAPI.encoder().encodeForHTML(displayDescription));
addDisplayScopesAndClaims(consentRequired, data);
data.put("user_name", userDisplayName);
data.put("xui", xuiState.isXUIEnabled());
data.put("user_code", request.getParameter(OAuth2Constants.DeviceCode.USER_CODE));
data.put("baseUrl", baseURLProviderFactory.get(request.<String>getParameter("realm")).getRootURL(ServletUtils.getRequest(getRequest())));
return data;
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class ExceptionHandler method handle.
/**
* Handles a OAuth2RestletException that is thrown when processing a OAuth2 authorization request.
* <br/>
* If the OAuth2RestletException has a status of {@link Status#REDIRECTION_TEMPORARY} the user agent will be
* redirected to the redirect uri set on the exception.
* <br/>
* If the OAuth2RestletException does not have a redirect status but still has a redirect uri set, the user
* agent will be redrected to the redirect uri with the exception message in the redirect uri.
* <br/>
* In all other cases the OAuth2 error page will be presented.
*
* @param exception The OAuth2RestletException.
* @param context The Restlet context.
* @param request The Restlet request.
* @param response The Restlet response.
*/
private void handle(OAuth2RestletException exception, Context context, Request request, Response response) {
if (exception.getStatus().equals(Status.REDIRECTION_TEMPORARY)) {
Redirector redirector = new Redirector(new Context(), exception.getRedirectUri(), Redirector.MODE_CLIENT_PERMANENT);
redirector.handle(request, response);
return;
} else {
response.setStatus(exception.getStatus());
}
if (!isEmpty(exception.getRedirectUri())) {
Reference ref = new Reference(exception.getRedirectUri());
if (UrlLocation.FRAGMENT.equals(exception.getParameterLocation())) {
ref.setFragment(representation.toForm(exception.asMap()).getQueryString());
} else {
ref.addQueryParameters(representation.toForm(exception.asMap()));
}
final Redirector redirector = new Redirector(context, ref.toString(), Redirector.MODE_CLIENT_FOUND);
redirector.handle(request, response);
return;
}
final Map<String, String> data = new HashMap<>(exception.asMap());
final String realm = requestFactory.create(request).getParameter("realm");
data.put("realm", realm);
data.put("baseUrl", baseURLProviderFactory.get(realm).getRootURL(ServletUtils.getRequest(request)));
response.setEntity(representation.getRepresentation(context, "page", "error.ftl", data));
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class OpenAMResourceOwnerSessionValidator method buildDefaultLoginUrl.
private URI buildDefaultLoginUrl(OAuth2Request request, String gotoUrl, String acrValues, String realm, String moduleName, String serviceName, String locale) throws URISyntaxException, ServerException, NotFoundException {
final Request req = request.getRequest();
final String authURL = getAuthURL(getHttpServletRequest(req));
final URI authURI = new URI(authURL);
final Reference loginRef = new Reference(authURI);
if (!isEmpty(realm)) {
loginRef.addQueryParameter(OAuth2Constants.Custom.REALM, realm);
}
if (!isEmpty(locale)) {
loginRef.addQueryParameter(LOCALE, locale);
}
// Prefer standard acr_values, then module, then service
if (!isEmpty(acrValues)) {
final ACRValue chosen = chooseBestAcrValue(request, acrValues.split("\\s+"));
if (chosen != null) {
loginRef.addQueryParameter(chosen.method.getIndexType().toString(), chosen.method.getName());
// Adjust the GOTO url to indicate which acr value was actually chosen
req.getResourceRef().addQueryParameter(OAuth2Constants.JWTTokenParams.ACR, chosen.acr);
}
} else if (!isEmpty(moduleName)) {
loginRef.addQueryParameter(MODULE, moduleName);
} else if (!isEmpty(serviceName)) {
loginRef.addQueryParameter(SERVICE, serviceName);
}
loginRef.addQueryParameter(GOTO, gotoUrl);
return loginRef.toUri();
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class RestletRealmRouterTest method setUpServerName.
private void setUpServerName(Request request, SSOToken adminToken, String realm) throws IdRepoException, SSOException {
Reference reference = request.getResourceRef();
given(request.getHostRef()).willReturn(reference);
given(reference.getHostDomain()).willReturn("HOST_DOMAIN");
given(coreWrapper.getOrganization(adminToken, "HOST_DOMAIN")).willReturn("REALM_HOST_DN");
given(coreWrapper.convertOrgNameToRealmName("REALM_HOST_DN")).willReturn(realm.equals("/") ? realm : "/" + realm);
request.getAttributes().put(RestletRealmRouter.REALM_INFO, new RealmInfo("/"));
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class RestletOAuth2RequestTest method theSetUp.
@BeforeMethod
private void theSetUp() {
//you need this
request = new Request();
Reference reference = new Reference("http://127.0.0.1:8080/test");
request.setResourceRef(reference);
request.setMethod(Method.POST);
JacksonRepresentationFactory jacksonRepresentationFactory = new JacksonRepresentationFactory(new ObjectMapper());
requestUnderTest = new RestletOAuth2Request(jacksonRepresentationFactory, request);
}
Aggregations