Guest User

Untitled

a guest
Apr 7th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. public class AuthSuccessEventHandler implements AuthenticationSuccessHandler {
  2.  
  3. // private static final String URL_ADMIN = "http://192.168.1.7:909/admin/auth/loginhello.html";
  4. // private static final String URL_USER = "/";
  5.  
  6. private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
  7.  
  8. @Override
  9. public void onAuthenticationSuccess(HttpServletRequest request,
  10. HttpServletResponse response,
  11. Authentication authentication) throws IOException {
  12.  
  13. Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
  14.  
  15. if (authorities.contains(new SimpleGrantedAuthority(User.ROLE_ADMIN))) {
  16. // response.sendRedirect("/admin/auth/loginhello.html");
  17. redirectStrategy.sendRedirect(request, response, "/admin/auth/loginhello.html");
  18. return;
  19. }
  20.  
  21. if (authorities.contains(new SimpleGrantedAuthority(User.ROLE_USER))) {
  22.  
  23. }
  24. }
  25. }
  26.  
  27. <security:http use-expressions="true">
  28. <security:intercept-url pattern="/api/admin/**" access="hasRole('ROLE_ADMIN')" />
  29. <security:intercept-url pattern="/admin/auth/login.html**" access="isAnonymous()" />
  30. <security:intercept-url pattern="/admin/index.html**" access="hasRole('ROLE_ADMIN')" />
  31. <security:intercept-url pattern="/api/**" access="hasRole('ROLE_USER')" />
  32. <security:form-login login-page="/admin/auth/login.html"
  33. authentication-success-handler-ref="authenticationSuccessHandler"
  34. username-parameter="username"
  35. password-parameter="password"
  36. login-processing-url="/admin/login"/>
  37. <security:csrf disabled="true"/>
  38. </security:http>
  39.  
  40. signIn() {
  41. this.logger.debug('Body: ', JSON.stringify({username: this.username, password: this.password}));
  42.  
  43. const body = new HttpParams()
  44. .set('username', this.username)
  45. .set('password', this.password);
  46.  
  47. this.http.post(this.loginUrl, body,
  48. {
  49. headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'}),
  50. responseType: 'blob',
  51. withCredentials: true,
  52. }).subscribe(val => {
  53. this.logger.debug('POST call successful value returned in body', val);
  54. }, response => {
  55. this.logger.debug('POST call in error', response);
  56. }, () => {
  57. this.logger.debug('The POST observable is now completed.');
  58. },
  59. );
  60. }
Add Comment
Please, Sign In to add comment