Search in sources :

Example 6 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class RestletFormBodyAccessTokenVerifierTest method shouldCheckValid.

@Test
public void shouldCheckValid() throws Exception {
    // Given
    Form form = new Form();
    form.add("access_token", "freddy");
    Request request = new Request();
    request.setEntity(form.getWebRepresentation());
    OAuth2Request req = new RestletOAuth2Request(null, request);
    AccessToken token = new AccessToken(json(object()), "access_token", "freddy") {

        @Override
        public boolean isExpired() {
            return false;
        }
    };
    when(tokenStore.readAccessToken(req, "freddy")).thenReturn(token);
    // When
    AccessTokenVerifier.TokenState result = verifier.verify(req);
    // Then
    assertThat(result.isValid()).isTrue();
    assertThat(result.getTokenId()).isEqualTo("freddy");
    verify(tokenStore).readAccessToken(req, "freddy");
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Form(org.restlet.data.Form) AccessToken(org.forgerock.oauth2.core.AccessToken) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessTokenVerifier(org.forgerock.oauth2.core.AccessTokenVerifier) Test(org.testng.annotations.Test)

Example 7 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class RestletFormBodyAccessTokenVerifierTest method shouldCheckExpired.

@Test
public void shouldCheckExpired() throws Exception {
    // Given
    Form form = new Form();
    form.add("access_token", "freddy");
    Request request = new Request();
    request.setEntity(form.getWebRepresentation());
    OAuth2Request req = new RestletOAuth2Request(null, request);
    AccessToken token = new AccessToken(json(object()), "access_token", "freddy") {

        @Override
        public boolean isExpired() {
            return true;
        }
    };
    when(tokenStore.readAccessToken(req, "freddy")).thenReturn(token);
    // When
    AccessTokenVerifier.TokenState result = verifier.verify(req);
    // Then
    assertThat(result.isValid()).isFalse();
    verify(tokenStore).readAccessToken(req, "freddy");
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Form(org.restlet.data.Form) AccessToken(org.forgerock.oauth2.core.AccessToken) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessTokenVerifier(org.forgerock.oauth2.core.AccessTokenVerifier) Test(org.testng.annotations.Test)

Example 8 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class RestletFormBodyAccessTokenVerifierTest method shouldCheckBody.

@Test
public void shouldCheckBody() throws Exception {
    // Given
    Request request = new Request();
    OAuth2Request req = new RestletOAuth2Request(null, request);
    // When
    AccessTokenVerifier.TokenState result = verifier.verify(req);
    // Then
    assertThat(result.isValid()).isFalse();
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessTokenVerifier(org.forgerock.oauth2.core.AccessTokenVerifier) Test(org.testng.annotations.Test)

Example 9 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class RestletHeaderAccessTokenVerifier method obtainTokenId.

/**
     * {@inheritDoc}
     */
protected String obtainTokenId(OAuth2Request request) {
    final Request req = request.getRequest();
    ChallengeResponse result = getChallengeResponse(req);
    if (result == null) {
        logger.debug("Request does not contain Authorization header.");
        return null;
    }
    return result.getRawValue();
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) ChallengeResponse(org.restlet.data.ChallengeResponse)

Example 10 with Request

use of org.restlet.Request in project OpenAM by OpenRock.

the class ResourceSetRegistrationExceptionFilterTest method shouldSet405ExceptionResponse.

@Test
@SuppressWarnings("unchecked")
public void shouldSet405ExceptionResponse() throws Exception {
    //Given
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    Status status = new Status(405);
    given(response.getStatus()).willReturn(status);
    //When
    exceptionFilter.afterHandle(request, response);
    //Then
    ArgumentCaptor<JacksonRepresentation> exceptionResponseCaptor = ArgumentCaptor.forClass(JacksonRepresentation.class);
    verify(response).setEntity(exceptionResponseCaptor.capture());
    Map<String, String> responseBody = (Map<String, String>) exceptionResponseCaptor.getValue().getObject();
    assertThat(responseBody).containsOnly(entry("error", "unsupported_method_type"));
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Request(org.restlet.Request) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

Request (org.restlet.Request)100 Response (org.restlet.Response)64 Test (org.testng.annotations.Test)38 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)37 Reference (org.restlet.data.Reference)26 Representation (org.restlet.representation.Representation)24 ChallengeResponse (org.restlet.data.ChallengeResponse)18 StringWriter (java.io.StringWriter)15 Status (org.restlet.data.Status)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HashMap (java.util.HashMap)12 ZNRecord (org.apache.helix.ZNRecord)11 AccessToken (org.forgerock.oauth2.core.AccessToken)11 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)11 StringReader (java.io.StringReader)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 Form (org.restlet.data.Form)9 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)8 BeforeMethod (org.testng.annotations.BeforeMethod)8