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:

  1. 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");     }  
  1. enabled httpsessioneventpublisher:
      public class appsecurityinitializer extends             abstractsecuritywebapplicationinitializer {          @override         protected boolean enablehttpsessioneventpublisher() {             return true;         }     }  
  1. 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;     }  
  1. 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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -