Search in sources :

Example 6 with InMemoryUserDetailsManager

use of org.springframework.security.provisioning.InMemoryUserDetailsManager 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;
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) LoggerFactory(org.slf4j.LoggerFactory) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) List(java.util.List) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) InMemoryUserDetailsManager(org.springframework.security.provisioning.InMemoryUserDetailsManager) Arrays.asList(java.util.Arrays.asList) Bean(org.springframework.context.annotation.Bean) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) InMemoryUserDetailsManager(org.springframework.security.provisioning.InMemoryUserDetailsManager) Bean(org.springframework.context.annotation.Bean)

Example 7 with InMemoryUserDetailsManager

use of org.springframework.security.provisioning.InMemoryUserDetailsManager in project tutorials by eugenp.

the class MultipleEntryPointsSecurityConfig method userDetailsService.

@Bean
public UserDetailsService userDetailsService() throws Exception {
    InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
    manager.createUser(User.withUsername("user").password("userPass").roles("USER").build());
    manager.createUser(User.withUsername("admin").password("adminPass").roles("ADMIN").build());
    return manager;
}
Also used : InMemoryUserDetailsManager(org.springframework.security.provisioning.InMemoryUserDetailsManager) Bean(org.springframework.context.annotation.Bean)

Example 8 with InMemoryUserDetailsManager

use of org.springframework.security.provisioning.InMemoryUserDetailsManager in project jhipster-registry by jhipster.

the class JWTSecurityConfiguration method userDetailsService.

@Bean
public UserDetailsService userDetailsService() {
    InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
    manager.createUser(User.withUsername(username).password(passwordEncoder().encode(password)).roles(roles).build());
    return manager;
}
Also used : InMemoryUserDetailsManager(org.springframework.security.provisioning.InMemoryUserDetailsManager) Bean(org.springframework.context.annotation.Bean)

Aggregations

InMemoryUserDetailsManager (org.springframework.security.provisioning.InMemoryUserDetailsManager)8 Bean (org.springframework.context.annotation.Bean)7 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 InMemoryUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.memory.InMemoryUserRoleListService)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Configuration (org.springframework.context.annotation.Configuration)1 Profile (org.springframework.context.annotation.Profile)1 DaoAuthenticationProvider (org.springframework.security.authentication.dao.DaoAuthenticationProvider)1 AuthenticationManagerBuilder (org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)1 HttpSecurity (org.springframework.security.config.annotation.web.builders.HttpSecurity)1 EnableWebSecurity (org.springframework.security.config.annotation.web.configuration.EnableWebSecurity)1 WebSecurityConfigurerAdapter (org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter)1