Skip to content

Commit

Permalink
sonar refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
strehle committed Aug 25, 2024
1 parent b46ac01 commit a2d85d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.cloudfoundry.identity.uaa.provider.oauth.ExternalOAuthAuthenticationManager;
import org.cloudfoundry.identity.uaa.provider.oauth.ExternalOAuthCodeToken;
import org.cloudfoundry.identity.uaa.provider.oauth.ExternalOAuthProviderConfigurator;
import org.cloudfoundry.identity.uaa.zone.MultitenantClientServices;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationEvent;
Expand All @@ -46,7 +45,6 @@
import java.net.URL;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.GRANT_TYPE_PASSWORD;
import static org.springframework.http.MediaType.APPLICATION_JSON;
Expand All @@ -57,16 +55,14 @@ public class PasswordGrantAuthenticationManager implements AuthenticationManager
private IdentityProviderProvisioning identityProviderProvisioning;
private RestTemplateConfig restTemplateConfig;
private ExternalOAuthAuthenticationManager externalOAuthAuthenticationManager;
private MultitenantClientServices clientDetailsService;
private ExternalOAuthProviderConfigurator externalOAuthProviderProvisioning;
private ApplicationEventPublisher eventPublisher;

public PasswordGrantAuthenticationManager(DynamicZoneAwareAuthenticationManager zoneAwareAuthzAuthenticationManager, final @Qualifier("identityProviderProvisioning") IdentityProviderProvisioning identityProviderProvisioning, RestTemplateConfig restTemplateConfig, ExternalOAuthAuthenticationManager externalOAuthAuthenticationManager, MultitenantClientServices clientDetailsService, ExternalOAuthProviderConfigurator externalOAuthProviderProvisioning) {
public PasswordGrantAuthenticationManager(DynamicZoneAwareAuthenticationManager zoneAwareAuthzAuthenticationManager, final @Qualifier("identityProviderProvisioning") IdentityProviderProvisioning identityProviderProvisioning, RestTemplateConfig restTemplateConfig, ExternalOAuthAuthenticationManager externalOAuthAuthenticationManager, ExternalOAuthProviderConfigurator externalOAuthProviderProvisioning) {
this.zoneAwareAuthzAuthenticationManager = zoneAwareAuthzAuthenticationManager;
this.identityProviderProvisioning = identityProviderProvisioning;
this.restTemplateConfig = restTemplateConfig;
this.externalOAuthAuthenticationManager = externalOAuthAuthenticationManager;
this.clientDetailsService = clientDetailsService;
this.externalOAuthProviderProvisioning = externalOAuthProviderProvisioning;
}

Expand All @@ -81,8 +77,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
if (identityProvider != null) {
possibleProviders = List.of(identityProvider.getOriginKey());
} else {
List<String> identityProviders = identityProviderProvisioning.retrieveActive(IdentityZoneHolder.get().getId()).stream().filter(this::providerSupportsPasswordGrant).map(IdentityProvider::getOriginKey).collect(Collectors.toList());
possibleProviders = Optional.ofNullable(allowedProviders).orElse(identityProviders).stream().filter(identityProviders::contains).collect(Collectors.toList());
List<String> identityProviders = identityProviderProvisioning.retrieveActive(IdentityZoneHolder.get().getId()).stream().filter(this::providerSupportsPasswordGrant).map(IdentityProvider::getOriginKey).toList();
possibleProviders = Optional.ofNullable(allowedProviders).orElse(identityProviders).stream().filter(identityProviders::contains).toList();
}
if (uaaLoginHint == null) {
if (defaultProvider != null && possibleProviders.contains(defaultProvider)) {
Expand Down Expand Up @@ -255,11 +251,11 @@ private List<String> getAllowedProviders() {
if (clientAuth == null) {
throw new BadCredentialsException("No client authentication found.");
}
List<String> allowedProviders = null;
if (clientAuth.getPrincipal() instanceof UaaClient uaaClient && uaaClient.getAdditionalInformation() != null) {
return (List<String>) uaaClient.getAdditionalInformation().get(ClientConstants.ALLOWED_PROVIDERS);
} else {
return null;
allowedProviders = (List<String>) uaaClient.getAdditionalInformation().get(ClientConstants.ALLOWED_PROVIDERS);
}
return allowedProviders;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.cloudfoundry.identity.uaa.provider.oauth.ExternalOAuthCodeToken;
import org.cloudfoundry.identity.uaa.provider.oauth.ExternalOAuthProviderConfigurator;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
import org.cloudfoundry.identity.uaa.zone.MultitenantClientServices;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -79,7 +78,6 @@ class PasswordGrantAuthenticationManagerTest {
private IdentityProviderProvisioning identityProviderProvisioning;
private RestTemplateConfig restTemplateConfig;
private ExternalOAuthAuthenticationManager externalOAuthAuthenticationManager;
private MultitenantClientServices clientDetailsService;
private ExternalOAuthProviderConfigurator externalOAuthProviderConfigurator;
private ApplicationEventPublisher eventPublisher;

Expand All @@ -95,7 +93,6 @@ void setUp() throws Exception {
identityProviderProvisioning = mock(IdentityProviderProvisioning.class);
restTemplateConfig = mock(RestTemplateConfig.class);
externalOAuthAuthenticationManager = mock(ExternalOAuthAuthenticationManager.class);
clientDetailsService = mock(MultitenantClientServices.class);
externalOAuthProviderConfigurator = mock(ExternalOAuthProviderConfigurator.class);

idp = mock(IdentityProvider.class);
Expand Down Expand Up @@ -126,7 +123,7 @@ void setUp() throws Exception {
when(clientAuth.getPrincipal()).thenReturn(uaaClient);
when(uaaClient.getAdditionalInformation()).thenReturn(mock(Map.class));

instance = new PasswordGrantAuthenticationManager(zoneAwareAuthzAuthenticationManager, identityProviderProvisioning, restTemplateConfig, externalOAuthAuthenticationManager, clientDetailsService, externalOAuthProviderConfigurator);
instance = new PasswordGrantAuthenticationManager(zoneAwareAuthzAuthenticationManager, identityProviderProvisioning, restTemplateConfig, externalOAuthAuthenticationManager, externalOAuthProviderConfigurator);
IdentityZoneHolder.clear();
eventPublisher = mock(ApplicationEventPublisher.class);
instance.setApplicationEventPublisher(eventPublisher);
Expand Down
1 change: 0 additions & 1 deletion uaa/src/main/webapp/WEB-INF/spring/oauth-endpoints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@
<constructor-arg name="zoneAwareAuthzAuthenticationManager" ref="zoneAwareAuthzAuthenticationManager"/>
<constructor-arg name="restTemplateConfig" ref="restTemplateConfig"/>
<constructor-arg name="externalOAuthAuthenticationManager" ref="externalOAuthAuthenticationManager"/>
<constructor-arg name="clientDetailsService" ref="jdbcClientDetailsService"/>
<constructor-arg name="externalOAuthProviderProvisioning" ref="externalOAuthProviderConfigurator"/>
</bean>

Expand Down

0 comments on commit a2d85d7

Please sign in to comment.