Created
February 23, 2015 17:05
-
-
Save chbatey/3a6e3a13ee2bfc02ccba to your computer and use it in GitHub Desktop.
Example spring config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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