Skip to content

Commit e67a40a

Browse files
duanemayiprotsiuk
authored andcommitted
wip: Break up AuthProvider
Move user shadowing, attribute processing, and authorities processing to their own classes. Enable Authorities Signed-off-by: Ivan Protsiuk <ivan.protsiuk@broadcom.com>
1 parent 82cd034 commit e67a40a

22 files changed

+1205
-1674
lines changed

server/src/main/java/org/cloudfoundry/identity/uaa/authentication/UaaAuthentication.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,6 @@ public UaaAuthentication(UaaPrincipal uaaPrincipal,
109109
this.userAttributes = new HashMap<>(userAttributes);
110110
}
111111

112-
public UaaAuthentication(UaaAuthentication existingAuthn, UaaPrincipal principal) {
113-
114-
this(principal, existingAuthn.getCredentials(), List.copyOf(existingAuthn.getAuthorities()), existingAuthn.getExternalGroups(),
115-
existingAuthn.getUserAttributes(), existingAuthn.getUaaAuthenticationDetails(), existingAuthn.isAuthenticated(),
116-
existingAuthn.getAuthenticatedTime(), existingAuthn.getExpiresAt());
117-
this.authContextClassRef = existingAuthn.authContextClassRef;
118-
this.authenticationMethods = existingAuthn.authenticationMethods;
119-
this.lastLoginSuccessTime = existingAuthn.lastLoginSuccessTime;
120-
}
121-
122112
@Override
123113
public String getName() {
124114
// Should we return the ID for the principal name? (No, because the

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/OpenSaml40CompatibleAssertionValidators.java

Lines changed: 0 additions & 247 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.cloudfoundry.identity.uaa.provider.saml;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition;
5+
import org.opensaml.core.xml.XMLObject;
6+
import org.opensaml.core.xml.schema.XSAny;
7+
import org.opensaml.core.xml.schema.XSBase64Binary;
8+
import org.opensaml.core.xml.schema.XSBoolean;
9+
import org.opensaml.core.xml.schema.XSBooleanValue;
10+
import org.opensaml.core.xml.schema.XSDateTime;
11+
import org.opensaml.core.xml.schema.XSInteger;
12+
import org.opensaml.core.xml.schema.XSQName;
13+
import org.opensaml.core.xml.schema.XSString;
14+
import org.opensaml.core.xml.schema.XSURI;
15+
16+
import javax.xml.namespace.QName;
17+
import java.time.Instant;
18+
19+
@Slf4j
20+
public class OpenSamlXmlUtils {
21+
22+
private OpenSamlXmlUtils() {
23+
throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
24+
}
25+
26+
public static String getStringValue(String key, SamlIdentityProviderDefinition definition, XMLObject xmlObject) {
27+
String value = null;
28+
if (xmlObject instanceof XSString xsString) {
29+
value = xsString.getValue();
30+
} else if (xmlObject instanceof XSAny xsAny) {
31+
value = xsAny.getTextContent();
32+
} else if (xmlObject instanceof XSInteger xsInteger) {
33+
Integer i = xsInteger.getValue();
34+
value = i != null ? i.toString() : null;
35+
} else if (xmlObject instanceof XSBoolean xsBoolean) {
36+
XSBooleanValue b = xsBoolean.getValue();
37+
value = b != null && b.getValue() != null ? b.getValue().toString() : null;
38+
} else if (xmlObject instanceof XSDateTime xsDateTime) {
39+
Instant d = xsDateTime.getValue();
40+
value = d != null ? d.toString() : null;
41+
} else if (xmlObject instanceof XSQName xsQName) {
42+
QName name = xsQName.getValue();
43+
value = name != null ? name.toString() : null;
44+
} else if (xmlObject instanceof XSURI xsUri) {
45+
value = xsUri.getURI();
46+
} else if (xmlObject instanceof XSBase64Binary xsBase64Binary) {
47+
value = xsBase64Binary.getValue();
48+
}
49+
50+
if (value != null) {
51+
log.debug("Found SAML user attribute {} of value {} [zone:{}, origin:{}]", key, value, definition.getZoneId(), definition.getIdpEntityAlias());
52+
return value;
53+
} else if (xmlObject != null) {
54+
log.debug("SAML user attribute {} at is not of type XSString or other recognizable type, {} [zone:{}, origin:{}]", key, xmlObject.getClass().getName(), definition.getZoneId(), definition.getIdpEntityAlias());
55+
}
56+
return null;
57+
}
58+
}

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/Saml2Utils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
public final class Saml2Utils {
4040

4141
private Saml2Utils() {
42+
throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
4243
}
4344

4445
public static String samlEncode(byte[] b) {

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/SamlAuthenticationFilterConfig.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.cloudfoundry.identity.uaa.provider.saml;
22

33
import org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning;
4+
import org.cloudfoundry.identity.uaa.scim.ScimGroupExternalMembershipManager;
45
import org.cloudfoundry.identity.uaa.user.UaaUserDatabase;
56
import org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager;
67
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.context.ApplicationEventPublisher;
79
import org.springframework.context.annotation.Bean;
810
import org.springframework.context.annotation.Configuration;
911
import org.springframework.core.convert.converter.Converter;
@@ -49,16 +51,23 @@ SecurityContextRepository securityContextRepository() {
4951
@Bean
5052
AuthenticationProvider samlAuthenticationProvider(IdentityZoneManager identityZoneManager,
5153
final UaaUserDatabase userDatabase,
52-
final JdbcIdentityProviderProvisioning identityProviderProvisioning) {
54+
final JdbcIdentityProviderProvisioning identityProviderProvisioning,
55+
ScimGroupExternalMembershipManager externalMembershipManager,
5356

54-
// SamlUaaResponseAuthenticationConverter samlResponseAuthenticationConverter =
55-
// new SamlUaaResponseAuthenticationConverter(identityZoneManager, userDatabase, identityProviderProvisioning);
56-
//
57-
// OpenSaml4AuthenticationProvider authProvider = new OpenSaml4AuthenticationProvider();
58-
// //authProvider.setAssertionValidator(OpenSaml40CompatibleAssertionValidators.createDefaultAssertionValidator());
59-
// authProvider.setResponseAuthenticationConverter(samlResponseAuthenticationConverter);
57+
ApplicationEventPublisher applicationEventPublisher) {
6058

61-
return new SamlLoginAuthenticationProvider(identityZoneManager, userDatabase, identityProviderProvisioning);
59+
SamlUaaUserManager samlUaaUserManager = new SamlUaaUserManager(userDatabase);
60+
samlUaaUserManager.setApplicationEventPublisher(applicationEventPublisher);
61+
62+
SamlUaaAuthenticationAttributesConverter attributesConverter = new SamlUaaAuthenticationAttributesConverter();
63+
SamlUaaAuthenticationAuthoritiesConverter authoritiesConverter = new SamlUaaAuthenticationAuthoritiesConverter(externalMembershipManager);
64+
65+
SamlUaaResponseAuthenticationConverter samlResponseAuthenticationConverter =
66+
new SamlUaaResponseAuthenticationConverter(identityZoneManager, identityProviderProvisioning,
67+
samlUaaUserManager, attributesConverter, authoritiesConverter);
68+
samlResponseAuthenticationConverter.setApplicationEventPublisher(applicationEventPublisher);
69+
70+
return new SamlLoginAuthenticationProvider(samlResponseAuthenticationConverter);
6271
}
6372

6473
@Autowired

0 commit comments

Comments
 (0)