import org.opendaylight.controller.usermanager.ISessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.security.core.context.SecurityContext;
public class SessionManager implements ISessionManager {
.getLogger(SessionManager.class);
private Map<ServletContext, Set<HttpSession>> sessionMap = new HashMap<ServletContext, Set<HttpSession>>();
- public static final String SPRING_SECURITY_CONTEXT_KEY = "SPRING_SECURITY_CONTEXT";
@Override
public void sessionCreated(HttpSessionEvent se) {
ServletContext ctx = se.getSession().getServletContext();
String path = ctx.getContextPath();
- logger.debug("Servlet Context Path created " + path);
- logger.debug("Session Id created for ctxt path " + se.getSession().getId());
+ logger.debug("Servlet Context Path created {}", path);
+ logger.debug("Session Id created for ctxt path {}",
+ se.getSession().getId());
synchronized (sessionMap) {
Set<HttpSession> set = sessionMap.get(ctx);
public void sessionDestroyed(HttpSessionEvent se) {
ServletContext ctx = se.getSession().getServletContext();
String path = ctx.getContextPath();
- logger.debug("Servlet Context Path of destroyed session - " + path);
- logger.debug("Session Id destroyed " + se.getSession().getId());
+ logger.debug("Servlet Context Path of destroyed session - {}", path);
+ logger.debug("Session Id destroyed {}", se.getSession().getId());
synchronized (sessionMap) {
Set<HttpSession> set = sessionMap.get(ctx);
while (sessIterator.hasNext()) {
HttpSession session = sessIterator.next();
if (session != null && sessionId != null && session.getId() != null && !session.getId().equals(sessionId)) {
- Object contextFromSession = session
- .getAttribute(SPRING_SECURITY_CONTEXT_KEY);
- if (contextFromSession != null
- && contextFromSession instanceof SecurityContext) {
- String storedUserName = ((SecurityContext) contextFromSession)
- .getAuthentication().getName();
- if (storedUserName != null && storedUserName.equals(username)) {
- sessionsList.add(session);
- sessIterator.remove();
- }
- else {
- logger.debug("storedUserName is null or did not match username " + username);
- }
- } else {
- logger.debug("contextFromSession is null or not instance of SecurityContext");
- }
+ sessionsList.add(session);
+ sessIterator.remove();
}
else {
logger.debug(" session or sessionId is null ");