Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package com.p.lodz.pl.bookexchange.config;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.boot.autoconfigure.security.SecurityProperties;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.core.annotation.Order;
  8. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  9. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  10. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  11. import org.springframework.security.core.userdetails.UserDetailsService;
  12. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  13.  
  14. @Configuration
  15. @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
  16. public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
  17. @Autowired
  18. private UserDetailsService userDetailsService;
  19.  
  20. @Bean
  21. public BCryptPasswordEncoder bCryptPasswordEncoder() {
  22. return new BCryptPasswordEncoder();
  23. }
  24.  
  25. @Override
  26. protected void configure(HttpSecurity http) throws Exception {
  27. http.authorizeRequests().antMatchers("/resources/**", "/register", "/").permitAll().anyRequest().authenticated()
  28. .and().formLogin().loginPage("/login").permitAll().and().logout().permitAll();
  29. }
  30.  
  31. @Autowired
  32. public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  33. auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement