use of org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition 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.provider.SamlIdentityProviderDefinition 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.provider.SamlIdentityProviderDefinition in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method filterIdpsForDefaultZone.
@Test
void filterIdpsForDefaultZone() throws Exception {
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get());
// mock session and saved request
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
SavedRequest savedRequest = mock(SavedRequest.class);
when(savedRequest.getParameterValues("client_id")).thenReturn(new String[] { "client-id" });
when(savedRequest.getRedirectUrl()).thenReturn("http://localhost:8080/uaa");
SessionUtils.setSavedRequestSession(session, savedRequest);
request.setSession(session);
// mock SamlIdentityProviderConfigurator
when(mockSamlIdentityProviderConfigurator.getIdentityProviderDefinitions((List<String>) isNull(), eq(IdentityZone.getUaa()))).thenReturn(idps);
endpoint.loginForHtml(extendedModelMap, null, request, singletonList(MediaType.TEXT_HTML));
Collection<SamlIdentityProviderDefinition> idpDefinitions = (Collection<SamlIdentityProviderDefinition>) extendedModelMap.asMap().get("idpDefinitions");
assertEquals(2, idpDefinitions.size());
Iterator<SamlIdentityProviderDefinition> iterator = idpDefinitions.iterator();
SamlIdentityProviderDefinition clientIdp = iterator.next();
assertEquals("awesome-idp", clientIdp.getIdpEntityAlias());
assertTrue(clientIdp.isShowSamlLink());
clientIdp = iterator.next();
assertEquals("my-client-awesome-idp", clientIdp.getIdpEntityAlias());
assertTrue(clientIdp.isShowSamlLink());
assertEquals(true, extendedModelMap.asMap().get("fieldUsernameShow"));
assertEquals(true, extendedModelMap.asMap().get("linkCreateAccountShow"));
}
use of org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method saml_links_for_json.
@Test
void saml_links_for_json() {
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get());
when(mockSamlIdentityProviderConfigurator.getIdentityProviderDefinitions(any(), any())).thenReturn(idps);
endpoint.infoForJson(extendedModelMap, null, new MockHttpServletRequest("GET", "http://someurl"));
Map<String, Object> links = (Map<String, Object>) extendedModelMap.asMap().get("links");
assertEquals("http://someurl", links.get("login"));
assertTrue(extendedModelMap.get("idpDefinitions") instanceof Map);
Map<String, String> idpDefinitions = (Map<String, String>) extendedModelMap.get("idpDefinitions");
for (SamlIdentityProviderDefinition def : idps) {
assertEquals("http://someurl/saml/discovery?returnIDParam=idp&entityID=" + endpoint.getZonifiedEntityId() + "&idp=" + def.getIdpEntityAlias() + "&isPassive=true", idpDefinitions.get(def.getIdpEntityAlias()));
}
}
use of org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition in project uaa by cloudfoundry.
the class LoginInfoEndpointTests method filterIdpsWithNoSavedRequest.
@Test
void filterIdpsWithNoSavedRequest() throws Exception {
LoginInfoEndpoint endpoint = getEndpoint(IdentityZoneHolder.get());
when(mockSamlIdentityProviderConfigurator.getIdentityProviderDefinitions((List<String>) isNull(), eq(IdentityZone.getUaa()))).thenReturn(idps);
endpoint.loginForHtml(extendedModelMap, null, new MockHttpServletRequest(), singletonList(MediaType.TEXT_HTML));
Collection<SamlIdentityProviderDefinition> idpDefinitions = (Collection<SamlIdentityProviderDefinition>) extendedModelMap.asMap().get("idpDefinitions");
assertEquals(2, idpDefinitions.size());
Iterator<SamlIdentityProviderDefinition> iterator = idpDefinitions.iterator();
SamlIdentityProviderDefinition clientIdp = iterator.next();
assertEquals("awesome-idp", clientIdp.getIdpEntityAlias());
assertTrue(clientIdp.isShowSamlLink());
clientIdp = iterator.next();
assertEquals("my-client-awesome-idp", clientIdp.getIdpEntityAlias());
assertTrue(clientIdp.isShowSamlLink());
assertEquals(true, extendedModelMap.asMap().get("fieldUsernameShow"));
assertEquals(true, extendedModelMap.asMap().get("linkCreateAccountShow"));
}
Aggregations