use of io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager in project gravitee-access-management by gravitee-io.
the class SocialAuthenticationProviderTest method shouldAuthenticateUser_sso_no_id_token.
@Test
public void shouldAuthenticateUser_sso_no_id_token() throws Exception {
JsonObject credentials = new JsonObject();
credentials.put("username", "my-user-id");
credentials.put("password", "my-user-password");
credentials.put("provider", "idp");
credentials.put("additionalParameters", Collections.emptyMap());
io.gravitee.am.identityprovider.api.User user = new io.gravitee.am.identityprovider.api.DefaultUser("username");
Client client = new Client();
client.setSingleSignOut(true);
when(userAuthenticationManager.connect(any())).thenReturn(Single.just(new User()));
when(authenticationProvider.loadUserByUsername(any(EndUserAuthentication.class))).thenReturn(Maybe.just(user));
when(routingContext.get("client")).thenReturn(client);
when(routingContext.get("provider")).thenReturn(authenticationProvider);
when(routingContext.get("providerId")).thenReturn("idp");
when(routingContext.request()).thenReturn(httpServerRequest);
when(routingContext.data()).thenReturn(Map.of("id_token", "some_id_token"));
final io.vertx.core.http.HttpServerRequest delegateRequest = mock(io.vertx.core.http.HttpServerRequest.class);
when(httpServerRequest.getDelegate()).thenReturn(delegateRequest);
when(delegateRequest.method()).thenReturn(HttpMethod.POST);
CountDownLatch latch = new CountDownLatch(1);
authProvider.authenticate(routingContext, credentials, userAsyncResult -> {
latch.countDown();
Assert.assertNotNull(userAsyncResult);
Assert.assertNotNull(userAsyncResult.result());
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
verify(userAuthenticationManager, times(1)).connect(any());
verify(eventManager).publishEvent(argThat(evt -> evt == AuthenticationEvent.SUCCESS), any());
}
use of io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager in project gravitee-access-management by gravitee-io.
the class SocialAuthenticationProviderTest method shouldAuthenticateUser_with_access_token_and_id_token.
@Test
public void shouldAuthenticateUser_with_access_token_and_id_token() throws Exception {
JsonObject credentials = new JsonObject();
credentials.put("username", "my-user-id");
credentials.put("password", "my-user-password");
credentials.put("provider", "idp");
credentials.put("additionalParameters", Collections.emptyMap());
io.gravitee.am.identityprovider.api.User user = new io.gravitee.am.identityprovider.api.DefaultUser("username");
Client client = new Client();
when(userAuthenticationManager.connect(any())).thenReturn(Single.just(new User()));
when(authenticationProvider.loadUserByUsername(any(EndUserAuthentication.class))).thenReturn(Maybe.just(user));
when(routingContext.get("client")).thenReturn(client);
when(routingContext.get("provider")).thenReturn(authenticationProvider);
when(routingContext.get("providerId")).thenReturn("idp");
when(routingContext.request()).thenReturn(httpServerRequest);
when(routingContext.data()).thenReturn(Map.of("access_token", "some_access_token", "id_token", "some_id_token"));
final io.vertx.core.http.HttpServerRequest delegateRequest = mock(io.vertx.core.http.HttpServerRequest.class);
when(httpServerRequest.getDelegate()).thenReturn(delegateRequest);
when(delegateRequest.method()).thenReturn(HttpMethod.POST);
CountDownLatch latch = new CountDownLatch(1);
authProvider.authenticate(routingContext, credentials, userAsyncResult -> {
latch.countDown();
Assert.assertNotNull(userAsyncResult);
Assert.assertNotNull(userAsyncResult.result());
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
verify(userAuthenticationManager, times(1)).connect(any());
verify(eventManager).publishEvent(argThat(evt -> evt == AuthenticationEvent.SUCCESS), any());
}
use of io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager in project gravitee-access-management by gravitee-io.
the class SocialAuthenticationProviderTest method shouldAuthenticateUser_with_id_token_client_sso.
@Test
public void shouldAuthenticateUser_with_id_token_client_sso() throws Exception {
JsonObject credentials = new JsonObject();
credentials.put("username", "my-user-id");
credentials.put("password", "my-user-password");
credentials.put("provider", "idp");
credentials.put("additionalParameters", Collections.emptyMap());
io.gravitee.am.identityprovider.api.User user = new io.gravitee.am.identityprovider.api.DefaultUser("username");
Client client = new Client();
client.setSingleSignOut(true);
when(userAuthenticationManager.connect(any())).thenReturn(Single.just(new User()));
when(authenticationProvider.loadUserByUsername(any(EndUserAuthentication.class))).thenReturn(Maybe.just(user));
when(routingContext.get("client")).thenReturn(client);
when(routingContext.get("provider")).thenReturn(authenticationProvider);
when(routingContext.get("providerId")).thenReturn("idp");
when(routingContext.request()).thenReturn(httpServerRequest);
when(routingContext.data()).thenReturn(Map.of("id_token", "some_id_token"));
final io.vertx.core.http.HttpServerRequest delegateRequest = mock(io.vertx.core.http.HttpServerRequest.class);
when(httpServerRequest.getDelegate()).thenReturn(delegateRequest);
when(delegateRequest.method()).thenReturn(HttpMethod.POST);
CountDownLatch latch = new CountDownLatch(1);
authProvider.authenticate(routingContext, credentials, userAsyncResult -> {
latch.countDown();
Assert.assertNotNull(userAsyncResult);
Assert.assertNotNull(userAsyncResult.result());
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
verify(userAuthenticationManager, times(1)).connect(any());
verify(eventManager).publishEvent(argThat(evt -> evt == AuthenticationEvent.SUCCESS), any());
}
use of io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager in project gravitee-access-management by gravitee-io.
the class SocialAuthenticationProviderTest method shouldNotAuthenticateUser_noUser.
@Test
public void shouldNotAuthenticateUser_noUser() throws Exception {
JsonObject credentials = new JsonObject();
credentials.put("username", "my-user-id");
credentials.put("password", "my-user-password");
credentials.put("provider", "idp");
Client client = new Client();
when(authenticationProvider.loadUserByUsername(any(EndUserAuthentication.class))).thenReturn(Maybe.empty());
when(routingContext.get("client")).thenReturn(client);
when(routingContext.get("provider")).thenReturn(authenticationProvider);
when(routingContext.request()).thenReturn(httpServerRequest);
final io.vertx.core.http.HttpServerRequest delegateRequest = mock(io.vertx.core.http.HttpServerRequest.class);
when(httpServerRequest.getDelegate()).thenReturn(delegateRequest);
when(delegateRequest.method()).thenReturn(HttpMethod.POST);
CountDownLatch latch = new CountDownLatch(1);
authProvider.authenticate(routingContext, credentials, userAsyncResult -> {
latch.countDown();
Assert.assertNotNull(userAsyncResult);
Assert.assertTrue(userAsyncResult.failed());
Assert.assertTrue(userAsyncResult.cause() instanceof BadCredentialsException);
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
verify(userAuthenticationManager, never()).connect(any());
verify(eventManager).publishEvent(argThat(evt -> evt == AuthenticationEvent.FAILURE), any());
}
use of io.gravitee.am.gateway.handler.common.auth.user.UserAuthenticationManager in project gravitee-access-management by gravitee-io.
the class SocialAuthenticationProviderTest method shouldNotAuthenticateUser_badCredentials.
@Test
public void shouldNotAuthenticateUser_badCredentials() throws Exception {
JsonObject credentials = new JsonObject();
credentials.put("username", "my-user-id");
credentials.put("password", "my-user-password");
credentials.put("provider", "idp");
Client client = new Client();
when(authenticationProvider.loadUserByUsername(any(EndUserAuthentication.class))).thenReturn(Maybe.error(BadCredentialsException::new));
when(routingContext.get("client")).thenReturn(client);
when(routingContext.get("provider")).thenReturn(authenticationProvider);
when(routingContext.request()).thenReturn(httpServerRequest);
final io.vertx.core.http.HttpServerRequest delegateRequest = mock(io.vertx.core.http.HttpServerRequest.class);
when(httpServerRequest.getDelegate()).thenReturn(delegateRequest);
when(delegateRequest.method()).thenReturn(HttpMethod.POST);
CountDownLatch latch = new CountDownLatch(1);
authProvider.authenticate(routingContext, credentials, userAsyncResult -> {
latch.countDown();
Assert.assertNotNull(userAsyncResult);
Assert.assertTrue(userAsyncResult.failed());
Assert.assertTrue(userAsyncResult.cause() instanceof BadCredentialsException);
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
verify(userAuthenticationManager, never()).connect(any());
verify(eventManager).publishEvent(argThat(evt -> evt == AuthenticationEvent.FAILURE), any());
}
Aggregations