BAEL-315 Removing custom success handler in favor of the default redirect.
This commit is contained in:
parent
c7551758d8
commit
9255a8390d
@ -1,54 +0,0 @@
|
||||
package com.baeldung.spring.cloud.bootstrap.gateway;
|
||||
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.WebAttributes;
|
||||
import org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler;
|
||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CustomAuthenticationHandler extends AbstractAuthenticationTargetUrlRequestHandler implements AuthenticationSuccessHandler{
|
||||
|
||||
public CustomAuthenticationHandler() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which sets the <tt>defaultTargetUrl</tt> property of the base class.
|
||||
* @param defaultTargetUrl the URL to which the user should be redirected on
|
||||
* successful authentication.
|
||||
*/
|
||||
public CustomAuthenticationHandler(String defaultTargetUrl) {
|
||||
setDefaultTargetUrl(defaultTargetUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the parent class {@code handle()} method to forward or redirect to the target
|
||||
* URL, and then calls {@code clearAuthenticationAttributes()} to remove any leftover
|
||||
* session data.
|
||||
*/
|
||||
public void onAuthenticationSuccess(HttpServletRequest request,
|
||||
HttpServletResponse response, Authentication authentication)
|
||||
throws IOException, ServletException {
|
||||
response.setStatus(303);
|
||||
handle(request, response, authentication);
|
||||
clearAuthenticationAttributes(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes temporary authentication-related data which may have been stored in the
|
||||
* session during the authentication process.
|
||||
*/
|
||||
protected final void clearAuthenticationAttributes(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
|
||||
}
|
||||
}
|
@ -28,7 +28,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.successHandler(new CustomAuthenticationHandler("/resource/hello/user"))
|
||||
.and()
|
||||
.logout().permitAll()
|
||||
.logoutSuccessUrl("/resource/hello/cloud").permitAll()
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.spring.cloud.bootstrap.gateway;
|
||||
package com.baeldung.spring.cloud.bootstrap.gateway.filter;
|
||||
|
||||
import com.netflix.zuul.ZuulFilter;
|
||||
import com.netflix.zuul.context.RequestContext;
|
Loading…
x
Reference in New Issue
Block a user