Search in sources :

Example 21 with User

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

the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_max_age.

@Test
public void shouldInvokeAuthorizationEndpoint_max_age() 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(routingContext -> {
        io.gravitee.am.model.User endUser = new io.gravitee.am.model.User();
        endUser.setLoggedAt(new Date(System.currentTimeMillis() - 60 * 1000));
        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));
    // user is logged for 1 min, the max_age is big enough to validate the request
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&max_age=120", 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) Date(java.util.Date) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 22 with User

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

the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_user_max_age_prompt_none.

@Test
public void shouldNotInvokeAuthorizationEndpoint_user_max_age_prompt_none() 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(false);
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    router.route().order(-1).handler(routingContext -> {
        io.gravitee.am.model.User endUser = new io.gravitee.am.model.User();
        endUser.setLoggedAt(new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000));
        routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(endUser)));
        routingContext.put(CLIENT_CONTEXT_KEY, client);
        routingContext.next();
    });
    // user is logged since yesterday, he must be redirected to the login page
    testRequest(HttpMethod.GET, "/oauth/authorize?response_type=code&client_id=client-id&redirect_uri=http://localhost:9999/callback&max_age=1&prompt=none", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback?error=login_required&error_description=Login+required", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : AuthorizationRequest(io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest) User(io.vertx.reactivex.ext.auth.User) Date(java.util.Date) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 23 with User

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

the class AuthorizationEndpointTest method shouldNotInvokeAuthorizationEndpoint_prompt_login.

@Test
public void shouldNotInvokeAuthorizationEndpoint_prompt_login() 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"));
    when(clientSyncService.findByClientId("client-id")).thenReturn(Maybe.just(client));
    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();
    });
    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?error=access_denied", 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 24 with User

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

the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_responseTypeCode.

@Test
public void shouldInvokeAuthorizationEndpoint_responseTypeCode() throws Exception {
    io.gravitee.am.model.User user = new io.gravitee.am.model.User();
    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(routingContext -> {
        routingContext.setUser(new User(new io.gravitee.am.gateway.handler.common.vertx.web.auth.user.User(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", 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) User(io.vertx.reactivex.ext.auth.User) AuthorizationRequest(io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 25 with User

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

the class AuthorizationEndpointTest method shouldInvokeAuthorizationEndpoint_missingClientResponseType.

@Test
public void shouldInvokeAuthorizationEndpoint_missingClientResponseType() throws Exception {
    final Client client = new Client();
    client.setId("client-id");
    client.setClientId("client-id");
    client.setResponseTypes(Arrays.asList(io.gravitee.am.common.oidc.ResponseType.ID_TOKEN));
    client.setRedirectUris(Collections.singletonList("http://localhost:9999/callback"));
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setApproved(true);
    authorizationRequest.setResponseType(ResponseType.TOKEN);
    authorizationRequest.setRedirectUri("http://localhost:9999/callback");
    Token accessToken = new AccessToken("token");
    AuthorizationResponse authorizationResponse = new ImplicitResponse();
    authorizationResponse.setRedirectUri(authorizationRequest.getRedirectUri());
    ((ImplicitResponse) authorizationResponse).setAccessToken(accessToken);
    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=token&client_id=client-id&nonce=123&redirect_uri=http://localhost:9999/callback", null, resp -> {
        String location = resp.headers().get("location");
        assertNotNull(location);
        assertEquals("http://localhost:9999/callback#error=unauthorized_client&error_description=Client+should+have+all+requested+response_type", location);
    }, HttpStatusCode.FOUND_302, "Found", null);
}
Also used : AuthorizationRequest(io.gravitee.am.gateway.handler.oauth2.service.request.AuthorizationRequest) User(io.vertx.reactivex.ext.auth.User) AccessToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken) Token(io.gravitee.am.gateway.handler.oauth2.service.token.Token) AccessToken(io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken) 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