Skip to content

Commit 4590929

Browse files
author
pivotal
committed
Merge branch 'releases/2.7.0'
2 parents cab137b + 67372dd commit 4590929

File tree

156 files changed

+5436
-1343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+5436
-1343
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ task resetCoverage(type: Delete) {
231231

232232
apply plugin: 'cargo'
233233

234+
task cleanCargoConfDir {
235+
delete file(System.getenv('TMPDIR') + '/cargo/conf')
236+
}
237+
234238
cargoStartLocal.dependsOn assemble, prepareDatabase
235-
cargoRunLocal.dependsOn assemble
239+
cargoRunLocal.dependsOn cleanCargoConfDir, assemble
236240

237241
task flushCoverageData(type: Exec) {
238242
commandLine "curl", "-s", "-v", "-X", "POST", "http://localhost:8080/uaa/healthz/coverage/flush"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* *****************************************************************************
3+
* Cloud Foundry
4+
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved.
5+
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
6+
* You may not use this product except in compliance with the License.
7+
*
8+
* This product includes a number of subcomponents with
9+
* separate copyright notices and license terms. Your use of these
10+
* subcomponents is subject to the terms and conditions of the
11+
* subcomponent's license, as noted in the LICENSE file.
12+
* *****************************************************************************
13+
*/
14+
15+
package org.cloudfoundry.identity.uaa;
16+
17+
import java.util.List;
18+
19+
public abstract class AbstractIdentityProviderDefinition {
20+
public static final String EMAIL_DOMAIN_ATTR = "emailDomain";
21+
22+
private List<String> emailDomain;
23+
24+
public List<String> getEmailDomain() {
25+
return emailDomain;
26+
}
27+
28+
public AbstractIdentityProviderDefinition setEmailDomain(List<String> emailDomain) {
29+
this.emailDomain = emailDomain;
30+
return this;
31+
}
32+
}

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/Origin.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*******************************************************************************
2+
* Cloud Foundry
3+
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved.
4+
*
5+
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
6+
* You may not use this product except in compliance with the License.
7+
*
8+
* This product includes a number of subcomponents with
9+
* separate copyright notices and license terms. Your use of these
10+
* subcomponents is subject to the terms and conditions of the
11+
* subcomponent's license, as noted in the LICENSE file.
12+
*******************************************************************************/
113
package org.cloudfoundry.identity.uaa.authentication;
214

315
import org.cloudfoundry.identity.uaa.oauth.RemoteUserAuthentication;
@@ -7,9 +19,6 @@
719

820
import java.lang.reflect.Method;
921

10-
/**
11-
* Created by fhanik on 6/4/14.
12-
*/
1322
public class Origin {
1423

1524
public static final String ORIGIN = "origin";
@@ -19,6 +28,7 @@ public class Origin {
1928
public static final String KEYSTONE = "keystone";
2029
public static final String SAML = "saml";
2130
public static final String NotANumber = "NaN";
31+
public static final String UNKNOWN = "unknown";
2232

2333

2434
public static String getUserId(Authentication authentication) {

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/login/LoginInfoEndpoint.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import org.cloudfoundry.identity.uaa.login.AutologinRequest;
2424
import org.cloudfoundry.identity.uaa.login.AutologinResponse;
2525
import org.cloudfoundry.identity.uaa.login.PasscodeInformation;
26-
import org.cloudfoundry.identity.uaa.login.saml.IdentityProviderConfigurator;
27-
import org.cloudfoundry.identity.uaa.login.saml.IdentityProviderDefinition;
2826
import org.cloudfoundry.identity.uaa.login.saml.LoginSamlAuthenticationToken;
27+
import org.cloudfoundry.identity.uaa.login.saml.SamlIdentityProviderConfigurator;
28+
import org.cloudfoundry.identity.uaa.login.saml.SamlIdentityProviderDefinition;
29+
import org.cloudfoundry.identity.uaa.login.saml.SamlRedirectUtils;
2930
import org.cloudfoundry.identity.uaa.user.UaaAuthority;
3031
import org.cloudfoundry.identity.uaa.util.JsonUtils;
3132
import org.cloudfoundry.identity.uaa.util.UaaStringUtils;
32-
import org.cloudfoundry.identity.uaa.util.UaaUrlUtils;
3333
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
3434
import org.springframework.core.env.Environment;
3535
import org.springframework.core.io.support.PropertiesLoaderUtils;
@@ -40,6 +40,7 @@
4040
import org.springframework.security.crypto.codec.Base64;
4141
import org.springframework.security.oauth2.provider.ClientDetails;
4242
import org.springframework.security.oauth2.provider.ClientDetailsService;
43+
import org.springframework.security.oauth2.provider.NoSuchClientException;
4344
import org.springframework.security.web.savedrequest.SavedRequest;
4445
import org.springframework.stereotype.Controller;
4546
import org.springframework.ui.Model;
@@ -50,7 +51,6 @@
5051
import org.springframework.web.bind.annotation.RequestMethod;
5152
import org.springframework.web.bind.annotation.ResponseBody;
5253
import org.springframework.web.bind.annotation.ResponseStatus;
53-
import org.springframework.web.util.UriComponentsBuilder;
5454

5555
import javax.servlet.http.HttpServletRequest;
5656
import javax.servlet.http.HttpSession;
@@ -97,7 +97,7 @@ public class LoginInfoEndpoint {
9797

9898
protected Environment environment;
9999

100-
private IdentityProviderConfigurator idpDefinitions;
100+
private SamlIdentityProviderConfigurator idpDefinitions;
101101

102102
private long codeExpirationMillis = 5 * 60 * 1000;
103103

@@ -118,7 +118,7 @@ public void setCodeExpirationMillis(long codeExpirationMillis) {
118118
this.codeExpirationMillis = codeExpirationMillis;
119119
}
120120

121-
public void setIdpDefinitions(IdentityProviderConfigurator idpDefinitions) {
121+
public void setIdpDefinitions(SamlIdentityProviderConfigurator idpDefinitions) {
122122
this.idpDefinitions = idpDefinitions;
123123
}
124124

@@ -193,11 +193,7 @@ public String invalidRequest(HttpServletRequest request) {
193193
}
194194

195195
protected String getZonifiedEntityId() {
196-
if (UaaUrlUtils.isUrl(entityID)) {
197-
return UaaUrlUtils.addSubdomainToUrl(entityID);
198-
} else {
199-
return UaaUrlUtils.getSubdomain()+entityID;
200-
}
196+
return SamlRedirectUtils.getZonifiedEntityId(entityID);
201197
}
202198

203199
private String login(Model model, Principal principal, List<String> excludedPrompts, boolean nonHtml) {
@@ -208,7 +204,7 @@ private String login(Model model, Principal principal, List<String> excludedProm
208204
HttpSession session = request != null ? request.getSession(false) : null;
209205
List<String> allowedIdps = getAllowedIdps(session);
210206

211-
List<IdentityProviderDefinition> idps = getIdentityProviderDefinitions(allowedIdps);
207+
List<SamlIdentityProviderDefinition> idps = getSamlIdentityProviderDefinitions(allowedIdps);
212208

213209
boolean fieldUsernameShow = true;
214210

@@ -218,12 +214,8 @@ private String login(Model model, Principal principal, List<String> excludedProm
218214
allowedIdps.contains(Origin.KEYSTONE)) {
219215
fieldUsernameShow = true;
220216
} else if (idps!=null && idps.size()==1) {
221-
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("saml/discovery");
222-
builder.queryParam("returnIDParam", "idp");
223-
builder.queryParam("entityID", getZonifiedEntityId());
224-
builder.queryParam("idp", idps.get(0).getIdpEntityAlias());
225-
builder.queryParam("isPassive", "true");
226-
return "redirect:" + builder.build().toUriString();
217+
String url = SamlRedirectUtils.getIdpRedirectUrl(idps.get(0), entityID);
218+
return "redirect:" + url;
227219
} else {
228220
fieldUsernameShow = false;
229221
}
@@ -241,7 +233,7 @@ private String login(Model model, Principal principal, List<String> excludedProm
241233
// Entity ID to start the discovery
242234
model.addAttribute("entityID", getZonifiedEntityId());
243235
model.addAttribute("idpDefinitions", idps);
244-
for (IdentityProviderDefinition idp : idps) {
236+
for (SamlIdentityProviderDefinition idp : idps) {
245237
if(idp.isShowSamlLink()) {
246238
model.addAttribute("showSamlLoginLinks", true);
247239
noSamlIdpsPresent = false;
@@ -282,7 +274,7 @@ private String login(Model model, Principal principal, List<String> excludedProm
282274
return "home";
283275
}
284276

285-
protected List<IdentityProviderDefinition> getIdentityProviderDefinitions(List<String> allowedIdps) {
277+
protected List<SamlIdentityProviderDefinition> getSamlIdentityProviderDefinitions(List<String> allowedIdps) {
286278
return idpDefinitions.getIdentityProviderDefinitions(allowedIdps, IdentityZoneHolder.get());
287279
}
288280

@@ -305,8 +297,12 @@ public List<String> getAllowedIdps(HttpSession session) {
305297
}
306298
SavedRequest savedRequest = (SavedRequest) session.getAttribute("SPRING_SECURITY_SAVED_REQUEST");
307299
String[] client_ids = savedRequest.getParameterValues("client_id");
308-
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(client_ids[0]);
309-
return (List<String>) clientDetails.getAdditionalInformation().get(ClientConstants.ALLOWED_PROVIDERS);
300+
try {
301+
ClientDetails clientDetails = clientDetailsService.loadClientByClientId(client_ids[0]);
302+
return (List<String>) clientDetails.getAdditionalInformation().get(ClientConstants.ALLOWED_PROVIDERS);
303+
}catch (NoSuchClientException x) {
304+
return null;
305+
}
310306
}
311307

312308
private void setCommitInfo(Model model) {

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/AuthEvent.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
*/
2020
abstract public class AuthEvent extends ApplicationEvent {
2121

22-
public AuthEvent(UaaUser user) {
22+
private boolean userModified = true;
23+
24+
public AuthEvent(UaaUser user, boolean userUpdated) {
2325
super(user);
26+
this.userModified = userUpdated;
2427
}
2528

2629
public UaaUser getUser() {
2730
return (UaaUser) source;
2831
}
32+
33+
public boolean isUserModified() {
34+
return userModified;
35+
}
2936
}

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/ExternalGroupAuthorizationEvent.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Cloud Foundry
2+
* Cloud Foundry
33
* Copyright (c) [2009-2014] Pivotal Software, Inc. All Rights Reserved.
44
*
55
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
@@ -13,7 +13,6 @@
1313

1414
package org.cloudfoundry.identity.uaa.authentication.manager;
1515

16-
import org.cloudfoundry.identity.uaa.authentication.Origin;
1716
import org.cloudfoundry.identity.uaa.user.UaaUser;
1817
import org.springframework.security.core.GrantedAuthority;
1918

@@ -29,8 +28,8 @@ public Collection<? extends GrantedAuthority> getExternalAuthorities() {
2928

3029
private boolean addGroups = false;
3130

32-
public ExternalGroupAuthorizationEvent(UaaUser user, Collection<? extends GrantedAuthority> externalAuthorities, boolean addGroups) {
33-
super(user);
31+
public ExternalGroupAuthorizationEvent(UaaUser user, boolean userModified, Collection<? extends GrantedAuthority> externalAuthorities, boolean addGroups) {
32+
super(user, userModified);
3433
this.addGroups = addGroups;
3534
this.externalAuthorities = externalAuthorities;
3635
}

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/ExternalLoginAuthenticationManager.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.apache.commons.logging.Log;
1919
import org.apache.commons.logging.LogFactory;
20+
import org.cloudfoundry.identity.uaa.authentication.Origin;
2021
import org.cloudfoundry.identity.uaa.authentication.UaaAuthentication;
2122
import org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetails;
2223
import org.cloudfoundry.identity.uaa.authentication.UaaPrincipal;
@@ -34,6 +35,7 @@
3435
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
3536
import org.springframework.security.core.Authentication;
3637
import org.springframework.security.core.AuthenticationException;
38+
import org.springframework.security.core.context.SecurityContextHolder;
3739
import org.springframework.security.core.userdetails.User;
3840
import org.springframework.security.core.userdetails.UserDetails;
3941
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -106,7 +108,12 @@ public Authentication authenticate(Authentication request) throws Authentication
106108
}
107109
if (addnew) {
108110
// Register new users automatically
109-
publish(new NewUserAuthenticatedEvent(user));
111+
if (isInvite()) {
112+
user = user.modifyId(((UaaPrincipal)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
113+
publish(new InvitedUserAuthenticatedEvent(user));
114+
} else {
115+
publish(new NewUserAuthenticatedEvent(user));
116+
}
110117
try {
111118
user = userDatabase.retrieveUserByName(user.getUsername(), getOrigin());
112119
} catch (UsernameNotFoundException ex) {
@@ -127,6 +134,15 @@ public Authentication authenticate(Authentication request) throws Authentication
127134
return success;
128135
}
129136

137+
protected boolean isInvite() {
138+
Authentication a = SecurityContextHolder.getContext().getAuthentication();
139+
return (
140+
a != null &&
141+
a.getPrincipal() instanceof UaaPrincipal &&
142+
Origin.UNKNOWN.equals(((UaaPrincipal)a.getPrincipal()).getOrigin())
143+
);
144+
}
145+
130146
protected Map<String,String> getExtendedAuthorizationInfo(Authentication auth) {
131147
Object details = auth.getDetails();
132148
if (details!=null && details instanceof UaaAuthenticationDetails) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* *****************************************************************************
3+
* Cloud Foundry
4+
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved.
5+
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
6+
* You may not use this product except in compliance with the License.
7+
*
8+
* This product includes a number of subcomponents with
9+
* separate copyright notices and license terms. Your use of these
10+
* subcomponents is subject to the terms and conditions of the
11+
* subcomponent's license, as noted in the LICENSE file.
12+
* *****************************************************************************
13+
*/
14+
15+
package org.cloudfoundry.identity.uaa.authentication.manager;
16+
17+
import org.cloudfoundry.identity.uaa.user.UaaUser;
18+
19+
public class InvitedUserAuthenticatedEvent extends AuthEvent {
20+
21+
public InvitedUserAuthenticatedEvent(UaaUser user) {
22+
super(user, true);
23+
}
24+
}

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/LdapLoginAuthenticationManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ protected String getEmail(UaaUser user, LdapUserDetails details) {
7070

7171
@Override
7272
protected UaaUser userAuthenticated(Authentication request, UaaUser user) {
73+
boolean userModified = false;
7374
//we must check and see if the email address has changed between authentications
7475
if (request.getPrincipal() !=null && request.getPrincipal() instanceof ExtendedLdapUserDetails) {
7576
ExtendedLdapUserDetails details = (ExtendedLdapUserDetails)request.getPrincipal();
7677
UaaUser fromRequest = getUser(details, getExtendedAuthorizationInfo(request));
7778
if (fromRequest.getEmail()!=null && !fromRequest.getEmail().equals(user.getEmail())) {
7879
user = user.modifyEmail(fromRequest.getEmail());
80+
userModified = true;
7981
}
8082
}
81-
ExternalGroupAuthorizationEvent event = new ExternalGroupAuthorizationEvent(user, request.getAuthorities(), isAutoAddAuthorities());
83+
ExternalGroupAuthorizationEvent event = new ExternalGroupAuthorizationEvent(user, userModified, request.getAuthorities(), isAutoAddAuthorities());
8284
publish(event);
8385
return getUserDatabase().retrieveUserById(user.getId());
8486
}
@@ -92,4 +94,4 @@ public void setAutoAddAuthorities(boolean autoAddAuthorities) {
9294
}
9395

9496

95-
}
97+
}

common/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/NewUserAuthenticatedEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
public class NewUserAuthenticatedEvent extends AuthEvent {
2323

2424
public NewUserAuthenticatedEvent(UaaUser user) {
25-
super(user);
25+
super(user, true);
2626
}
2727
}

0 commit comments

Comments
 (0)