Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. }`
  2. `@Override
  3. protected void configure(HttpSecurity http) throws Exception {
  4. System.out.println("Http scurity called");
  5. http.httpBasic().
  6. and().
  7. authorizeRequests()
  8. .antMatchers("/").permitAll()
  9. .antMatchers("/login").permitAll()
  10. .antMatchers("/registration").permitAll()
  11. .antMatchers("/admin/**").hasAuthority("ADMIN")
  12. .antMatchers("/db").hasAuthority("DBA")
  13. .antMatchers("/user").hasAuthority("USER").anyRequest()
  14. .authenticated().and().csrf().disable().formLogin()
  15. .loginPage("/login").failureUrl("/login?error=true")
  16. .successHandler(customSuccessHandler)
  17. .usernameParameter("username")
  18. .passwordParameter("password")
  19. .and().logout()
  20. .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
  21. .logoutSuccessUrl("/").and().exceptionHandling()
  22. .accessDeniedPage("/access-denied");
  23. }`
  24.  
  25. `@RequestMapping(value = { "/", "/login" }, method = RequestMethod.GET)
  26. public ModelAndView login() {
  27. System.out.println("/login called");
  28. ModelAndView modelAndView = new ModelAndView();
  29. modelAndView.setViewName("login");
  30. return modelAndView;
  31. }`
  32.  
  33. Authentication auth = SecurityContextHolder.getContext().getAuthentication();
  34. String currentUser = null;
  35. if (!(auth instanceof AnonymousAuthenticationToken)) {
  36. currentUser = auth.getName();
  37. }
  38.  
  39. User user1 = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  40. user1.getAuthorities();
  41. System.out.println("++++++++++++++++++++++++++++++");
  42. System.out.println(request == null);
  43. Users u = (Users) request.getSession(false).getAttribute("user");
  44. Uniconnect uni = (Uniconnect) request.getSession(false).getAttribute("uniconnect");
  45. UserUniconnect uu = new UserUniconnect();
  46. uu.setUser(u);
  47. uu.setUniconnect(uni);
  48.  
  49. return uu;
  50. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement