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

Adds UdsPersonService implementation backed by UserDetailsService

Useful for applications that integrate with UdsPersonService for user lookups, this implementation provides something that is backed by the "local-users" UserDetailsService (UserDetailsManager) implementation.
parent ff66cf06
No related branches found
No related tags found
No related merge requests found
......@@ -54,6 +54,26 @@
<artifactId>spring-profile-conditional-filter</artifactId>
<version>${adi.development.version}</version>
</dependency>
<dependency>
<groupId>edu.wisc.services.uds</groupId>
<artifactId>uds-person-data-model-1.1</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>edu.wisc.services.uds</groupId>
<artifactId>uds-person-ws</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
......
......@@ -14,6 +14,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>edu.wisc.services.uds</groupId>
<artifactId>uds-person-ws</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
......
/**
*
*/
package edu.wisc.uwss.local;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import edu.wisc.services.uds.person.v1_1.Appointment;
import edu.wisc.services.uds.person.v1_1.Appointments;
import edu.wisc.services.uds.person.v1_1.Demographic;
import edu.wisc.services.uds.person.v1_1.Employee;
import edu.wisc.services.uds.person.v1_1.Identifier;
import edu.wisc.services.uds.person.v1_1.Identifiers;
import edu.wisc.services.uds.person.v1_1.Name;
import edu.wisc.services.uds.person.v1_1.Person;
import edu.wisc.services.uds.person.v1_1.UDDS;
import edu.wisc.uds.UdsPersonService;
import edu.wisc.uwss.UWUserDetails;
/**
* Implementation of {@link UdsPersonService} that is intended for use
* with the local development "local-users" {@link Profile}.
*
* @author Nicholas Blair
*/
@Profile("local-users")
public class LocalUsersUdsPersonServiceImpl implements UdsPersonService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private UserDetailsService userDetailsService;
/* (non-Javadoc)
* @see edu.wisc.uds.UdsPersonService#getPerson(edu.wisc.services.uds.person.v1_1.Identifiers)
*/
@Override
public Person getPerson(Identifiers identifiers) {
for(Identifier identifier: identifiers.getIdentifiers()) {
try {
UWUserDetails userDetails = (UWUserDetails) userDetailsService.loadUserByUsername(identifier.getValue());
// method won't return null by contract, it'll throw UsernameNotFoundException instead
Person result = new Person();
Demographic demographic = new Demographic();
demographic.setEmail(userDetails.getEmailAddress());
Name name = new Name();
name.setFull(userDetails.getFullName());
demographic.setName(name);
result.setDemographic(demographic);
Employee employee = new Employee();
employee.setAppointments(new Appointments());
for(String udds : userDetails.getUddsMembership()) {
Appointment appointment = new Appointment();
UDDS u = new UDDS();
u.setCode(udds);
appointment.setUDDS(u);
employee.getAppointments().getAppointments().add(appointment);
}
result.setEmployee(employee);
return result;
} catch (UsernameNotFoundException e) {
logger.debug("no userDetails found for " + identifier, e);
}
}
return null;
}
/* (non-Javadoc)
* @see edu.wisc.uds.UdsPersonService#getPeople(java.util.List)
*/
@Override
public List<Person> getPeople(List<Identifiers> identifiers) {
throw new UnsupportedOperationException("source to implement getPeople(List) not provided via Spring's UserDetailsService");
}
}
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