Search in sources :

Example 1 with UserDetailsService

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");
}
Also used : UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Test(org.junit.Test)

Example 2 with UserDetailsService

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);
}
Also used : AuthorizationServerSecurityConfigurer(org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer) FrameworkEndpointHandlerMapping(org.springframework.security.oauth2.provider.endpoint.FrameworkEndpointHandlerMapping) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService)

Example 3 with UserDetailsService

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);
        }
    };
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Person(org.devgateway.toolkit.persistence.dao.Person) Bean(org.springframework.context.annotation.Bean)

Example 4 with UserDetailsService

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);
    }
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) ITenant(org.pentaho.platform.api.mt.ITenant) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) RoleExport(org.pentaho.platform.plugin.services.importexport.RoleExport)

Example 5 with UserDetailsService

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);
}
Also used : UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Token(org.molgenis.data.security.auth.Token) TokenFactory(org.molgenis.data.security.auth.TokenFactory) DataService(org.molgenis.data.DataService) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)43 Test (org.junit.jupiter.api.Test)26 UserDetails (org.springframework.security.core.userdetails.UserDetails)22 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)7 Test (org.junit.Test)6 User (org.springframework.security.core.userdetails.User)6 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 Authentication (org.springframework.security.core.Authentication)3 UserDetailsPasswordService (org.springframework.security.core.userdetails.UserDetailsPasswordService)3 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)3 NoOpPasswordEncoder (org.springframework.security.crypto.password.NoOpPasswordEncoder)3 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Person (org.devgateway.toolkit.persistence.dao.Person)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)2 ITenant (org.pentaho.platform.api.mt.ITenant)2