Java Code Examples for org.springframework.security.core.userdetails.User#UserBuilder

The following examples show how to use org.springframework.security.core.userdetails.User#UserBuilder . 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: SpringSecurityHttpEndpointsBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public UserDetailsService userDetailsService() {
    User.UserBuilder users = User.withDefaultPasswordEncoder();
    InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
    // 为用户 mercyblitz 分配密码和 ENDPOINT_ADMIN 权限
    manager.createUser(users.username("mercyblitz").password("123456").roles("ENDPOINT_ADMIN").build());
    return manager;
}
 
Example 2
Source File: BankingUsersDetailService.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Optional<Customer> customerFound = customerRepository.findByUsername(username);
    if (customerFound.isPresent()) {
        Customer customer = customerFound.get();
        User.UserBuilder builder = User
                .withUsername(username)
                .password(customer.getPassword())
                .roles("CUSTOMER");
        return builder.build();
    } else {
        throw new UsernameNotFoundException("User not found.");
    }

}
 
Example 3
Source File: BankingUsersDetailService.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Optional<Customer> customerFound = customerRepository.findByUsername(username);
    if (customerFound.isPresent()) {
        Customer customer = customerFound.get();
        User.UserBuilder builder = User
                .withUsername(username)
                .password(customer.getPassword())
                .roles("CUSTOMER");
        return builder.build();
    } else {
        throw new UsernameNotFoundException("User not found.");
    }

}
 
Example 4
Source File: BankingUsersDetailService.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Optional<Customer> customerFound = customerRepository.findByUsername(username);
    if (customerFound.isPresent()) {
        Customer customer = customerFound.get();
        User.UserBuilder builder = User
                .withUsername(username)
                .password(customer.getPassword())
                .roles("CUSTOMER");
        return builder.build();
    } else {
        throw new UsernameNotFoundException("User not found.");
    }

}
 
Example 5
Source File: BankingUsersDetailService.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    Optional<Customer> customerFound = customerRepository.findByUsername(username);
    if (customerFound.isPresent()) {
        Customer customer = customerFound.get();
        User.UserBuilder builder = User
                .withUsername(username)
                .password(customer.getPassword())
                .roles("CUSTOMER");
        return builder.build();
    } else {
        throw new UsernameNotFoundException("User not found.");
    }

}
 
Example 6
Source File: ReservationClientApplication.java    From bootiful-reactive-microservices with Apache License 2.0 5 votes vote down vote up
@Bean
MapReactiveUserDetailsService authentication() {
	User.UserBuilder builder = User.withDefaultPasswordEncoder();
	return new MapReactiveUserDetailsService(
		builder.username("jlong").password("pw").roles("USER").build(),
		builder.username("rwinch").password("pw").roles("USER", "ADMIN").build()
	);
}
 
Example 7
Source File: WebSecurityConfig.java    From spring4ws-demos with Apache License 2.0 5 votes vote down vote up
@Override
@Bean
public UserDetailsService userDetailsService() {
	User.UserBuilder users = User.withDefaultPasswordEncoder();
	InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
	manager.createUser(
			users.username("fabrice").password("fab123").roles("USER").build());
	manager.createUser(users.username("paulson").password("bond")
			.roles("ADMIN", "USER").build());
	return manager;
}