org.springframework.security.provisioning.inmemoryuserdetailsmanager Java Examples

The following examples show how to use org.springframework.security.provisioning.inmemoryuserdetailsmanager. 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: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@Bean
public UserDetailsService myUserDetailsService() {

    InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();

    String[][] usersGroupsAndRoles = {
            {"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 #2
Source File: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@Bean
public UserDetailsService myUserDetailsService() {

    InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();

    String[][] usersGroupsAndRoles = {
            {"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: SecurityConfig.java    From promregator with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: SecurityConfig.java    From spring-security-oauth2-demo with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 创建两个内存用户
 * 用户名 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: KeycloakUserDetailsAuthenticationProviderTest.java    From smartling-keycloak-extras with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Set<UserDetails> users = new HashSet<>();

    user = new User(KNOWN_USERNAME, "password", Arrays.asList(new SimpleGrantedAuthority("user")));
    users.add(user);

    userDetailsService = new InMemoryUserDetailsManager(Collections.unmodifiableCollection(users));

    provider = new KeycloakUserDetailsAuthenticationProvider();
    provider.setUserDetailsService(userDetailsService);

    when(principal.getName()).thenReturn(KNOWN_USERNAME);
    when(account.getPrincipal()).thenReturn(principal);

    token = new KeycloakAuthenticationToken(account);
}
 
Example #6
Source File: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: SecurityConfiguration.java    From spring-boot-demo with MIT License 6 votes vote down vote up
@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 #8
Source File: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: SecurityContextApplication.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 6 votes vote down vote up
@Bean
@Override
@SuppressWarnings("deprecation")
public UserDetailsService userDetailsService() {
    UserDetails user =
            User.withDefaultPasswordEncoder()
                    .username("user")
                    .password("user")
                    .roles("USER")
                    .build();

    UserDetails admin = User.withDefaultPasswordEncoder()
            .username("admin")
            .password("admin")
            .roles("ADMIN")
            .build();

    return new InMemoryUserDetailsManager(user, admin);
}
 
Example #12
Source File: DemoApplicationConfiguration.java    From activiti-examples with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: OAuth2SecurityConfiguration.java    From jhipster-registry with Apache License 2.0 5 votes vote down vote up
@Bean
public InMemoryUserDetailsManager inMemoryUserDetailsManager(
    SecurityProperties properties,
    ObjectProvider<PasswordEncoder> passwordEncoder) {
    SecurityProperties.User user = properties.getUser();
    List<String> roles = user.getRoles();
    return new InMemoryUserDetailsManager(User.withUsername(user.getName())
        .password(getOrDeducePassword(user, passwordEncoder.getIfAvailable()))
        .roles(StringUtils.toStringArray(roles)).build());
}
 
Example #14
Source File: WebSecurityConfig.java    From training with MIT License 5 votes vote down vote up
@Bean
@Override
public UserDetailsService userDetailsService() {
    UserDetails user =
         User.withDefaultPasswordEncoder()
            .username("user")
            .password("password")
            .roles("USER")
            .build();

    return new InMemoryUserDetailsManager(user);
}
 
Example #15
Source File: AppConfig.java    From smartling-keycloak-extras with Apache License 2.0 5 votes vote down vote up
@Bean
UserDetailsService userDetailsService() {
    Set<UserDetails> users = new HashSet<>();
    User user = new User(KNOWN_EMAIL, "does_not_matter", Arrays.asList(new SimpleGrantedAuthority("user")));
    users.add(user);
    return new InMemoryUserDetailsManager(Collections.unmodifiableCollection(users));
}
 
Example #16
Source File: SecurityConfig.java    From streaming-file-server with MIT License 5 votes vote down vote up
@Bean
public UserDetailsService userDetailsService(final PasswordEncoder encoder) {
  return new InMemoryUserDetailsManager(
      User.withUsername("user")
          .password(encoder.encode("password"))
          .roles("USER")
          .build(),
      User.withUsername("admin")
          .password(encoder.encode("admin"))
          .roles("USER", "ADMIN")
          .build()
  );
}
 
Example #17
Source File: SecurityConfig.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Bean
@Override
public UserDetailsService userDetailsService() {
	final InMemoryUserDetailsManager inMemory =
		new InMemoryUserDetailsManager(this.fileSecurityProperties.getUsers());
	return inMemory;
}
 
Example #18
Source File: SecurityConfig.java    From POC with Apache License 2.0 5 votes vote down vote up
@Bean
InMemoryUserDetailsManager inMemoryUserDetailsManager() {
	return new InMemoryUserDetailsManager(
			User.withUsername("username").password("{noop}password").authorities("ROLE_USER").build(),
			User.withUsername("admin").password("{noop}admin")
					.authorities("ROLE_ACTUATOR", "ROLE_USER", "ROLE_ADMIN").build());
}
 
Example #19
Source File: Application.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
/**
 * This section defines the user accounts which can be used for authentication as well as the roles each user has.
 */
@Bean
InMemoryUserDetailsManager userDetailsManager() {

	UserBuilder builder = User.withDefaultPasswordEncoder();

	UserDetails greg = builder.username("greg").password("turnquist").roles("USER").build();
	UserDetails ollie = builder.username("ollie").password("gierke").roles("USER", "ADMIN").build();

	return new InMemoryUserDetailsManager(greg, ollie);
}
 
Example #20
Source File: JWTSecurityConfiguration.java    From jhipster-registry with Apache License 2.0 5 votes vote down vote up
@Bean
public UserDetailsService userDetailsService() {
    InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
    manager.createUser(
        User.withUsername(username)
            .password(passwordEncoder().encode(password))
            .roles(roles)
            .build());
    return manager;
}
 
Example #21
Source File: FileAuthenticationConfiguration.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the {@link AuthenticationManagerBuilder}. Creates an
 * {@link InMemoryUserDetailsManager} with the provided {@link FileAuthenticationConfiguration#getUsers()}.
 * {@link FileAuthenticationConfiguration#getUsers()} must contain at least 1 user.
 *
 * @throws IllegalArgumentException if {@link FileAuthenticationConfiguration#getUsers()} is empty.
 */
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {

	Assert.notEmpty(this.users,
		String.format("No user specified. Please specify at least 1 user (e.g. via '%s')",
			CONFIGURATION_PROPERTIES_PREFIX + ".users"));

	final InMemoryUserDetailsManager inMemory = new InMemoryUserDetailsManager(getUsers());
	auth.userDetailsService(inMemory);
}
 
Example #22
Source File: AuthenticationConfiguration.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
@Bean
UserDetailsService userDetailsService() {
	// @formatter:off
	return new InMemoryUserDetailsManager(
			User.withDefaultPasswordEncoder().username("greg").password("turnquist").roles("read").build());
	// @formatter:on
}
 
Example #23
Source File: MockServerConfig.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@Bean(name = "userDetailsService")
public UserDetailsService inMemoryUserDetailsManager() {
    List<UserDetails> users = new ArrayList<>(1);
    users.add(new User("user", "[email protected]", "User", "User", "user", Arrays.asList(new Role("ROLE_USER", Arrays.asList("RIGHT_AS_USER")))));
    users.add(new User("[email protected]", "[email protected]", "Facebook", "User", "facebook", Arrays.asList(new Role("ROLE_USER", Arrays.asList("RIGHT_AS_USER")))));

    return new InMemoryUserDetailsManager(users);
}
 
Example #24
Source File: LearningSpringBootEurekaServerApplication.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@Bean
UserDetailsService userDetailsService() {
	return new InMemoryUserDetailsManager(
		User
			.withUsername("user")
			.password("password")
			.roles("USER").build());
}
 
Example #25
Source File: LearningSpringBootConfigServer.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@Bean
UserDetailsService userDetailsService() {
	return new InMemoryUserDetailsManager(
		User
			.withUsername("user")
			.password("password")
			.roles("USER").build());
}
 
Example #26
Source File: LearningSpringBootEurekaServerApplication.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@Bean
UserDetailsService userDetailsService() {
	return new InMemoryUserDetailsManager(
		User
			.withUsername("user")
			.password("password")
			.roles("USER").build());
}
 
Example #27
Source File: LearningSpringBootConfigServer.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@Bean
UserDetailsService userDetailsService() {
	return new InMemoryUserDetailsManager(
		User
			.withUsername("user")
			.password("password")
			.roles("USER").build());
}
 
Example #28
Source File: SecurityConfig.java    From spring-cloud-skipper with Apache License 2.0 5 votes vote down vote up
@Bean
@Override
public UserDetailsService userDetailsService() {
	final InMemoryUserDetailsManager inMemory =
		new InMemoryUserDetailsManager(this.fileSecurityProperties.getUsers());
	return inMemory;
}
 
Example #29
Source File: WebSecurityConfig.java    From zkspringboot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an {@link InMemoryUserDetailsManager} for demo/testing purposes only. DON'T use this in production, see: {@link User#withUserDetails}!
 * @return userDetailsService
 */
@Bean
@Override
public UserDetailsService userDetailsService() {
    UserDetails user =
            User.withDefaultPasswordEncoder()
                    .username("user")
                    .password("password")
                    .roles("USER")
                    .build();

    return new InMemoryUserDetailsManager(user);
}
 
Example #30
Source File: WebSecurityConfiguration.java    From Hands-On-RESTful-API-Design-Patterns-and-Best-Practices with MIT License 5 votes vote down vote up
@Bean
@Override
public UserDetailsService userDetailsService() {
	
	UserDetails user1=User.builder().username("user1").password(passwordEncoder().encode("secret!23")).
			roles("USER").build();
	UserDetails user2=User.builder().username("user2").password(passwordEncoder().encode("secret1@3")).
			roles("USER").build();
	UserDetails adminUser=User.builder().username("admin").password(passwordEncoder().encode("secret@dmin")).
			roles("ADMIN").build();
    return new InMemoryUserDetailsManager(user1, user2, adminUser);
}