Guest User

Untitled

a guest
Dec 7th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. @SpringBootApplication
  2. public class Boot extends SpringBootServletInitializer {
  3.  
  4. @Override
  5. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  6. return application.sources(Boot.class);
  7. }
  8.  
  9. public static void main(String[] args) throws Exception {
  10. SpringApplication.run(Boot.class, args);
  11. }
  12.  
  13. @Bean
  14. public WebSecurityConfigurerAdapter webSecurityConfigurerAdapter() {
  15. return new WebSecurityConfig();
  16. }
  17.  
  18. }
  19.  
  20. @Configuration
  21. @EnableWebSecurity
  22. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  23.  
  24. @Autowired
  25. private UserDetailsService userDetailsService;
  26.  
  27. @Bean
  28. public BCryptPasswordEncoder bCryptPasswordEncoder() {
  29. return new BCryptPasswordEncoder();
  30. }
  31.  
  32. @Override
  33. protected void configure(HttpSecurity http) throws Exception {
  34. http.authorizeRequests()
  35. // .antMatchers("/home").permitAll()
  36. // .antMatchers("/home/**").permitAll()
  37. // .antMatchers("/login").permitAll()
  38. .antMatchers("/user/**").permitAll()
  39. .antMatchers("/products/form").hasRole("ADMIN")
  40. .antMatchers("/shopping/**").permitAll()
  41. .antMatchers(HttpMethod.POST, "/products").hasRole("ADMIN")
  42. .antMatchers("/products/**").permitAll()
  43. .anyRequest().authenticated()
  44. .and().formLogin().loginPage("/login").defaultSuccessUrl("/home").permitAll()
  45. .and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/home").permitAll()
  46. .and().exceptionHandling().accessDeniedPage("/WEB-INF/views/errors/403.jsp");
  47.  
  48. }
  49.  
  50. @Autowired
  51. public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  52. auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
  53. }
  54. }
Add Comment
Please, Sign In to add comment