Skip to content

Commit 310560a

Browse files
Add optimization: if "uaa" or "ldap" is passed as the login hint, only look up the single provider instead of all qualifying in the zone
1 parent e0df1de commit 310560a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

server/src/main/java/org/cloudfoundry/identity/uaa/authentication/manager/PasswordGrantAuthenticationManager.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,34 @@ public Authentication authenticate(Authentication authentication) throws Authent
8383
} else {
8484
/* no suiting OIDC IdP was found - get all qualifying IdPs in the zone
8585
* (i.e., active, supports password grant and is allowed by the client) */
86-
final List<String> identityProviders = identityProviderProvisioning.retrieveActive(IdentityZoneHolder.get().getId()).stream()
87-
.filter(PasswordGrantAuthenticationManager::providerSupportsPasswordGrant)
88-
.map(IdentityProvider::getOriginKey)
89-
.toList();
86+
final List<String> identityProviders;
87+
88+
final String originLoginHint = Optional.ofNullable(uaaLoginHint).map(UaaLoginHint::getOrigin).orElse(null);
89+
final boolean isLoginHintUaa = OriginKeys.UAA.equalsIgnoreCase(originLoginHint);
90+
if (isLoginHintUaa || OriginKeys.LDAP.equalsIgnoreCase(originLoginHint)) {
91+
/* if "uaa" or "ldap" is passed in the login hint (not as default origin), only look up the single IdP
92+
* instead of all qualifying ones in the zone (we later only allow this exact IdP anyway) */
93+
94+
// only returns active IdP
95+
final IdentityProvider uaaOrLdapIdp = identityProviderProvisioning.retrieveByOrigin(
96+
isLoginHintUaa ? OriginKeys.UAA : OriginKeys.LDAP,
97+
IdentityZoneHolder.get().getId()
98+
);
99+
100+
identityProviders = Optional.ofNullable(uaaOrLdapIdp)
101+
.filter(PasswordGrantAuthenticationManager::providerSupportsPasswordGrant) // always true for "uaa" or "ldap" IdPs
102+
.map(IdentityProvider::getOriginKey)
103+
.stream()
104+
.toList();
105+
} else {
106+
identityProviders = identityProviderProvisioning.retrieveActive(IdentityZoneHolder.get().getId())
107+
.stream()
108+
.filter(PasswordGrantAuthenticationManager::providerSupportsPasswordGrant)
109+
.map(IdentityProvider::getOriginKey)
110+
.toList();
111+
}
112+
113+
// only keep the IdPs that are allowed by the client
90114
if (allowedProviders == null) {
91115
// client allows all IdPs
92116
possibleProviders = new ArrayList<>(identityProviders);

server/src/test/java/org/cloudfoundry/identity/uaa/authentication/manager/PasswordGrantAuthenticationManagerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void setUp() throws Exception {
117117

118118
when(identityProviderProvisioning.retrieveActive("uaa")).thenReturn(Arrays.asList(idp, uaaProvider, ldapProvider));
119119
when(externalOAuthProviderConfigurator.retrieveByOrigin("oidcprovider", "uaa")).thenReturn(idp);
120+
when(identityProviderProvisioning.retrieveByOrigin("uaa", "uaa")).thenReturn(uaaProvider);
121+
when(identityProviderProvisioning.retrieveByOrigin("ldap", "uaa")).thenReturn(ldapProvider);
120122

121123
Authentication clientAuth = mock(Authentication.class);
122124
when(clientAuth.getName()).thenReturn("clientid");

0 commit comments

Comments
 (0)