Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AuthSuccessEventHandler implements AuthenticationSuccessHandler {
- // private static final String URL_ADMIN = "http://192.168.1.7:909/admin/auth/loginhello.html";
- // private static final String URL_USER = "/";
- private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
- @Override
- public void onAuthenticationSuccess(HttpServletRequest request,
- HttpServletResponse response,
- Authentication authentication) throws IOException {
- Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
- if (authorities.contains(new SimpleGrantedAuthority(User.ROLE_ADMIN))) {
- // response.sendRedirect("/admin/auth/loginhello.html");
- redirectStrategy.sendRedirect(request, response, "/admin/auth/loginhello.html");
- return;
- }
- if (authorities.contains(new SimpleGrantedAuthority(User.ROLE_USER))) {
- }
- }
- }
- <security:http use-expressions="true">
- <security:intercept-url pattern="/api/admin/**" access="hasRole('ROLE_ADMIN')" />
- <security:intercept-url pattern="/admin/auth/login.html**" access="isAnonymous()" />
- <security:intercept-url pattern="/admin/index.html**" access="hasRole('ROLE_ADMIN')" />
- <security:intercept-url pattern="/api/**" access="hasRole('ROLE_USER')" />
- <security:form-login login-page="/admin/auth/login.html"
- authentication-success-handler-ref="authenticationSuccessHandler"
- username-parameter="username"
- password-parameter="password"
- login-processing-url="/admin/login"/>
- <security:csrf disabled="true"/>
- </security:http>
- signIn() {
- this.logger.debug('Body: ', JSON.stringify({username: this.username, password: this.password}));
- const body = new HttpParams()
- .set('username', this.username)
- .set('password', this.password);
- this.http.post(this.loginUrl, body,
- {
- headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'}),
- responseType: 'blob',
- withCredentials: true,
- }).subscribe(val => {
- this.logger.debug('POST call successful value returned in body', val);
- }, response => {
- this.logger.debug('POST call in error', response);
- }, () => {
- this.logger.debug('The POST observable is now completed.');
- },
- );
- }
Add Comment
Please, Sign In to add comment