Skip to content

Commit 3449e86

Browse files
authored
Merge pull request #3388 from cloudfoundry/dgarnier/login-server
Move login-server.xml to java-config
2 parents ec5271f + e95d648 commit 3449e86

19 files changed

+343
-616
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import org.cloudfoundry.identity.uaa.util.UaaStringUtils;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
import org.springframework.beans.factory.annotation.Qualifier;
1011
import org.springframework.http.HttpMethod;
1112
import org.springframework.security.authentication.AuthenticationManager;
1213
import org.springframework.security.authentication.BadCredentialsException;
1314
import org.springframework.security.core.Authentication;
1415
import org.springframework.security.core.AuthenticationException;
1516
import org.springframework.security.core.context.SecurityContextHolder;
1617
import org.springframework.security.web.AuthenticationEntryPoint;
18+
import org.springframework.stereotype.Component;
1719
import org.springframework.util.Assert;
1820

1921
import javax.servlet.Filter;

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
package org.cloudfoundry.identity.uaa.authentication;
1616

1717
import org.cloudfoundry.identity.uaa.util.UaaStringUtils;
18+
import org.springframework.beans.factory.annotation.Qualifier;
19+
import org.springframework.security.authentication.AuthenticationManager;
1820
import org.springframework.security.authentication.BadCredentialsException;
21+
import org.springframework.stereotype.Component;
1922

