Skip to content

Commit

Permalink
Add support for configuring global links
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanik committed May 5, 2017
1 parent 56dd407 commit e7970f6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
14 changes: 14 additions & 0 deletions model/src/main/java/org/cloudfoundry/identity/uaa/zone/Links.java
Expand Up @@ -14,6 +14,7 @@

package org.cloudfoundry.identity.uaa.zone;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

Expand All @@ -24,6 +25,19 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class Links {

@JsonIgnore
private static SelfService globalService = null;

@JsonIgnore
public static SelfService getGlobalService() {
return globalService;
}

@JsonIgnore
public static void setGlobalService(SelfService globalService) {
Links.globalService = globalService;
}

private SelfService service = new SelfService();
private Logout logout = new Logout();
private String homeRedirect = null;
Expand Down
@@ -1,6 +1,6 @@
/*******************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved.
* Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
Expand Down
Expand Up @@ -33,7 +33,7 @@ public class IdentityZoneConfigurationBootstrap implements InitializingBean {
private IdentityZoneProvisioning provisioning;
private boolean selfServiceLinksEnabled = true;
private String homeRedirect = null;
private Map<String,String> selfServiceLinks;
private Map<String,Object> selfServiceLinks;
private List<String> logoutRedirectWhitelist;
private String logoutRedirectParameterName;
private String logoutDefaultRedirectUrl;
Expand Down Expand Up @@ -83,8 +83,15 @@ public void afterPropertiesSet() throws InvalidIdentityZoneDetailsException {
definition.getSamlConfig().setActiveKeyId(this.activeKeyId);

if (selfServiceLinks!=null) {
String signup = selfServiceLinks.get("signup");
String passwd = selfServiceLinks.get("passwd");
if (selfServiceLinks.get("global")!=null) {
Map<String, String> global = (Map<String, String>) selfServiceLinks.remove("global");
Links.SelfService globalService = new Links.SelfService();
globalService.setPasswd(global.get("passwd"));
globalService.setSignup(global.get("signup"));
Links.setGlobalService(globalService);
}
String signup = (String)selfServiceLinks.get("signup");
String passwd = (String)selfServiceLinks.get("passwd");
if (hasText(signup)) {
definition.getLinks().getSelfService().setSignup(signup);
}
Expand Down Expand Up @@ -142,7 +149,7 @@ public void setHomeRedirect(String homeRedirect) {
}
}

public void setSelfServiceLinks(Map<String, String> links) {
public void setSelfServiceLinks(Map<String, Object> links) {
this.selfServiceLinks = links;
}

Expand Down
Expand Up @@ -52,7 +52,7 @@ public class IdentityZoneConfigurationBootstrapTests extends JdbcTestBase {
public static final String ID = "id";
private IdentityZoneProvisioning provisioning;
private IdentityZoneConfigurationBootstrap bootstrap;
private Map<String, String> links = new HashMap<>();
private Map<String, Object> links = new HashMap<>();


@Before
Expand Down Expand Up @@ -160,6 +160,18 @@ public void signup_link_configured() throws Exception {
assertEquals("/forgot_password", zone.getConfig().getLinks().getSelfService().getPasswd());
}

@Test
public void global_links_set() throws Exception {
Map<String,String> global = new HashMap<>();
global.put("signup", "https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/create_account");
global.put("passwd", "https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/forgot_password");
links.put("global", global);
signup_link_configured();
assertEquals("https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/create_account", Links.getGlobalService().getSignup());
assertEquals("https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/forgot_password", Links.getGlobalService().getPasswd());
}


@Test
public void passwd_link_configured() throws Exception {
links.put("passwd", "/configured_passwd");
Expand Down
@@ -1,3 +1,15 @@
/*******************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
*******************************************************************************/
package org.cloudfoundry.identity.uaa.login;

import org.cloudfoundry.identity.uaa.TestClassNullifier;
Expand Down
Expand Up @@ -259,6 +259,7 @@ public void defaults_and_required_properties() throws Exception {

assertFalse(zoneConfiguration.isAccountChooserEnabled());
assertTrue(zoneConfiguration.getLinks().getSelfService().isSelfServiceLinksEnabled());
assertNull(zoneConfiguration.getLinks().getGlobalService());
assertNull(zoneConfiguration.getLinks().getHomeRedirect());
assertEquals("redirect", zoneConfiguration.getLinks().getLogout().getRedirectParameterName());
assertEquals("/login", zoneConfiguration.getLinks().getLogout().getRedirectUrl());
Expand Down Expand Up @@ -452,6 +453,8 @@ public void all_properties_set() throws Exception {
assertEquals("http://some.redirect.com/redirect", zoneConfiguration.getLinks().getHomeRedirect());
assertEquals("/configured_signup", zoneConfiguration.getLinks().getSelfService().getSignup());
assertEquals("/configured_passwd", zoneConfiguration.getLinks().getSelfService().getPasswd());
assertEquals("https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/create_account", zoneConfiguration.getLinks().getGlobalService().getSignup());
assertEquals("https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/forgot_password", zoneConfiguration.getLinks().getGlobalService().getPasswd());

assertEquals("redirect", zoneConfiguration.getLinks().getLogout().getRedirectParameterName());
assertEquals("/configured_login", zoneConfiguration.getLinks().getLogout().getRedirectUrl());
Expand Down
3 changes: 3 additions & 0 deletions uaa/src/test/resources/test/bootstrap/all-properties-set.yml
Expand Up @@ -107,6 +107,9 @@ ldap:
file: ldap/ldap-search-and-bind.xml
providerDescription: Test LDAP Provider Description
links:
global:
passwd: "https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/forgot_password"
signup: "https://{zone.subdomain}.myaccountmanager.domain.com/z/{zone.id}/create_account"
passwd: /configured_passwd
signup: /configured_signup
login:
Expand Down

0 comments on commit e7970f6

Please sign in to comment.