Guest User

Untitled

a guest
Oct 8th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. @Configuration
  2. @EnableWebSecurity
  3. public class MainSecurityConfig extends WebSecurityConfigurerAdapter {
  4.  
  5.  
  6. @Resource
  7. private UserDetailsServiceImpl userDetailsService;
  8.  
  9. @Bean
  10. public HttpSessionEventPublisher httpSessionEventPublisher() {
  11. return new HttpSessionEventPublisher();
  12. }
  13.  
  14.  
  15. @Bean
  16. public PasswordEncoder passwordEncoder() {
  17. return new BCryptPasswordEncoder();
  18. }
  19.  
  20. @Override
  21. protected void configure(HttpSecurity http) throws Exception {
  22.  
  23. http
  24. .csrf().disable();
  25.  
  26. http
  27. .authorizeRequests()
  28. .antMatchers("/", "/**", "/login/**", "/index.html", "/login.html", "/components/**", "/css/**", "/js/**", "/fonts/**", "/images/**", "/.sass-cache/**", "/services.html").permitAll()
  29. .anyRequest().authenticated();
  30.  
  31.  
  32. http.formLogin()
  33. .loginPage("/login")
  34. .failureForwardUrl("/login.html")
  35. .usernameParameter("user")
  36. .passwordParameter("password");
  37.  
  38.  
  39.  
  40. }
  41.  
  42. @Override
  43. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  44. auth.authenticationProvider(authenticationProvider());
  45. }
  46.  
  47.  
  48. @Bean
  49. public DaoAuthenticationProvider authenticationProvider() {
  50. DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
  51. authProvider.setUserDetailsService(userDetailsService);
  52. authProvider.setPasswordEncoder(passwordEncoder());
  53. return authProvider;
  54. }
  55.  
  56. @Service
  57. public class UserDetailsServiceImpl implements UserDetailsService {
  58. @Resource
  59. private HttpSession httpSession;
  60.  
  61.  
  62. @Resource
  63. private UserDao userDao;
  64.  
  65.  
  66. @Override
  67. public UserDetails loadUserByUsername(String user) throws UsernameNotFoundException {
  68.  
  69. User userByEmail = userDao.findUserByEmail(user);
  70.  
  71. UserDetailsImpl userDetails = new UserDetailsImpl(userByEmail, httpSession.getId());
  72.  
  73. return userDetails;
  74. }
  75. }
  76.  
  77. $scope.loginUser = function () {
  78. $scope.user.user = $scope.email;
  79. $scope.user.password = $scope.password;
  80. $http.get("/login", { params: {username: $scope.user.user, password: $scope.user.password}});
Add Comment
Please, Sign In to add comment