onSuccess(..) -> onLogin(..), sessionDestroyed(..) 수정

master
mjkhan21 9 months ago
parent 4663096f4f
commit dc9ba1d219

@ -23,7 +23,7 @@ public interface AuthenticationService extends UserDetailsService {
/**
* @param authentication
*/
void onSuccess(Authentication authentication);
void onLogin(Authentication authentication);
/**
* @param params

@ -177,7 +177,7 @@ public class AuthenticationServiceBean extends DaoAuthenticationProvider impleme
}
@Override
public void onSuccess(Authentication authentication) {
public void onLogin(Authentication authentication) {
log().debug("{} authenticated.", authentication.getPrincipal());
authenticationBean.onSuccess(authentication);
}

@ -72,7 +72,7 @@ public class AuthenticationSuccess extends SavedRequestAwareAuthenticationSucces
user.setInfo("loggedInAt", new Date());
remember(user, hreq, hresp);
}
authenticationService.onSuccess(authentication);
authenticationService.onLogin(authentication);
return new DataObject().set("authenticated", true);
}

@ -72,11 +72,6 @@ public class LogoutSuccess extends SimpleUrlLogoutSuccessHandler implements Appl
@Override
public void onLogoutSuccess(HttpServletRequest hreq, HttpServletResponse hresp, Authentication authentication) throws IOException, ServletException {
authenticationService.onLogout(authentication);
HttpSession session = hreq.getSession(false);
if (session != null)
session.invalidate();
new Kookie()
.set(hreq)
.set(hresp)
@ -88,32 +83,6 @@ public class LogoutSuccess extends SimpleUrlLogoutSuccessHandler implements Appl
hresp.sendRedirect(getSuccessUrl(hreq.getContextPath()));
}
/* .
* @param hreq 릿
* @param hresp 릿
protected void removeCookies(HttpServletRequest hreq, HttpServletResponse hresp) {
Cookie[] cookies = hreq.getCookies();
if (cookies == null || cookies.length < 1) return;
for (Cookie cookie: cookies) {
removeCookie(hresp, cookie, "JSESSIONID", "userAccount");
}
}*/
/* .
* @param hresp 릿
* @param cookie
* @param cookieNames
protected void removeCookie(HttpServletResponse hresp, Cookie cookie, String... cookieNames) {
for (String name: cookieNames) {
if (!name.equals(cookie.getName())) continue;
cookie.setMaxAge(0);
cookie.setValue("");
hresp.addCookie(cookie);
}
}*/
@Override
public void setApplicationContext(ApplicationContext actx) throws BeansException {
if (!(actx instanceof WebApplicationContext)) return;
@ -128,11 +97,23 @@ public class LogoutSuccess extends SimpleUrlLogoutSuccessHandler implements Appl
@Override
public void sessionDestroyed(HttpSessionEvent evt) {
HttpSession session = evt.getSession();
if (isHandled(session)) return;
SecurityContext sctx = (SecurityContext)session.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
if (sctx == null) return;
Authentication authentication = sctx.getAuthentication();
log().debug("Session expired for {}", authentication.getPrincipal());
authenticationService.onLogout(authentication);
log().debug("Session expired for {}", authentication.getPrincipal());
}
private boolean isHandled(HttpSession session) {
Boolean handled = (Boolean)session.getAttribute("evtHandled");
if (Boolean.TRUE.equals(handled)) {
session.removeAttribute("evtHandled");
return true;
}
session.setAttribute("evtHandled", true);
return false;
}
}
Loading…
Cancel
Save