2023
import javax.servlet.http.HttpServletRequest;
2124
import javax.servlet.http.HttpServletResponse;
@@ -27,10 +30,16 @@
2730
* It sets the authentication to a client only
2831
* Oauth2Authentication object as that is expected by
2932
* the LoginAuthenticationManager.
30-
*
3133
*/
34+
@Component
3235
public class LoginClientParametersAuthenticationFilter extends AbstractClientParametersAuthenticationFilter {
3336

37+
public LoginClientParametersAuthenticationFilter(
38+
@Qualifier("clientAuthenticationManager") AuthenticationManager authenticationManager
39+
) {
40+
this.setClientAuthenticationManager(authenticationManager);
41+
}
42+
3443
@Override
3544
public void wrapClientCredentialLogin(HttpServletRequest req, HttpServletResponse res, Map<String, String> loginInfo, String clientId) {
3645
if (loginInfo.isEmpty()) {

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,48 @@
1515

1616
package org.cloudfoundry.identity.uaa.authentication;
1717

18+
import org.cloudfoundry.identity.uaa.authentication.manager.LoginAuthenticationManager;
1819
import org.cloudfoundry.identity.uaa.oauth.provider.OAuth2Authentication;
1920
import org.cloudfoundry.identity.uaa.oauth.provider.OAuth2RequestFactory;
2021
import org.cloudfoundry.identity.uaa.oauth.provider.endpoint.TokenEndpointAuthenticationFilter;
21-
import org.springframework.security.authentication.AuthenticationManager;
22+
import org.springframework.beans.factory.annotation.Qualifier;
2223
import org.springframework.security.core.Authentication;
2324
import org.springframework.security.core.context.SecurityContextHolder;
25+
import org.springframework.stereotype.Component;
2426
import org.springframework.util.StringUtils;
2527

2628
import javax.servlet.http.HttpServletRequest;
2729
import javax.servlet.http.HttpServletResponse;
2830
import java.io.IOException;
29-
import java.util.Collections;
3031
import java.util.HashMap;
3132
import java.util.List;
3233
import java.util.Map;
3334

3435
import static org.cloudfoundry.identity.uaa.oauth.token.TokenConstants.GRANT_TYPE_PASSWORD;
3536

37+
@Component
3638
public class LoginServerTokenEndpointFilter extends TokenEndpointAuthenticationFilter {
3739

38-
39-
private List<String> parameterNames = Collections.emptyList();
40+
private final List<String> parameterNames = List.of(
41+
"login",
42+
"username",
43+
"user_id",
44+
"origin",
45+
"given_name",
46+
"family_name",
47+
"email",
48+
"authorities"
49+
);
4050

4151
/**
4252
* @param authenticationManager an AuthenticationManager for the incoming request
4353
*/
44-
public LoginServerTokenEndpointFilter(AuthenticationManager authenticationManager, OAuth2RequestFactory oAuth2RequestFactory, List<String> addNewUserParameters) {
54+
public LoginServerTokenEndpointFilter(
55+
LoginAuthenticationManager authenticationManager,
56+
OAuth2RequestFactory oAuth2RequestFactory,
57+
UaaAuthenticationDetailsSource authenticationDetailsSource) {
4558
super(authenticationManager, oAuth2RequestFactory);
46-
this.parameterNames = addNewUserParameters;
59+
setAuthenticationDetailsSource(authenticationDetailsSource);
4760
}
4861

4962
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.identity.uaa.authentication;
22

3+
import org.cloudfoundry.identity.uaa.authentication.manager.LoginAuthenticationManager;
34
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
45
import org.cloudfoundry.identity.uaa.login.AuthenticationResponse;
56
import org.cloudfoundry.identity.uaa.oauth.provider.OAuth2Authentication;
@@ -39,7 +40,7 @@ public class RemoteAuthenticationEndpoint {
3940

4041
public RemoteAuthenticationEndpoint(
4142
final @Qualifier("zoneAwareAuthzAuthenticationManager") AuthenticationManager authenticationManager,
42-
final @Qualifier("loginAuthenticationMgr") AuthenticationManager loginAuthenticationManager) {
43+
LoginAuthenticationManager loginAuthenticationManager) {
4344
this.authenticationManager = authenticationManager;
4445
this.loginAuthenticationManager = loginAuthenticationManager;
4546
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import javax.servlet.http.HttpServletRequest;
1717

1818
import org.springframework.security.authentication.AuthenticationDetailsSource;
19+
import org.springframework.stereotype.Component;
1920

2021
/**
2122
* @author Luke Taylor
2223
*/
24+
@Component
2325
public class UaaAuthenticationDetailsSource implements
2426
AuthenticationDetailsSource<HttpServletRequest, UaaAuthenticationDetails> {
2527
@Override

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

Lines changed: 0 additions & 204 deletions
This file was deleted.

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,30 @@
3636
import org.springframework.security.core.context.SecurityContext;
3737
import org.springframework.security.core.context.SecurityContextHolder;
3838
import org.springframework.security.core.userdetails.UsernameNotFoundException;
39+
import org.springframework.stereotype.Component;
3940

4041
import java.util.Map;
4142

4243
import static org.cloudfoundry.identity.uaa.constants.OriginKeys.NotANumber;
4344

45+
@Component
4446
public class LoginAuthenticationManager implements AuthenticationManager, ApplicationEventPublisherAware {
4547
private final Logger logger = LoggerFactory.getLogger(getClass());
4648
private final IdentityZoneManager identityZoneManager;
49+
private final UaaUserDatabase userDatabase;
4750

4851
private ApplicationEventPublisher eventPublisher;
4952

50-
private UaaUserDatabase userDatabase;
51-
52-
public LoginAuthenticationManager(IdentityZoneManager identityZoneManager) {
53+
public LoginAuthenticationManager(IdentityZoneManager identityZoneManager, UaaUserDatabase userDatabase) {
5354
this.identityZoneManager = identityZoneManager;
55+
this.userDatabase = userDatabase;
5456
}
5557

5658
@Override
5759
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher) {
5860
this.eventPublisher = eventPublisher;
5961
}
6062

61-
/**
62-
* @param userDatabase the userDatabase to set
63-
*/
64-
public void setUserDatabase(UaaUserDatabase userDatabase) {
65-
this.userDatabase = userDatabase;
66-
}
67-
6863
@Override
6964
public Authentication authenticate(Authentication request) throws AuthenticationException {
7065

0 commit comments

Comments
 (0)