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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations