SEC-208: Fix threading issue.
This commit is contained in:
parent
88e8e60861
commit
fba45cb19e
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -15,6 +15,13 @@
|
||||||
|
|
||||||
package org.acegisecurity.concurrent;
|
package org.acegisecurity.concurrent;
|
||||||
|
|
||||||
|
import org.acegisecurity.ui.session.HttpSessionDestroyedEvent;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -27,18 +34,12 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.acegisecurity.ui.session.HttpSessionDestroyedEvent;
|
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base implementation of {@link
|
* Base implementation of {@link org.acegisecurity.concurrent.SessionRegistry}
|
||||||
* org.acegisecurity.concurrent.SessionRegistry} which also listens for
|
* which also listens for {@link
|
||||||
* {@link org.acegisecurity.ui.session.HttpSessionDestroyedEvent}s
|
* org.acegisecurity.ui.session.HttpSessionDestroyedEvent}s published in the
|
||||||
* published in the Spring application context.
|
* Spring application context.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* NB: It is important that you register the {@link
|
* NB: It is important that you register the {@link
|
||||||
|
@ -59,21 +60,29 @@ public class SessionRegistryImpl implements SessionRegistry,
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
|
public Object[] getAllPrincipals() {
|
||||||
|
return principals.keySet().toArray();
|
||||||
|
}
|
||||||
|
|
||||||
public SessionInformation[] getAllSessions(Object principal) {
|
public SessionInformation[] getAllSessions(Object principal) {
|
||||||
Set sessionsUsedByPrincipal = (Set) principals.get(principal);
|
Set sessionsUsedByPrincipal = (Set) principals.get(principal);
|
||||||
|
|
||||||
if (sessionsUsedByPrincipal == null) {
|
if (sessionsUsedByPrincipal == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
Iterator iter = sessionsUsedByPrincipal.iterator();
|
Iterator iter = sessionsUsedByPrincipal.iterator();
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
String sessionId = (String) iter.next();
|
synchronized (sessionsUsedByPrincipal) {
|
||||||
SessionInformation sessionInformation = getSessionInformation(sessionId);
|
String sessionId = (String) iter.next();
|
||||||
if (!sessionInformation.isExpired()) {
|
SessionInformation sessionInformation = getSessionInformation(sessionId);
|
||||||
list.add(sessionInformation);
|
|
||||||
}
|
if (!sessionInformation.isExpired()) {
|
||||||
|
list.add(sessionInformation);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (SessionInformation[]) list.toArray(new SessionInformation[] {});
|
return (SessionInformation[]) list.toArray(new SessionInformation[] {});
|
||||||
|
@ -134,21 +143,18 @@ public class SessionRegistryImpl implements SessionRegistry,
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
sessionIds.remove(sessionId);
|
sessionIds.remove(sessionId);
|
||||||
|
|
||||||
Set sessionsUsedByPrincipal = (Set) principals.get(info
|
Set sessionsUsedByPrincipal = (Set) principals.get(info.getPrincipal());
|
||||||
.getPrincipal());
|
|
||||||
|
|
||||||
if (sessionsUsedByPrincipal != null) {
|
if (sessionsUsedByPrincipal != null) {
|
||||||
sessionsUsedByPrincipal.remove(sessionId);
|
synchronized (sessionsUsedByPrincipal) {
|
||||||
|
sessionsUsedByPrincipal.remove(sessionId);
|
||||||
if (sessionsUsedByPrincipal.size() == 0) {
|
|
||||||
// No need to keep pbject in principals Map anymore
|
if (sessionsUsedByPrincipal.size() == 0) {
|
||||||
principals.remove(info.getPrincipal());
|
// No need to keep object in principals Map anymore
|
||||||
|
principals.remove(info.getPrincipal());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getAllPrincipals() {
|
|
||||||
return principals.keySet().toArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue