Guest User

Untitled

a guest
Nov 19th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. @Configuration
  2. @EnableWebSecurity
  3. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  4.  
  5.     @Autowired
  6.     private CustomUserDetailsService customUserDetailsService;
  7.  
  8.     @Bean
  9.     public BCryptPasswordEncoder bCryptPasswordEncoder() {
  10.         return new BCryptPasswordEncoder();
  11.     }
  12.  
  13.     // Work around https://jira.spring.io/browse/SEC-2855
  14.     @Bean
  15.     public SessionRegistry sessionRegistry() {
  16.         SessionRegistry sessionRegistry = new SessionRegistryImpl();
  17.         return sessionRegistry;
  18.     }
  19.  
  20.     // Register HttpSessionEventPublisher
  21.     @Bean
  22.     public static ServletListenerRegistrationBean httpSessionEventPublisher() {
  23.         return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
  24.     }
  25.  
  26.     @Override
  27.     protected void configure(HttpSecurity http) throws Exception {
  28.         http
  29.                 .authorizeRequests()
  30.                 .antMatchers("/", "/post/{postId}", "/add_post", "/posts", "/registration", "/post/").permitAll()
  31.                 .anyRequest().authenticated()
  32.                 .and()
  33.                 .formLogin()
  34.                 .loginPage("/login")
  35.                 .permitAll()
  36.                 .and()
  37.                 .logout()
  38.                 .permitAll();
  39.  
  40.       //  http.csrf().disable();
  41.  
  42.         http.sessionManagement()
  43.                 .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
  44.     }
  45.  
  46.     @Override
  47.     public void configure(WebSecurity web) throws Exception {
  48.         web.ignoring().antMatchers("/resources/**").anyRequest();
  49.     }
  50.  
  51.     @Autowired
  52.     public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  53.         auth.userDetailsService(customUserDetailsService).passwordEncoder(new BCryptPasswordEncoder());
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment