use of io.gravitee.am.model.IdentityProvider in project gravitee-access-management by gravitee-io.
the class IdentifierFirstLoginEndpoint method redirect.
private void redirect(RoutingContext routingContext) {
final List<IdentityProvider> socialProviders = routingContext.get(SOCIAL_PROVIDER_CONTEXT_KEY);
final String username = routingContext.request().getParam(USERNAME_PARAM_KEY);
final String[] domainName = username.split("@");
// username is not an email, continue
if (domainName.length < 2) {
doInternalRedirect(routingContext);
return;
}
// no social providers configured, continue
if (socialProviders == null) {
doInternalRedirect(routingContext);
return;
}
final IdentityProvider identityProvider = socialProviders.stream().filter(s -> s.getDomainWhitelist() != null && s.getDomainWhitelist().stream().anyMatch(domainName[1]::equals)).findFirst().orElse(null);
// no IdP has matched, continue
if (identityProvider == null) {
doInternalRedirect(routingContext);
return;
}
// else, redirect to the external provider
doExternalRedirect(routingContext, identityProvider);
}
use of io.gravitee.am.model.IdentityProvider in project gravitee-access-management by gravitee-io.
the class IdentifierFirstLoginEndpointTest method shouldInvokeLoginEndpoint_redirectUsernameMatchesDomain.
@Test
public void shouldInvokeLoginEndpoint_redirectUsernameMatchesDomain() throws Exception {
router.route(HttpMethod.POST, "/login/identifier").handler(routingContext -> {
final IdentityProvider idp = new IdentityProvider();
idp.setId("provider-id");
idp.setDomainWhitelist(List.of("domain.com"));
routingContext.put(SOCIAL_PROVIDER_CONTEXT_KEY, List.of(idp));
routingContext.put(SOCIAL_AUTHORIZE_URL_CONTEXT_KEY, Map.of(idp.getId(), "https://host/some/provider/oauth/authorize"));
routingContext.next();
}).handler(identifierFirstLoginEndpoint::handle);
when(clientSyncService.findByClientId(appClient.getClientId())).thenReturn(Maybe.just(appClient));
testRequest(HttpMethod.POST, "/login/identifier?username=username@domain.com&client_id=" + appClient.getClientId() + "&response_type=code&redirect_uri=somewhere.com", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertTrue(location.contains("https://host/some/provider/oauth/authorize?login_hint=username%40domain.com"));
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.gravitee.am.model.IdentityProvider in project gravitee-access-management by gravitee-io.
the class IdentifierFirstLoginEndpointTest method shouldInvokeLoginEndpoint_redirectUsernameMatchesDomainAndSpecificIdp.
@Test
public void shouldInvokeLoginEndpoint_redirectUsernameMatchesDomainAndSpecificIdp() throws Exception {
router.route(HttpMethod.POST, "/login/identifier").handler(routingContext -> {
final IdentityProvider idp = new IdentityProvider();
idp.setId("provider-id");
idp.setDomainWhitelist(List.of("domain.com"));
idp.setType("google");
routingContext.put(SOCIAL_PROVIDER_CONTEXT_KEY, List.of(idp));
routingContext.put(SOCIAL_AUTHORIZE_URL_CONTEXT_KEY, Map.of(idp.getId(), "https://host/some/provider/oauth/authorize"));
routingContext.next();
}).handler(identifierFirstLoginEndpoint::handle);
when(clientSyncService.findByClientId(appClient.getClientId())).thenReturn(Maybe.just(appClient));
testRequest(HttpMethod.POST, "/login/identifier?username=username@domain.com&client_id=" + appClient.getClientId() + "&response_type=code&redirect_uri=somewhere.com", null, resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertTrue(location.equals("https://host/some/provider/oauth/authorize?login_hint=username%40domain.com"));
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.gravitee.am.model.IdentityProvider in project gravitee-access-management by gravitee-io.
the class LoginEndpointHandlerTest method shouldInvokeLoginEndpoint_redirectProvider.
@Test
public void shouldInvokeLoginEndpoint_redirectProvider() throws Exception {
appClient.getLoginSettings().setIdentifierFirstEnabled(false);
appClient.getLoginSettings().setHideForm(TRUE);
router.route(HttpMethod.GET, "/login").handler(routingContext -> {
final IdentityProvider idp = new IdentityProvider();
idp.setId("provider-id");
routingContext.put(SOCIAL_PROVIDER_CONTEXT_KEY, List.of(idp));
routingContext.put(SOCIAL_AUTHORIZE_URL_CONTEXT_KEY, Map.of(idp.getId(), "/some/provider/oauth/authorize"));
routingContext.next();
}).handler(new LoginHideFormHandler(domain)).handler(get302AssertMockRoutingContextHandler(loginEndpoint, true, false));
when(clientSyncService.findByClientId(appClient.getClientId())).thenReturn(Maybe.just(appClient));
testRequest(HttpMethod.GET, "/login?client_id=" + appClient.getClientId() + "&response_type=code&redirect_uri=somewhere.com", HttpStatusCode.FOUND_302, "Found");
}
use of io.gravitee.am.model.IdentityProvider in project gravitee-access-management by gravitee-io.
the class LoginEndpointHandlerTest method shouldInvokeLoginEndpoint_noRedirectMultipleProviders.
@Test
public void shouldInvokeLoginEndpoint_noRedirectMultipleProviders() throws Exception {
appClient.getLoginSettings().setIdentifierFirstEnabled(false);
appClient.getLoginSettings().setHideForm(TRUE);
router.route(HttpMethod.GET, "/login").handler(routingContext -> {
final IdentityProvider idp1 = new IdentityProvider();
idp1.setId("provider-id-1");
final IdentityProvider idp2 = new IdentityProvider();
idp2.setId("provider-id-2");
routingContext.put(SOCIAL_PROVIDER_CONTEXT_KEY, List.of(idp1, idp2));
routingContext.next();
}).handler(new LoginHideFormHandler(domain)).handler(get200AssertMockRoutingContextHandler(loginEndpoint, true, false));
when(clientSyncService.findByClientId(appClient.getClientId())).thenReturn(Maybe.just(appClient));
testRequest(HttpMethod.GET, "/login?client_id=" + appClient.getClientId() + "&response_type=code&redirect_uri=somewhere.com", HttpStatusCode.OK_200, "OK");
}
Aggregations