java - Centralized system for session management (and killing) for Spring Security and/or Spring BlazeDS Integration -
i'm having hard time implementing feature our customer requests. in short want able logout customer of choosing out of application via admin side. application using flex front end technology , accessing server via amf. server side using spring security , spring blazeds integration.
basically question is: spring security and/or spring blazeds integration offer centralized system session management (and killing) out-of-the-box?
for proof-of-concept purposes have tried logout users , kill sessions following code:
package xxx.xxx.xxx; import java.util.list; import org.apache.commons.lang.builder.reflectiontostringbuilder; import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory; import org.springframework.beans.factory.annotation.autowired; import org.springframework.security.authentication.usernamepasswordauthenticationtoken; import org.springframework.security.core.session.sessioninformation; import org.springframework.security.core.session.sessionregistry; import org.springframework.security.core.userdetails.user; import flex.messaging.messagebroker; import flex.messaging.security.logincommand; public class sessionserviceimpl { private static final log log = logfactory.getlog(sessionserviceimpl.class); private sessionregistry sessionregistry; private messagebroker messagebroker; public sessionregistry getsessionregistry() { return sessionregistry; } @autowired public void setsessionregistry(sessionregistry sessionregistry) { log.debug("sessionregistry set"); this.sessionregistry = sessionregistry; } public messagebroker getmessagebroker() { return messagebroker; } @autowired public void setmessagebroker(messagebroker messagebroker) { log.debug("messagebroker set"); this.messagebroker = messagebroker; } public void logoutuser(string username) { log.debug("logging out user username: "+username); list<object> principals = null; if(sessionregistry != null){ principals = sessionregistry.getallprincipals(); }else{ log.debug("sessionregistry null"); } if(principals != null){ (object object : principals) { user user = (user)object; // single users sessions list<sessioninformation> sessions = sessionregistry.getallsessions(user, false); log.debug("sessions list size: "+sessions.size()); if(messagebroker != null){ logincommand command = messagebroker.getloginmanager().getlogincommand(); usernamepasswordauthenticationtoken usernamepasswordauthenticationtoken = new usernamepasswordauthenticationtoken(user, user.getpassword()); command.logout(usernamepasswordauthenticationtoken); (sessioninformation sessioninformation : sessions) { log.debug(reflectiontostringbuilder.tostring(sessioninformation)); sessioninformation.expirenow(); sessionregistry.removesessioninformation(sessioninformation.getsessionid()); } }else{ log.debug("messagebroker null"); } if(object != null){ log.debug(reflectiontostringbuilder.tostring(object)); }else{ log.debug("object null"); } } }else{ log.debug("principals null"); } } } unfortunately above code not work. far can tell because 2 things:
a) logincommand not "application wide" tied current session, therefore try logout current session (the session admin using) , oblivious of other sessions
b) sessioninformation.expirenow() tries expire session if user manages make request before session gets invalidated, session not destroyed
from documentation can see session directly invalidated session.invalidate(), seems have no way access session objects.
what fastest or smartest way implement kind of feature?
best regards, jukka
my approach have indirect session invalidation.
use concurrentsessioncontrol security option limit 1 session per user. write custom sessionauthenticationstrategy checks if user has been marked , invalidates session if needed. note session strategy should executed before example usernamepassword filter creates new session.
you can user either database or static class hold usernames. furthermore want have kind of timestamp, invalidats sessions x minutes after have been marked.
a whole approach implement servlet session listener, records login sessions in user->session map , can invalidate them if necessary
you can take @ reference manual on how wire beans http://docs.spring.io/spring-security/site/docs/3.0.x/reference/session-mgmt.html
Comments
Post a Comment