SessionRegistryImpl is now aware of SessionIdChangedEvent

This commit is contained in:
Venkata Jaswanth
2018-06-14 01:36:07 +10:00
committed by Eleftheria Stein
parent ae532c080c
commit 5fc6414377
7 changed files with 164 additions and 5 deletions

View File

@@ -25,6 +25,7 @@ import org.springframework.security.web.context.support.SecurityWebApplicationCo
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
/**
@@ -44,7 +45,7 @@ import javax.servlet.http.HttpSessionListener;
*
* @author Ray Krueger
*/
public class HttpSessionEventPublisher implements HttpSessionListener {
public class HttpSessionEventPublisher implements HttpSessionListener, HttpSessionIdListener {
// ~ Static fields/initializers
// =====================================================================================
@@ -90,4 +91,16 @@ public class HttpSessionEventPublisher implements HttpSessionListener {
getContext(event.getSession().getServletContext()).publishEvent(e);
}
@Override
public void sessionIdChanged(HttpSessionEvent event, String oldSessionId) {
HttpSessionIdChangedEvent e = new HttpSessionIdChangedEvent(event.getSession(), oldSessionId);
Log log = LogFactory.getLog(LOGGER_NAME);
if (log.isDebugEnabled()) {
log.debug("Publishing event: " + e);
}
getContext(event.getSession().getServletContext()).publishEvent(e);
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.web.session;
import javax.servlet.http.HttpSession;
import org.springframework.security.core.session.SessionIdChangedEvent;
/**
* Published by the {@link HttpSessionEventPublisher} when an {@code HttpSession} id
* is changed
*
*/
public class HttpSessionIdChangedEvent extends SessionIdChangedEvent {
private final String oldSessionId;
private final String newSessionid;
// ~ Constructors
// ===================================================================================================
public HttpSessionIdChangedEvent(HttpSession session, String oldSessionId) {
super(session);
this.oldSessionId = oldSessionId;
this.newSessionid = session.getId();
}
public String getOldSessionId() {
return oldSessionId;
}
@Override
public String getNewSessionId() {
return newSessionid;
}
}