Skip to content
Snippets Groups Projects
Commit dd3aeb01 authored by Nicholas Blair's avatar Nicholas Blair
Browse files

Merge branch 'udsperson-constructor' into 'master'

refactor: change injection strategy for UdsPersonUserDetailsServiceImpl

`UdsPersonUserDetailsServiceImpl` is not initialized automatically by either of the primary 'local-users' or 'preauth' Profiles. It's typically constructed by downstream projects manually (not by component scanning).
    
 Registering more than 1 `UserDetailsService` - say one for the uw-spring-security stack, and a different one for `UdsPersonUserDetailsServiceImpl` - will result in ApplicationContext initialization errors as the Configuration classes provided in uw-spring-security-config expect 1 and only 1 UserDetailsService.
    
The recommended use now for `UdsPersonUserDetailsServiceImpl` is to provide the needed `UserDetailsService` by hand, not by automatic autowiring. If the 1 UserDetailsService provided by uw-spring-security is appropriate, it's easy to retrieve from the ApplicationContext; if an alternate one is required it can be constructed without registering it as a @Bean.

See merge request !25
parents 71358aec 909d54fb
No related branches found
No related tags found
1 merge request!25refactor: change injection strategy for UdsPersonUserDetailsServiceImpl
......@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.wisc.uwss</groupId>
<artifactId>uw-spring-security</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>UW Spring Security Parent</name>
<description>Parent project for module to integrate Spring Security with UW authentication mechanism.</description>
......
......@@ -3,7 +3,7 @@
<parent>
<groupId>edu.wisc.uwss</groupId>
<artifactId>uw-spring-security</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>
<artifactId>uw-spring-security-config</artifactId>
<name>UW Spring Security Configuration</name>
......
......@@ -3,7 +3,7 @@
<parent>
<groupId>edu.wisc.uwss</groupId>
<artifactId>uw-spring-security</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>
<artifactId>uw-spring-security-core</artifactId>
<name>UW Spring Security Core</name>
......
......@@ -25,9 +25,18 @@ import edu.wisc.uwss.UWUserDetails;
*/
public class UdsPersonUserDetailsServiceImpl implements UserDetailsService{
@Autowired UdsPersonService personService;
@Autowired(required=false) IdentifiersFactory identifiersFactory = new IdentifiersFactory.NetID();
protected UdsPersonService personService;
protected IdentifiersFactory identifiersFactory = new IdentifiersFactory.NetID();
@Autowired
public UdsPersonUserDetailsServiceImpl(UdsPersonService personService) {
this(personService, new IdentifiersFactory.NetID());
}
@Autowired(required=false)
public UdsPersonUserDetailsServiceImpl(UdsPersonService personService, IdentifiersFactory identifiersFactory) {
this.personService = personService;
this.identifiersFactory = identifiersFactory;
}
@Override
public UWUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Identifiers identifiers = identifiersFactory.withValue(username);
......
......@@ -83,4 +83,9 @@ public class UWUserDetailsImplTest {
assertEquals(lower.getEmailAddress(), upper.getEmailAddress());
assertEquals(lower.getEmailAddressHash(), upper.getEmailAddressHash());
}
@Test
public void newInstance_success() {
UWUserDetailsImpl instance = UWUserDetailsImpl.newInstance("UW123A123", "bucky", "", "Bucky Badger", "bucky.badger@wisc.edu", Collections.<String>emptyList(), Collections.<String>emptyList());
}
}
......@@ -3,7 +3,7 @@
<parent>
<groupId>edu.wisc.uwss</groupId>
<artifactId>uw-spring-security</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>
<artifactId>uw-spring-security-sample-war</artifactId>
<name>UW Spring Security Sample War</name>
......
......@@ -3,7 +3,7 @@
<parent>
<groupId>edu.wisc.uwss</groupId>
<artifactId>uw-spring-security</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
</parent>
<artifactId>uw-spring-security-web</artifactId>
<name>UW Spring Security Web</name>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment