Skip to content

Instantly share code, notes, and snippets.

@chbatey
Created February 23, 2015 17:05
Show Gist options
  • Save chbatey/3a6e3a13ee2bfc02ccba to your computer and use it in GitHub Desktop.
Save chbatey/3a6e3a13ee2bfc02ccba to your computer and use it in GitHub Desktop.
Example spring config
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityConfig.class);
@Inject
private UserDetailsService userDetailsService;
@Inject
private Md5PasswordEncoder md5PasswordEncoder;
@Inject
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
LOGGER.info("Setting up users");
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setPasswordEncoder(md5PasswordEncoder);
authProvider.setUserDetailsService(userDetailsService);
ReflectionSaltSource saltSource = new ReflectionSaltSource();
saltSource.setUserPropertyToUse("salt");
authProvider.setSaltSource(saltSource);
auth.authenticationProvider(authProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.csrf().disable();
http.httpBasic();
http.authorizeRequests()
.antMatchers("/api/auction").hasRole("USER")
.antMatchers("/api/user").anonymous();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment