Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created December 22, 2017 18:22
Show Gist options
  • Select an option

  • Save darbyluv2code/58471ed04bc5c65aa22054889b385a7b to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/58471ed04bc5c65aa22054889b385a7b to your computer and use it in GitHub Desktop.
updates from Spring Security 5
package com.luv2code.springsecurity.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.User.UserBuilder;
@Configuration
@EnableWebSecurity
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
UserBuilder users = User.withDefaultPasswordEncoder();
auth.inMemoryAuthentication()
.withUser(users.username("john").password("test123").roles("EMPLOYEE"))
.withUser(users.username("mary").password("test123").roles("MANAGER"))
.withUser(users.username("susan").password("test123").roles("ADMIN"));
}
/*
@Bean
public static NoOpPasswordEncoder passwordEncoder() {
return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment