Search in sources :

Example 16 with User

use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.

the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_noUser_code_challenge_valid_s256.

@Test
public void shouldNotInvokeAuthorizationEndpoint_noUser_code_challenge_valid_s256() throws Exception {
    final Client client = new Client();
    client.setId("client-id");
    client.setClientId("client-id");
    client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setApproved(true);
    authorizationRequest.setResponseType(ResponseType.CODE);
    authorizationRequest.setRedirectUri("http://localhost:9999/callback");
    AuthorizationResponse authorizationResponse = new AuthorizationCodeResponse();
    authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
    ((AuthorizationCodeResponse) authorizationResponse).setCode("test-code");
    router.route().order(-1).handler(new Handler<RoutingContext>() {

        @Override
        public void handle(RoutingContext routingContext) {
            routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
            routingContext.next();
        }
    });
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    when(flow.run(any(), any(), any())).thenReturn(Single.just(authorizationResponse));
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&code_challenge_method=S256&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback?code=test-code", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : JWTAuthorizationCodeResponse(io.gravitee.am.gateway.handler.oauth2.service.response.jwt.JWTAuthorizationCodeResponse) AuthorizationRequest(io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest) User(io.vertx.reactivex.ext.auth.User) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 17 with User

use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.

the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_invalidScope.

@Test
public void shouldNotInvokeAuthorizationEndpoint_invalidScope() throws Exception {
    final Client client = new Client();
    client.setId("client-id");
    client.setClientId("client-id");
    client.setScopeSettings(Collections.singletonList(new ApplicationScopeSettings("read")));
    client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
    router.route().order(-1).handler(routingContext -> {
        routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
        routingContext.next();
    });
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&scope=unknown", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback?error=invalid_scope&error_description=Invalid+scope%2528s%2529%253A+unknown", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : User(io.vertx.reactivex.ext.auth.User) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 18 with User

use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.

the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_prompt_login_consent_step.

@Test
public void shouldInvokeAuthorizationEndpoint_prompt_login_consent_step() throws Exception {
    final Client client = new Client();
    client.setId("client-id");
    client.setClientId("client-id");
    client.setScopeSettings(Collections.singletonList(new ApplicationScopeSettings("read")));
    client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setApproved(true);
    authorizationRequest.setResponseType(ResponseType.CODE);
    authorizationRequest.setRedirectUri("http://localhost:9999/callback");
    AuthorizationResponse authorizationResponse = new AuthorizationCodeResponse();
    authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
    ((AuthorizationCodeResponse) authorizationResponse).setCode("test-code");
    router.route().order(-1).handler(routingContext -> {
        routingContext.session().put(ConstantKeys.USER_LOGIN_COMPLETED_KEY, true);
        routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
        routingContext.next();
    });
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    when(flow.run(any(), any(), any())).thenReturn(Single.just(authorizationResponse));
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&prompt=login", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback?code=test-code", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : JWTAuthorizationCodeResponse(io.gravitee.am.gateway.handler.oauth2.service.response.jwt.JWTAuthorizationCodeResponse) AuthorizationRequest(io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest) User(io.vertx.reactivex.ext.auth.User) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 19 with User

use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.

the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_forcePKCE_noCodeChallenge.

@Test
public void shouldNotInvokeAuthorizationEndpoint_forcePKCE_noCodeChallenge() throws Exception {
    final Client client = new Client();
    client.setId("client-id");
    client.setClientId("client-id");
    client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
    client.setForcePKCE(true);
    router.route().order(-1).handler(routingContext -> {
        routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
        routingContext.next();
    });
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback?error=invalid_request&error_description=Missing+parameter%253A+code_challenge", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : User(io.vertx.reactivex.ext.auth.User) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 20 with User

use of io.vertx.reactivex.ext.auth.User in project gravitee-access-management by gravitee-io.

the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_prompt_login_social_auth_step.

@Test
public void shouldInvokeAuthorizationEndpoint_prompt_login_social_auth_step() throws Exception {
    final Client client = new Client();
    client.setId("client-id");
    client.setClientId("client-id");
    client.setScopeSettings(Collections.singletonList(new ApplicationScopeSettings("read")));
    client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setApproved(true);
    authorizationRequest.setResponseType(ResponseType.CODE);
    authorizationRequest.setRedirectUri("http://localhost:9999/callback");
    AuthorizationResponse authorizationResponse = new AuthorizationCodeResponse();
    authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
    ((AuthorizationCodeResponse) authorizationResponse).setCode("test-code");
    router.route().order(-1).handler(routingContext -> {
        routingContext.session().put(ConstantKeys.USER_LOGIN_COMPLETED_KEY, true);
        routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(new io.gravitee.am.model.User())));
        routingContext.next();
    });
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    when(flow.run(any(), any(), any())).thenReturn(Single.just(authorizationResponse));
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&prompt=login", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback?code=test-code", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : JWTAuthorizationCodeResponse(io.gravitee.am.gateway.handler.oauth2.service.response.jwt.JWTAuthorizationCodeResponse) AuthorizationRequest(io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest) User(io.vertx.reactivex.ext.auth.User) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Aggregations

User (io.vertx.reactivex.ext.auth.User)30 Client (io.gravitee.am.model.oidc.Client)25 AuthorizationRequest (io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest)20 Test (org.junit.Test)20 JWTAuthorizationCodeResponse (io.gravitee.am.gateway.handler.oauth2.service.response.jwt.JWTAuthorizationCodeResponse)11 ApplicationScopeSettings (io.gravitee.am.model.application.ApplicationScopeSettings)10 Token (io.gravitee.am.gateway.handler.oauth2.service.token.Token)3 AccessToken (io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken)3 Date (java.util.Date)3 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)2 AccessDeniedException (io.gravitee.am.gateway.handler.oauth2.exception.AccessDeniedException)2 RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)2 HttpRequestContext (io.crnk.core.engine.http.HttpRequestContext)1 QueryContext (io.crnk.core.engine.query.QueryContext)1 SecurityProvider (io.crnk.core.engine.security.SecurityProvider)1 SecurityProviderContext (io.crnk.core.engine.security.SecurityProviderContext)1 CrnkRequestInterceptor (io.crnk.setup.vertx.CrnkRequestInterceptor)1 AccountDisabledException (io.gravitee.am.common.exception.authentication.AccountDisabledException)1 AccountIllegalStateException (io.gravitee.am.common.exception.authentication.AccountIllegalStateException)1 AccountStatusException (io.gravitee.am.common.exception.authentication.AccountStatusException)1