use of org.cloudfoundry.identity.uaa.zone.MultitenantClientServices in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method getPromptsFromNonOIDCProvider.
@Test
void getPromptsFromNonOIDCProvider() {
MockHttpServletRequest mockHttpServletRequest = getMockHttpServletRequest();
mockHttpServletRequest.setParameter("origin", "non-OIDC");
IdentityProvider provider = mock(IdentityProvider.class);
SamlIdentityProviderDefinition samlConfig = mock(SamlIdentityProviderDefinition.class);
when(provider.getConfig()).thenReturn(samlConfig);
when(mockIdentityProviderProvisioning.retrieveByOrigin("non-OIDC", "uaa")).thenReturn(provider);
MultitenantClientServices clientDetailsService = mockClientService();
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get(), clientDetailsService);
endpoint.infoForLoginJson(extendedModelMap, null, mockHttpServletRequest);
assertNotNull(extendedModelMap.get("prompts"));
assertTrue(extendedModelMap.get("prompts") instanceof Map);
Map<String, String[]> returnedPrompts = (Map<String, String[]>) extendedModelMap.get("prompts");
assertEquals(2, returnedPrompts.size());
assertNotNull(returnedPrompts.get("username"));
assertEquals("Email", returnedPrompts.get("username")[1]);
assertNotNull(returnedPrompts.get("password"));
assertEquals("Password", returnedPrompts.get("password")[1]);
}
use of org.cloudfoundry.identity.uaa.zone.MultitenantClientServices in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method filterIDPsForAuthcodeClientInOtherZone.
@Test
void filterIDPsForAuthcodeClientInOtherZone() throws Exception {
// mock session and saved request
MockHttpServletRequest request = getMockHttpServletRequest();
IdentityZone zone = MultitenancyFixture.identityZone("other-zone", "other-zone");
IdentityZoneHolder.set(zone);
List<String> allowedProviders = Arrays.asList("my-client-awesome-idp1", "my-client-awesome-idp2");
// mock Client service
BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("client-id");
clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, new LinkedList<>(allowedProviders));
MultitenantClientServices clientDetailsService = mock(MultitenantClientServices.class);
when(clientDetailsService.loadClientByClientId("client-id", "other-zone")).thenReturn(clientDetails);
// mock SamlIdentityProviderConfigurator
List<SamlIdentityProviderDefinition> clientIDPs = new LinkedList<>();
clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp1", "uaa"));
clientIDPs.add(createIdentityProviderDefinition("my-client-awesome-idp2", "uaa"));
when(mockSamlIdentityProviderConfigurator.getIdentityProviderDefinitions(eq(allowedProviders), eq(zone))).thenReturn(clientIDPs);
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get(), clientDetailsService);
endpoint.loginForHtml(extendedModelMap, null, request, singletonList(MediaType.TEXT_HTML));
Collection<SamlIdentityProviderDefinition> idpDefinitions = (Collection<SamlIdentityProviderDefinition>) extendedModelMap.asMap().get("idpDefinitions");
assertEquals(2, idpDefinitions.size());
assertThat(idpDefinitions, PredicateMatcher.has(c -> c.getIdpEntityAlias().equals("my-client-awesome-idp1")));
assertThat(idpDefinitions, PredicateMatcher.has(SamlIdentityProviderDefinition::isShowSamlLink));
assertEquals(false, extendedModelMap.asMap().get("fieldUsernameShow"));
assertEquals(false, extendedModelMap.asMap().get("linkCreateAccountShow"));
}
use of org.cloudfoundry.identity.uaa.zone.MultitenantClientServices in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method loginHintOriginOidc.
@Test
void loginHintOriginOidc() throws Exception {
MockHttpServletRequest mockHttpServletRequest = getMockHttpServletRequest();
MultitenantClientServices clientDetailsService = mockClientService();
mockOidcProvider(mockIdentityProviderProvisioning);
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get(), clientDetailsService);
SavedRequest savedRequest = SessionUtils.getSavedRequestSession(mockHttpServletRequest.getSession());
when(savedRequest.getParameterValues("login_hint")).thenReturn(new String[] { "{\"origin\":\"my-OIDC-idp1\"}" });
String redirect = endpoint.loginForHtml(extendedModelMap, null, mockHttpServletRequest, singletonList(MediaType.TEXT_HTML));
assertThat(redirect, startsWith("redirect:http://localhost:8080/uaa"));
assertThat(redirect, containsString("my-OIDC-idp1"));
assertNull(extendedModelMap.get("login_hint"));
}
use of org.cloudfoundry.identity.uaa.zone.MultitenantClientServices in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method loginHintOriginOidcForJson.
@Test
void loginHintOriginOidcForJson() throws Exception {
MockHttpServletRequest mockHttpServletRequest = getMockHttpServletRequest();
MultitenantClientServices clientDetailsService = mockClientService();
mockOidcProvider(mockIdentityProviderProvisioning);
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get(), clientDetailsService);
SavedRequest savedRequest = SessionUtils.getSavedRequestSession(mockHttpServletRequest.getSession());
when(savedRequest.getParameterValues("login_hint")).thenReturn(new String[] { "{\"origin\":\"my-OIDC-idp1\"}" });
endpoint.infoForLoginJson(extendedModelMap, null, mockHttpServletRequest);
assertNotNull(extendedModelMap.get("prompts"));
assertTrue(extendedModelMap.get("prompts") instanceof Map);
Map<String, String[]> returnedPrompts = (Map<String, String[]>) extendedModelMap.get("prompts");
assertEquals(3, returnedPrompts.size());
}
use of org.cloudfoundry.identity.uaa.zone.MultitenantClientServices in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method defaultProviderLdapWithAllowedOnlyOIDC.
@Test
void defaultProviderLdapWithAllowedOnlyOIDC() throws Exception {
MockHttpServletRequest mockHttpServletRequest = getMockHttpServletRequest();
List<String> allowedProviders = singletonList("my-OIDC-idp1");
// mock Client service
BaseClientDetails clientDetails = new BaseClientDetails();
clientDetails.setClientId("client-id");
clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, new LinkedList<>(allowedProviders));
MultitenantClientServices clientDetailsService = mock(MultitenantClientServices.class);
when(clientDetailsService.loadClientByClientId("client-id", "uaa")).thenReturn(clientDetails);
mockOidcProvider(mockIdentityProviderProvisioning);
IdentityZoneHolder.get().getConfig().setDefaultIdentityProvider("ldap");
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get(), clientDetailsService);
String redirect = endpoint.loginForHtml(extendedModelMap, null, mockHttpServletRequest, singletonList(MediaType.TEXT_HTML));
assertThat(redirect, startsWith("redirect:http://localhost:8080/uaa"));
assertThat(redirect, containsString("my-OIDC-idp1"));
assertFalse(extendedModelMap.containsKey("login_hint"));
}
Aggregations