Skip to content

Commit

Permalink
display client name if present for IDP Dicovery
Browse files Browse the repository at this point in the history
[#117269923] https://www.pivotaltracker.com/story/show/117269923

Signed-off-by: Priyata Agrawal <pagrawal@pivotal.io>
  • Loading branch information
mbhave authored and Priyata25 committed May 4, 2016
1 parent e88a116 commit 50535aa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
Expand Up @@ -34,7 +34,6 @@
import org.cloudfoundry.identity.uaa.util.UaaStringUtils; import org.cloudfoundry.identity.uaa.util.UaaStringUtils;
import org.cloudfoundry.identity.uaa.zone.IdentityZone; import org.cloudfoundry.identity.uaa.zone.IdentityZone;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration; import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneConfigurationValidator;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder; import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
Expand Down Expand Up @@ -223,7 +222,13 @@ private String login(Model model, Principal principal, List<String> excludedProm


private String login(Model model, Principal principal, List<String> excludedPrompts, boolean jsonResponse, HttpServletRequest request) { private String login(Model model, Principal principal, List<String> excludedPrompts, boolean jsonResponse, HttpServletRequest request) {
HttpSession session = request != null ? request.getSession(false) : null; HttpSession session = request != null ? request.getSession(false) : null;
List<String> allowedIdps = getAllowedIdps(session); List<String> allowedIdps = null;
String clientName = null;
Map<String,Object> clientInfo;
if((clientInfo = getClientInfo(session)) != null) {
allowedIdps = (List<String>) clientInfo.get(ClientConstants.ALLOWED_PROVIDERS);
clientName = (String) clientInfo.get(ClientConstants.CLIENT_NAME);
}


Map<String, SamlIdentityProviderDefinition> samlIdps = getSamlIdentityProviderDefinitions(allowedIdps); Map<String, SamlIdentityProviderDefinition> samlIdps = getSamlIdentityProviderDefinitions(allowedIdps);
Map<String, AbstractXOAuthIdentityProviderDefinition> oauthIdentityProviderDefinitions = getOauthIdentityProviderDefinitions(); Map<String, AbstractXOAuthIdentityProviderDefinition> oauthIdentityProviderDefinitions = getOauthIdentityProviderDefinitions();
Expand Down Expand Up @@ -321,6 +326,7 @@ private String login(Model model, Principal principal, List<String> excludedProm
model.addAttribute(FIELD_USERNAME_SHOW, fieldUsernameShow); model.addAttribute(FIELD_USERNAME_SHOW, fieldUsernameShow);
model.addAttribute(IDP_DEFINITIONS, samlIdps.values()); model.addAttribute(IDP_DEFINITIONS, samlIdps.values());
model.addAttribute(OAUTH_DEFINITIONS, oauthIdentityProviderDefinitions); model.addAttribute(OAUTH_DEFINITIONS, oauthIdentityProviderDefinitions);
model.addAttribute("clientName", clientName);
} }
model.addAttribute(LINKS, links); model.addAttribute(LINKS, links);
setCommitInfo(model); setCommitInfo(model);
Expand Down Expand Up @@ -404,15 +410,15 @@ protected boolean hasSavedOauthAuthorizeRequest(HttpSession session) {
return false; return false;
} }


public List<String> getAllowedIdps(HttpSession session) { public Map<String, Object> getClientInfo(HttpSession session) {
if (!hasSavedOauthAuthorizeRequest(session)) { if (!hasSavedOauthAuthorizeRequest(session)) {
return null; return null;
} }
SavedRequest savedRequest = (SavedRequest) session.getAttribute("SPRING_SECURITY_SAVED_REQUEST"); SavedRequest savedRequest = (SavedRequest) session.getAttribute("SPRING_SECURITY_SAVED_REQUEST");
String[] client_ids = savedRequest.getParameterValues("client_id"); String[] client_ids = savedRequest.getParameterValues("client_id");
try { try {
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(client_ids[0]); ClientDetails clientDetails = clientDetailsService.loadClientByClientId(client_ids[0]);
return (List<String>) clientDetails.getAdditionalInformation().get(ClientConstants.ALLOWED_PROVIDERS); return clientDetails.getAdditionalInformation();
} catch (NoSuchClientException x) { } catch (NoSuchClientException x) {
return null; return null;
} }
Expand Down
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layouts/pivotal-ui-main"> <html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layouts/pivotal-ui-main">
<div layout:fragment="page-content"> <div layout:fragment="page-content">
<h4 class="txt-c pbxxl ptxl"> <h4 class="txt-c pbxxl ptxl" th:text="${T(org.springframework.util.StringUtils).hasText(clientName) ? 'Sign in to continue to ' + clientName : 'Sign in to continue'}">
Sign in to continue Sign in to continue
</h4> </h4>
<form action="/login/password" th:action="@{/login/password}" method="post" role="form" _lpchecked="1"> <form action="/login/password" th:action="@{/login/password}" method="post" role="form" _lpchecked="1">
Expand Down
Expand Up @@ -1645,6 +1645,50 @@ public void idpDiscoveryPageDisplayed_IfFlagIsEnabled() throws Exception {
getWebApplicationContext().getBean(LoginInfoEndpoint.class).setIdpDiscoveryEnabled(false); getWebApplicationContext().getBean(LoginInfoEndpoint.class).setIdpDiscoveryEnabled(false);
} }


@Test
public void idpDiscoveryClientNameDisplayed() throws Exception {
getWebApplicationContext().getBean(LoginInfoEndpoint.class).setIdpDiscoveryEnabled(true);
BaseClientDetails client = new BaseClientDetails("koala-client", "", "", "client_credentials", "uaa.none", "http://*.wildcard.testing,http://testing.com");
client.setClientSecret("secret");
client.addAdditionalInformation(ClientConstants.CLIENT_NAME, "woohoo");
MockMvcUtils.utils().createClient(getMockMvc(), adminToken, client);

MockHttpSession session = new MockHttpSession();
SavedRequest savedRequest = new DefaultSavedRequest(new MockHttpServletRequest(), new PortResolverImpl()) {
@Override
public String getRedirectUrl() {
return "http://test/redirect/oauth/authorize";
}
@Override
public String[] getParameterValues(String name) {
if ("client_id".equals(name)) {
return new String[] {"koala-client"};
}
return new String[0];
}
@Override public List<Cookie> getCookies() { return null; }
@Override public String getMethod() { return null; }
@Override public List<String> getHeaderValues(String name) { return null; }
@Override
public Collection<String> getHeaderNames() { return null; }
@Override public List<Locale> getLocales() { return null; }
@Override public Map<String, String[]> getParameterMap() { return null; }
};
session.setAttribute("SPRING_SECURITY_SAVED_REQUEST", savedRequest);

getMockMvc().perform(get("/login")
.session(session)
.header("Accept", TEXT_HTML))
.andExpect(status().isOk())
.andExpect(view().name("idp_discovery/email"))
.andExpect(content().string(containsString("Sign in to continue to woohoo")))
.andExpect(xpath("//input[@name='email']").exists())
.andExpect(xpath("//div[@class='action']//a").string("Create account"))
.andExpect(xpath("//input[@type='submit']/@value").string("Next"));

getWebApplicationContext().getBean(LoginInfoEndpoint.class).setIdpDiscoveryEnabled(false);
}

@Test @Test
public void emailPageIdpDiscoveryEnabled_SelfServiceLinksDisabled() throws Exception { public void emailPageIdpDiscoveryEnabled_SelfServiceLinksDisabled() throws Exception {
setSelfServiceLinksEnabled(false); setSelfServiceLinksEnabled(false);
Expand Down

0 comments on commit 50535aa

Please sign in to comment.