How to use in Memory Authentication in Spring Boot version 5?
What are the best way to implement in memory authentication?
I wanted to know how can I implement in memory authentication in my Spring Boot Version 5 Application.
CodePudding user response:
By a simple google search you can find a lot of samples and documents for your question, as springs docs says you can use in memory authentication as below:
@Bean
public UserDetailsService users() {
UserDetails user = User.builder()
.username("user")
.password("{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW")
.roles("USER")
.build();
UserDetails admin = User.builder()
.username("admin")
.password("{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW")
.roles("USER", "ADMIN")
.build();
return new InMemoryUserDetailsManager(user, admin);
}
for more details check the docs.