Spring Security SessionRegistry java config only -
can provide real working code snippet on how not empty sessionregistry object in spring security using java config only (without xml).
i'm using spring security v4.0.1.release
and i'm tried do:
- implemented hashcode() , equals() methods in userdetails apache commons lang:
@override public int hashcode() { return hashcodebuilder.reflectionhashcode(this, "password", "id", "role", "description", "registrationdate", "enabled"); } @override public boolean equals(object obj) { return equalsbuilder.reflectionequals(this, obj, "password", "id", "role", "description", "registrationdate", "enabled"); }
- enabled httpsessioneventpublisher:
public class appsecurityinitializer extends abstractsecuritywebapplicationinitializer { @override protected boolean enablehttpsessioneventpublisher() { return true; } }
- defined beans in security config class:
@bean public sessionregistry getsessionregistry() { return new sessionregistryimpl(); } @bean public sessionauthenticationstrategy getsessionauthstrategy(sessionregistry sessionregistry) { concurrentsessioncontrolauthenticationstrategy controlauthenticationstrategy = new concurrentsessioncontrolauthenticationstrategy(sessionregistry); return controlauthenticationstrategy; }
- set http security:
httpsecurity .formlogin().loginpage("/login") .defaultsuccessurl("/", true) .successhandler(new loginsuccesshandler()) .and() .sessionmanagement() .sessionauthenticationstrategy(sessionauthenticationstrategy).maximumsessions(1).maxsessionspreventslogin(true) .and().and() .csrf().disable(); return httpsecurity;
code works, it's prevents me login under same user twise, when i'm getting sessionregistry in controller class, it's empty.
looks if spring creates different sessionregistryimpl on own.
what about
httpsecurity .sessionmanagement() .maximumsessions(1) .sessionregistry(getsessionregistry());
leaving out sessionauthenticationstrategy stuff?!
Comments
Post a Comment