Skip to content

Commit

Permalink
Add optimization: if "uaa" or "ldap" is passed as the login hint, onl…
Browse files Browse the repository at this point in the history
…y look up the single provider instead of all qualifying in the zone
  • Loading branch information
adrianhoelzl-sap committed Nov 27, 2024
1 parent e0df1de commit 310560a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,34 @@ public Authentication authenticate(Authentication authentication) throws Authent
} else {
/* no suiting OIDC IdP was found - get all qualifying IdPs in the zone
* (i.e., active, supports password grant and is allowed by the client) */
final List<String> identityProviders = identityProviderProvisioning.retrieveActive(IdentityZoneHolder.get().getId()).stream()
.filter(PasswordGrantAuthenticationManager::providerSupportsPasswordGrant)
.map(IdentityProvider::getOriginKey)
.toList();
final List<String> identityProviders;

final String originLoginHint = Optional.ofNullable(uaaLoginHint).map(UaaLoginHint::getOrigin).orElse(null);
final boolean isLoginHintUaa = OriginKeys.UAA.equalsIgnoreCase(originLoginHint);
if (isLoginHintUaa || OriginKeys.LDAP.equalsIgnoreCase(originLoginHint)) {
/* if "uaa" or "ldap" is passed in the login hint (not as default origin), only look up the single IdP
* instead of all qualifying ones in the zone (we later only allow this exact IdP anyway) */

// only returns active IdP
final IdentityProvider uaaOrLdapIdp = identityProviderProvisioning.retrieveByOrigin(
isLoginHintUaa ? OriginKeys.UAA : OriginKeys.LDAP,
IdentityZoneHolder.get().getId()
);

identityProviders = Optional.ofNullable(uaaOrLdapIdp)
.filter(PasswordGrantAuthenticationManager::providerSupportsPasswordGrant) // always true for "uaa" or "ldap" IdPs
.map(IdentityProvider::getOriginKey)
.stream()
.toList();
} else {
identityProviders = identityProviderProvisioning.retrieveActive(IdentityZoneHolder.get().getId())
.stream()
.filter(PasswordGrantAuthenticationManager::providerSupportsPasswordGrant)
.map(IdentityProvider::getOriginKey)
.toList();
}

// only keep the IdPs that are allowed by the client
if (allowedProviders == null) {
// client allows all IdPs
possibleProviders = new ArrayList<>(identityProviders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void setUp() throws Exception {

when(identityProviderProvisioning.retrieveActive("uaa")).thenReturn(Arrays.asList(idp, uaaProvider, ldapProvider));
when(externalOAuthProviderConfigurator.retrieveByOrigin("oidcprovider", "uaa")).thenReturn(idp);
when(identityProviderProvisioning.retrieveByOrigin("uaa", "uaa")).thenReturn(uaaProvider);
when(identityProviderProvisioning.retrieveByOrigin("ldap", "uaa")).thenReturn(ldapProvider);

Authentication clientAuth = mock(Authentication.class);
when(clientAuth.getName()).thenReturn("clientid");
Expand Down

0 comments on commit 310560a

Please sign in to comment.