Search in sources :

Example 1 with Reference

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);
}
Also used : Reference(org.restlet.data.Reference)

Example 2 with Reference

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);
}
Also used : Reference(org.restlet.data.Reference)

Example 3 with Reference

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();
}
Also used : Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Parameter(org.restlet.data.Parameter) Redirector(org.restlet.routing.Redirector)

Example 4 with Reference

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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(org.restlet.Response) SSOToken(com.iplanet.sso.SSOToken) Restlet(org.restlet.Restlet) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) HttpRequest(org.restlet.engine.adapter.HttpRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.restlet.Request) Test(org.testng.annotations.Test)

Example 5 with Reference

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;
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) ServletCall(org.restlet.ext.servlet.internal.ServletCall) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference)

Aggregations

Reference (org.restlet.data.Reference)46 Request (org.restlet.Request)26 Response (org.restlet.Response)26 Representation (org.restlet.representation.Representation)19 StringWriter (java.io.StringWriter)15 HashMap (java.util.HashMap)11 ZNRecord (org.apache.helix.ZNRecord)11 StringReader (java.io.StringReader)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 ResourceException (org.restlet.resource.ResourceException)8 Form (org.restlet.data.Form)5 IOException (java.io.IOException)3 Date (java.util.Date)3 Test (org.junit.Test)3 ContextResourceClient (org.qi4j.library.rest.client.api.ContextResourceClient)3 ContextResourceClientFactory (org.qi4j.library.rest.client.api.ContextResourceClientFactory)3 ErrorHandler (org.qi4j.library.rest.client.api.ErrorHandler)3 HandlerCommand (org.qi4j.library.rest.client.api.HandlerCommand)3 ResponseHandler (org.qi4j.library.rest.client.spi.ResponseHandler)3