Java Code Examples for org.springframework.security.provisioning.InMemoryUserDetailsManager#createUser()
The following examples show how to use
org.springframework.security.provisioning.InMemoryUserDetailsManager#createUser() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityConfig.java From promregator with Apache License 2.0 | 6 votes |
@Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); String password = this.basicAuthPassword; if (password == null) { password = UUID.randomUUID().toString(); // NB: Logging does not work here properly yet; better use stderr System.err.println(); System.err.println( String.format("Using generated password for user %s: %s", this.basicAuthUsername, password)); System.err.println(); } manager.createUser(User.withUsername(this.basicAuthUsername).password(String.format("{noop}%s", password)) .roles("USER").build()); return manager; }
Example 2
Source File: DemoApplicationConfiguration.java From activiti-examples with Apache License 2.0 | 6 votes |
@Bean public UserDetailsService myUserDetailsService() { InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager(); String[][] usersGroupsAndRoles = { {"salaboy", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"ryandawsonuk", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"erdemedeiros", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam"}, {"system", "password", "ROLE_ACTIVITI_USER"}, {"admin", "password", "ROLE_ACTIVITI_ADMIN"}, }; for (String[] user : usersGroupsAndRoles) { List<String> authoritiesStrings = Arrays.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; }
Example 3
Source File: SecurityConfiguration.java From spring-boot-demo with MIT License | 6 votes |
@Bean protected UserDetailsService myUserDetailsService() { InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager(); String[][] usersGroupsAndRoles = {{"salaboy", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"ryandawsonuk", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"erdemedeiros", "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 = Arrays.asList(Arrays.copyOfRange(user, 2, user.length)); log.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]"); inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]), authoritiesStrings .stream() .map(SimpleGrantedAuthority::new) .collect(Collectors.toList()))); } return inMemoryUserDetailsManager; }
Example 4
Source File: SecurityConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 6 votes |
/** * 创建两个内存用户 * 用户名 user 密码 123456 角色 ROLE_USER * 用户名 admin 密码 admin 角色 ROLE_ADMIN * * @return InMemoryUserDetailsManager */ @Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user") .password(passwordEncoder().encode("123456")) .authorities("ROLE_USER").build()); manager.createUser(User.withUsername("admin") .password(passwordEncoder().encode("admin")) .authorities("ROLE_ADMIN").build()); manager.createUser(User.withUsername("13712341234") .password(passwordEncoder().encode("123456")) .authorities("ROLE_ADMIN").build()); return manager; }
Example 5
Source File: DemoApplicationConfiguration.java From activiti-examples with Apache License 2.0 | 6 votes |
@Bean public UserDetailsService myUserDetailsService() { InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager(); String[][] usersGroupsAndRoles = { {"system", "password", "ROLE_ACTIVITI_USER"}, {"reviewer", "password", "ROLE_ACTIVITI_USER"}, {"admin", "password", "ROLE_ACTIVITI_ADMIN"}, }; for (String[] user : usersGroupsAndRoles) { List<String> authoritiesStrings = Arrays.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; }
Example 6
Source File: DemoApplicationConfiguration.java From activiti-examples with Apache License 2.0 | 6 votes |
@Bean public UserDetailsService myUserDetailsService() { InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager(); String[][] usersGroupsAndRoles = { {"salaboy", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"ryandawsonuk", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"erdemedeiros", "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 = Arrays.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; }
Example 7
Source File: SecurityConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
/** * 创建两个内存用户 * 用户名 user 密码 123456 角色 ROLE_USER * 用户名 admin 密码 admin 角色 ROLE_ADMIN * * @return InMemoryUserDetailsManager */ @Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user") .password(passwordEncoder().encode("123456")) .authorities("ROLE_USER").build()); manager.createUser(User.withUsername("admin") .password(passwordEncoder().encode("admin")) .authorities("ROLE_ADMIN").build()); return manager; }
Example 8
Source File: EurekaServerMockApplication.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
@Bean public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("test").password("{noop}test") .roles("USER").build()); return manager; }
Example 9
Source File: SshShellSecurityConfigurationTest.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@Bean public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); PasswordEncoder encoder = passwordEncoder(); manager.createUser(User.withUsername("user").password(encoder.encode("password")).roles("USER").build()); manager.createUser(User.withUsername("actuator").password(encoder.encode("password")).roles("ACTUATOR").build ()); manager.createUser(User.withUsername("admin").password(encoder.encode("admin")).roles("ADMIN", "ACTUATOR") .build()); return manager; }
Example 10
Source File: SecurityConfig.java From Spring-Security-Third-Edition with MIT License | 5 votes |
/** * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService()) * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager} * UserDetailsManager vs UserDetailsService */ @Bean @Override public UserDetailsManager userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("[email protected]").password("user1").roles("USER").build()); manager.createUser(User.withUsername("[email protected]").password("admin1").roles("USER", "ADMIN").build()); return manager; }
Example 11
Source File: SecurityConfig.java From Spring with Apache License 2.0 | 5 votes |
@Bean public UserDetailsService userDetailsService() { final InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("ankidaemon").password("password").roles("CHIEF").build()); manager.createUser(User.withUsername("test").password("test").roles("USER").build()); return manager; }
Example 12
Source File: ApiBootWebSecurityMemoryAutoConfiguration.java From api-boot with Apache License 2.0 | 5 votes |
@Override @Bean protected UserDetailsService userDetailsService() { InMemoryUserDetailsManager memoryUserDetails = new InMemoryUserDetailsManager(); List<SecurityUser> users = apiBootSecurityProperties.getUsers(); if (!ObjectUtils.isEmpty(users)) { for (SecurityUser securityUser : users) { memoryUserDetails.createUser(User.builder().username(securityUser.getUsername()).password(passwordEncoder().encode(securityUser.getPassword())).roles(securityUser.getRoles()).build()); } } return memoryUserDetails; }
Example 13
Source File: ApiBootWebSecurityMemoryAutoConfiguration.java From beihu-boot with Apache License 2.0 | 5 votes |
@Override @Bean protected UserDetailsService userDetailsService() { InMemoryUserDetailsManager memoryUserDetails = new InMemoryUserDetailsManager(); List<SecurityUser> users = apiBootSecurityProperties.getUsers(); if (!ObjectUtils.isEmpty(users)) { for (SecurityUser securityUser : users) { memoryUserDetails.createUser(User.builder().username(securityUser.getUsername()).password(passwordEncoder().encode(securityUser.getPassword())).roles(securityUser.getRoles()).build()); } } return memoryUserDetails; }
Example 14
Source File: SecurityConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
/** * 创建两个内存用户 * 用户名 user 密码 123456 角色 ROLE_USER * 用户名 admin 密码 admin 角色 ROLE_ADMIN * * @return InMemoryUserDetailsManager */ @Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user") .password(passwordEncoder().encode("123456")) .authorities("ROLE_USER").build()); manager.createUser(User.withUsername("admin") .password(passwordEncoder().encode("admin")) .authorities("ROLE_ADMIN").build()); return manager; }
Example 15
Source File: SecurityConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
/** * 创建两个内存用户 * 用户名 user 密码 123456 角色 ROLE_USER * 用户名 admin 密码 admin 角色 ROLE_ADMIN * * @return InMemoryUserDetailsManager */ @Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user") .password(passwordEncoder().encode("123456")) .authorities("ROLE_USER").build()); manager.createUser(User.withUsername("admin") .password(passwordEncoder().encode("admin")) .authorities("ROLE_ADMIN").build()); return manager; }
Example 16
Source File: SecurityConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
/** * 创建两个内存用户 * 用户名 user 密码 123456 角色 ROLE_USER * 用户名 admin 密码 admin 角色 ROLE_ADMIN * * @return InMemoryUserDetailsManager */ @Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user") .password(passwordEncoder().encode("123456")) .authorities("ROLE_USER").build()); manager.createUser(User.withUsername("admin") .password(passwordEncoder().encode("admin")) .authorities("ROLE_ADMIN").build()); return manager; }
Example 17
Source File: SecurityConfig.java From Spring-Security-Third-Edition with MIT License | 5 votes |
/** * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService()) * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager} * UserDetailsManager vs UserDetailsService */ @Bean @Override public UserDetailsManager userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user").password("password").roles("USER").build()); manager.createUser(User.withUsername("admin").password("admin").roles("USER", "ADMIN").build()); manager.createUser(User.withUsername("[email protected]").password("user1").roles("USER").build()); manager.createUser(User.withUsername("[email protected]").password("admin1").roles("USER", "ADMIN").build()); return manager; }
Example 18
Source File: SecurityConfig.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
/** * 创建两个内存用户 * 用户名 user 密码 123456 角色 ROLE_USER * 用户名 admin 密码 admin 角色 ROLE_ADMIN * * @return InMemoryUserDetailsManager */ @Bean @Override public UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("user") .password(passwordEncoder().encode("123456")) .authorities("ROLE_USER").build()); manager.createUser(User.withUsername("admin") .password(passwordEncoder().encode("admin")) .authorities("ROLE_ADMIN").build()); return manager; }
Example 19
Source File: SecurityConfig.java From spring-boot-demo with MIT License | 5 votes |
/** * 配置用户 * 使用内存中的用户,实际项目中,一般使用的是数据库保存用户,具体的实现类可以使用JdbcDaoImpl或者JdbcUserDetailsManager * * @return */ @Bean @Override protected UserDetailsService userDetailsService() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("admin").password(PasswordEncoderFactories.createDelegatingPasswordEncoder().encode("admin")).authorities("USER").build()); return manager; }
Example 20
Source File: SecurityConfiguration.java From qconfig with MIT License | 4 votes |
@Bean InMemoryUserDetailsManager inMemoryUserDetailsManager() { InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); manager.createUser(User.withUsername("admin").password("123456").roles("USER").build()); return manager; }