use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class OpenAMResourceOwnerSessionValidatorTest method mockPrompt.
private void mockPrompt(String prompt) {
restletRequest.setResourceRef(new Reference("http://openam.example.com:8080/openam/oauth2/authorize?prompt=" + prompt));
given(mockOAuth2Request.getParameter("prompt")).willReturn(prompt);
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class RestletOAuth2RequestTest method setQueryParam.
private void setQueryParam(Request request) {
Reference reference = request.getResourceRef();
reference.addQueryParameter("realm", "realmFromQueryParam");
request.setResourceRef(reference);
request.setMethod(Method.GET);
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class OAuth2Representation method toRepresentation.
/**
* Converts the authorization token into a representation to send back to the user agent.
*
* @param context The Restlet context.
* @param request The Restlet request.
* @param response The Restlet response.
* @param authorizationToken The authorization token.
* @param redirectUri The redirect uri.
* @return The representation to send to the user agent.
*/
Representation toRepresentation(Context context, Request request, Response response, AuthorizationToken authorizationToken, String redirectUri) {
final Form tokenForm = toForm(authorizationToken);
final Reference redirectReference = new Reference(redirectUri);
if (authorizationToken.isFragment()) {
redirectReference.setFragment(tokenForm.getQueryString());
} else {
final Iterator<Parameter> iter = tokenForm.iterator();
while (iter.hasNext()) {
redirectReference.addQueryParameter(iter.next());
}
}
if (isFormPostRequest(requestFactory.create(request))) {
return getFormPostRepresentation(context, authorizationToken, redirectReference.toString());
}
final Redirector dispatcher = new Redirector(context, redirectReference.toString(), Redirector.MODE_CLIENT_FOUND);
dispatcher.handle(request, response);
return response == null ? null : response.getEntity();
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class RestletRealmRouterTest method shouldHandleQueryParamRealmWithNoLeadingSlash.
@Test
public void shouldHandleQueryParamRealmWithNoLeadingSlash() throws IdRepoException, SSOException {
//Given
SSOToken adminToken = mock(SSOToken.class);
Restlet next = mock(Restlet.class);
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
Request request = setUpRequest(httpRequest, adminToken);
Response response = mock(Response.class);
setUpServerName(request, adminToken, "/");
Reference reference = mock(Reference.class);
given(request.getResourceRef()).willReturn(reference);
Reference baseRef = mock(Reference.class);
given(reference.getBaseRef()).willReturn(baseRef);
given(baseRef.toString()).willReturn("The base url");
Form queryForm = mock(Form.class);
given(reference.getQueryAsForm()).willReturn(queryForm);
given(queryForm.getFirstValue("realm")).willReturn("REALM");
setUpRealmValidator("REALM", false, adminToken);
//When
router.doHandle(next, request, response);
//Then
assertThat(request.getAttributes()).containsEntry("realm", "/REALM");
verify(httpRequest).setAttribute("realm", "/REALM");
}
use of org.restlet.data.Reference in project OpenAM by OpenRock.
the class RestletRealmRouterTest method setUpRequest.
private Request setUpRequest(HttpServletRequest httpRequest, SSOToken adminToken) {
HttpRequest request = generateRequest();
ServletCall serverCall = mock(ServletCall.class);
given(request.getHttpCall()).willReturn(serverCall);
given(serverCall.getRequest()).willReturn(httpRequest);
Reference reference = mock(Reference.class);
given(request.getResourceRef()).willReturn(reference);
Form queryForm = mock(Form.class);
given(reference.getQueryAsForm()).willReturn(queryForm);
Reference baseReference = mock(Reference.class);
given(reference.getBaseRef()).willReturn(baseReference);
given(baseReference.toString()).willReturn("The base url");
given(coreWrapper.getAdminToken()).willReturn(adminToken);
return request;
}
Aggregations