use of org.springframework.security.core.userdetails.UserDetailsService in project molgenis by molgenis.
the class PlatformITConfig method userDetailsService.
@Bean
public UserDetailsService userDetailsService() {
UserDetailsService userDetailsService = mock(UserDetailsService.class);
UserDetails adminUserDetails = mock(UserDetails.class);
Collection authorities = singleton(new SimpleGrantedAuthority(ROLE_SYSTEM));
when(adminUserDetails.getAuthorities()).thenReturn(authorities);
when(userDetailsService.loadUserByUsername("admin")).thenReturn(adminUserDetails);
return userDetailsService;
}
use of org.springframework.security.core.userdetails.UserDetailsService in project oc-explorer by devgateway.
the class TestUserDetailsConfiguration method testUserDetailsAdminProcuringEntity.
@Bean("testUserDetailsAdminProcuringEntity")
public UserDetailsService testUserDetailsAdminProcuringEntity() {
return new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Person person = new Person();
person.setUsername(username);
person.setPassword("idontcare");
person.setAuthorities(Arrays.asList(new SimpleGrantedAuthority("ROLE_PROCURING_ENTITY"), new SimpleGrantedAuthority("ROLE_ADMIN")));
return personRepository.save(person);
}
};
}
use of org.springframework.security.core.userdetails.UserDetailsService in project Activiti by Activiti.
the class DemoApplicationConfiguration method myUserDetailsService.
@Bean
public UserDetailsService myUserDetailsService() {
InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();
String[][] usersGroupsAndRoles = { { "bob", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam" }, { "john", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam" }, { "hannah", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam" }, { "other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam" }, { "admin", "password", "ROLE_ACTIVITI_ADMIN" } };
for (String[] user : usersGroupsAndRoles) {
List<String> authoritiesStrings = asList(Arrays.copyOfRange(user, 2, user.length));
logger.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]");
inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]), authoritiesStrings.stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList())));
}
return inMemoryUserDetailsManager;
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserDetailsServiceFactoryBean method authenticationUserDetailsService.
@SuppressWarnings("unchecked")
AuthenticationUserDetailsService authenticationUserDetailsService(String name) {
UserDetailsService uds;
if (!StringUtils.hasText(name)) {
Map<String, ?> beans = getBeansOfType(AuthenticationUserDetailsService.class);
if (!beans.isEmpty()) {
if (beans.size() > 1) {
throw new ApplicationContextException("More than one AuthenticationUserDetailsService registered." + " Please use a specific Id reference.");
}
return (AuthenticationUserDetailsService) beans.values().toArray()[0];
}
uds = getUserDetailsService();
} else {
Object bean = this.beanFactory.getBean(name);
if (bean instanceof AuthenticationUserDetailsService) {
return (AuthenticationUserDetailsService) bean;
} else if (bean instanceof UserDetailsService) {
uds = cachingUserDetailsService(name);
if (uds == null) {
uds = (UserDetailsService) bean;
}
} else {
throw new ApplicationContextException("Bean '" + name + "' must be a UserDetailsService or an" + " AuthenticationUserDetailsService");
}
}
return new UserDetailsByNameServiceWrapper(uds);
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class LdapUserServiceBeanDefinitionParserTests method externalContextMapperIsSupported.
@Test
public void externalContextMapperIsSupported() {
setContext("<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>" + "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-context-mapper-ref='mapper'/>" + "<b:bean id='mapper' class='" + InetOrgPersonContextMapper.class.getName() + "'/>");
UserDetailsService uds = (UserDetailsService) this.appCtx.getBean("ldapUDS");
UserDetails ben = uds.loadUserByUsername("ben");
assertThat(ben instanceof InetOrgPerson).isTrue();
}
Aggregations