Search in sources :

Example 11 with OAuth2RestletException

use of org.forgerock.oauth2.restlet.OAuth2RestletException in project OpenAM by OpenRock.

the class EndSessionTest method shouldAttemptEndSessionAndFailMismatchRedirect.

@Test
public void shouldAttemptEndSessionAndFailMismatchRedirect() throws Exception {
    // given
    String requestedUri = "http://www.example.com";
    String registeredUri = "http://www.google.com";
    when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri);
    when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri)));
    // when
    OAuth2RestletException exception = null;
    try {
        endSession.endSession();
    } catch (OAuth2RestletException e) {
        exception = e;
    }
    // then
    verify(openIDConnectEndSession, times(1)).endSession(any(String.class));
    assertThat(exception).isNotNull();
    assertThat(exception.getError()).isEqualTo("redirect_uri_mismatch");
}
Also used : OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 12 with OAuth2RestletException

use of org.forgerock.oauth2.restlet.OAuth2RestletException in project OpenAM by OpenRock.

the class OpenIDConnectConfiguration method getConfiguration.

/**
     * Handles GET requests to the OpenId Connect .well-known endpoint for retrieving the OpenId Connect provider
     * configuration.
     *
     * @return The representation of the OpenId Connect provider configuration.
     * @throws OAuth2RestletException If an error occurs whilst retrieving the OpenId Connect provider configuration.
     */
@Get
public Representation getConfiguration() throws OAuth2RestletException {
    try {
        final OAuth2Request request = requestFactory.create(getRequest());
        final JsonValue configuration = providerConfiguration.getConfiguration(request);
        return new JsonRepresentation(configuration.asMap());
    } catch (OAuth2Exception e) {
        throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) JsonValue(org.forgerock.json.JsonValue) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 13 with OAuth2RestletException

use of org.forgerock.oauth2.restlet.OAuth2RestletException in project OpenAM by OpenRock.

the class OpenIDConnectDiscovery method discovery.

/**
     * Handles GET requests to the OpenId Connect discovery endpoint.
     *
     * @return The representation of the OpenId Connect discovery.
     * @throws OAuth2RestletException If an error occurs whilst performing the discovery.
     */
@Get
public Representation discovery() throws OAuth2RestletException {
    final OAuth2Request request = requestFactory.create(getRequest());
    final String resource = request.getParameter("resource");
    final String rel = request.getParameter("rel");
    final String realm = request.getParameter("realm");
    try {
        final String deploymentUrl = baseUrlProviderFactory.get(realm).getRootURL(ServletUtils.getRequest(getRequest()));
        final Map<String, Object> response = providerDiscovery.discover(resource, rel, deploymentUrl, request);
        return new JsonRepresentation(response);
    } catch (OAuth2Exception e) {
        throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 14 with OAuth2RestletException

use of org.forgerock.oauth2.restlet.OAuth2RestletException in project OpenAM by OpenRock.

the class ConnectClientRegistration method getClient.

/**
     * Handles GET requests to the OpenId Connect client registration endpoint for retrieving OpenId Connect client
     * registrations.
     *
     * @return The representation of the client registration details.
     * @throws OAuth2RestletException If an error occurs whilst retrieving the client registration.
     */
@Get
public Representation getClient() throws OAuth2RestletException {
    final OAuth2Request request = requestFactory.create(getRequest());
    final String clientId = request.getParameter(OAuth2Constants.OAuth2Client.CLIENT_ID);
    final String accessToken = getRequest().getChallengeResponse().getRawValue();
    try {
        final JsonValue registration = clientRegistrationService.getRegistration(clientId, accessToken, request);
        return jacksonRepresentationFactory.create(registration.asMap());
    } catch (OAuth2Exception e) {
        throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) JsonValue(org.forgerock.json.JsonValue) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Aggregations

OAuth2Exception (org.forgerock.oauth2.core.exceptions.OAuth2Exception)11 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)10 OAuth2RestletException (org.forgerock.oauth2.restlet.OAuth2RestletException)7 Get (org.restlet.resource.Get)6 JsonValue (org.forgerock.json.JsonValue)4 Post (org.restlet.resource.Post)4 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)3 RedirectUriMismatchException (org.forgerock.oauth2.core.exceptions.RedirectUriMismatchException)3 ResourceOwnerAuthenticationRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerAuthenticationRequired)3 URI (java.net.URI)2 AuthorizationToken (org.forgerock.oauth2.core.AuthorizationToken)2 DeviceCode (org.forgerock.oauth2.core.DeviceCode)2 ResourceOwnerConsentRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerConsentRequired)2 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)2 Request (org.restlet.Request)2 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)2 Representation (org.restlet.representation.Representation)2 Test (org.testng.annotations.Test)2 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1