Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSecurity
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- private CustomUserDetailsService customUserDetailsService;
- @Bean
- public BCryptPasswordEncoder bCryptPasswordEncoder() {
- return new BCryptPasswordEncoder();
- }
- // Work around https://jira.spring.io/browse/SEC-2855
- @Bean
- public SessionRegistry sessionRegistry() {
- SessionRegistry sessionRegistry = new SessionRegistryImpl();
- return sessionRegistry;
- }
- // Register HttpSessionEventPublisher
- @Bean
- public static ServletListenerRegistrationBean httpSessionEventPublisher() {
- return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .authorizeRequests()
- .antMatchers("/", "/post/{postId}", "/add_post", "/posts", "/registration", "/post/").permitAll()
- .anyRequest().authenticated()
- .and()
- .formLogin()
- .loginPage("/login")
- .permitAll()
- .and()
- .logout()
- .permitAll();
- // http.csrf().disable();
- http.sessionManagement()
- .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
- }
- @Override
- public void configure(WebSecurity web) throws Exception {
- web.ignoring().antMatchers("/resources/**").anyRequest();
- }
- @Autowired
- public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
- auth.userDetailsService(customUserDetailsService).passwordEncoder(new BCryptPasswordEncoder());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment