use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security by spring-projects.
the class UserServiceBeanDefinitionParserTests method userWithBothPropertiesAndEmbeddedUsersThrowsException.
@Test(expected = FatalBeanException.class)
public void userWithBothPropertiesAndEmbeddedUsersThrowsException() {
setContext("<user-service id='service' properties='doesntmatter.props'>" + " <user name='joe' password='joespassword' authorities='ROLE_A'/>" + "</user-service>");
UserDetailsService userService = (UserDetailsService) appContext.getBean("service");
userService.loadUserByUsername("Joe");
}
use of org.springframework.security.core.userdetails.UserDetailsService in project spring-security-oauth by spring-projects.
the class AuthorizationServerSecurityConfiguration method configure.
@Override
protected void configure(HttpSecurity http) throws Exception {
AuthorizationServerSecurityConfigurer configurer = new AuthorizationServerSecurityConfigurer();
FrameworkEndpointHandlerMapping handlerMapping = endpoints.oauth2EndpointHandlerMapping();
http.setSharedObject(FrameworkEndpointHandlerMapping.class, handlerMapping);
configure(configurer);
http.apply(configurer);
String tokenEndpointPath = handlerMapping.getServletPath("/oauth/token");
String tokenKeyPath = handlerMapping.getServletPath("/oauth/token_key");
String checkTokenPath = handlerMapping.getServletPath("/oauth/check_token");
if (!endpoints.getEndpointsConfigurer().isUserDetailsServiceOverride()) {
UserDetailsService userDetailsService = http.getSharedObject(UserDetailsService.class);
endpoints.getEndpointsConfigurer().userDetailsService(userDetailsService);
}
// @formatter:off
http.authorizeRequests().antMatchers(tokenEndpointPath).fullyAuthenticated().antMatchers(tokenKeyPath).access(configurer.getTokenKeyAccess()).antMatchers(checkTokenPath).access(configurer.getCheckTokenAccess()).and().requestMatchers().antMatchers(tokenEndpointPath, tokenKeyPath, checkTokenPath).and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
// @formatter:on
http.setSharedObject(ClientDetailsService.class, clientDetailsService);
}
use of org.springframework.security.core.userdetails.UserDetailsService in project ocvn 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 pentaho-platform by pentaho.
the class PentahoPlatformExporter method exportUsersAndRoles.
protected void exportUsersAndRoles() {
log.debug("export users & roles");
IUserRoleListService userRoleListService = PentahoSystem.get(IUserRoleListService.class);
UserDetailsService userDetailsService = PentahoSystem.get(UserDetailsService.class);
IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = PentahoSystem.get(IRoleAuthorizationPolicyRoleBindingDao.class);
ITenant tenant = TenantUtils.getCurrentTenant();
// get the user settings for this user
IUserSettingService service = getUserSettingService();
// User Export
List<String> userList = userRoleListService.getAllUsers(tenant);
for (String user : userList) {
UserExport userExport = new UserExport();
userExport.setUsername(user);
userExport.setPassword(userDetailsService.loadUserByUsername(user).getPassword());
for (String role : userRoleListService.getRolesForUser(tenant, user)) {
userExport.setRole(role);
}
if (service != null && service instanceof IAnyUserSettingService) {
IAnyUserSettingService userSettings = (IAnyUserSettingService) service;
List<IUserSetting> settings = userSettings.getUserSettings(user);
if (settings != null) {
for (IUserSetting setting : settings) {
userExport.addUserSetting(new ExportManifestUserSetting(setting));
}
}
}
this.getExportManifest().addUserExport(userExport);
}
// export the global user settings
if (service != null) {
List<IUserSetting> globalUserSettings = service.getGlobalUserSettings();
if (globalUserSettings != null) {
for (IUserSetting setting : globalUserSettings) {
getExportManifest().addGlobalUserSetting(new ExportManifestUserSetting(setting));
}
}
}
// RoleExport
List<String> roles = userRoleListService.getAllRoles();
for (String role : roles) {
RoleExport roleExport = new RoleExport();
roleExport.setRolename(role);
roleExport.setPermission(roleBindingDao.getRoleBindingStruct(null).bindingMap.get(role));
exportManifest.addRoleExport(roleExport);
}
}
use of org.springframework.security.core.userdetails.UserDetailsService in project molgenis by molgenis.
the class DataServiceTokenServiceTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
tokenGenerator = mock(TokenGenerator.class);
dataService = mock(DataService.class);
userDetailsService = mock(UserDetailsService.class);
TokenFactory tokenFactory = mock(TokenFactory.class);
when(tokenFactory.create()).thenAnswer(invocation -> mock(Token.class));
tokenService = new DataServiceTokenService(tokenGenerator, dataService, userDetailsService, tokenFactory);
}
Aggregations