java - How to autowire SecurityContextRepository by class implementation -
i'm trying ajax login code taked overthere, is:
@controller @requestmapping("/login") public class ajaxlogincontroller { @autowired @qualifier("authenticationmanager") authenticationmanager authenticationmanager; @autowired securitycontextrepository repository; @autowired remembermeservices remembermeservices; @requestmapping(method=requestmethod.get) public void login() {} @requestmapping(method=requestmethod.post) @responsebody public string performlogin( @requestparam("j_username") string username, @requestparam("j_password") string password, httpservletrequest request, httpservletresponse response) { usernamepasswordauthenticationtoken token = new usernamepasswordauthenticationtoken(username, password); seek { authentication auth = authenticationmanager.authenticate(token); securitycontextholder.getcontext().setauthentication(auth); repository.savecontext(securitycontextholder.getcontext(), request, response); remembermeservices.loginsuccess(request, response, auth); homecoming "{\"status\": true}"; } grab (badcredentialsexception ex) { homecoming "{\"status\": false, \"error\": \"bad credentials\"}"; } } }
this illustration have xml configuration of beans autowire, project requires class configuration. solved first autowire issue adding security class configuration:
@bean public authenticationmanager authenticationmanager() throws exception { homecoming authenticationmanager(); }
now i'm trying securitycontextrepository find on forums xml configurations solutions. knows how configure class bean solve this? thx.
httpsessionsecuritycontextrepository
default implementation securitycontextrepository
. add together configuration:
@bean public securitycontextrepository securitycontextrepository() { homecoming new httpsessionsecuritycontextrepository(); }
note name of bean securitycontextrepository
, not repository
which, think, reduces possible ambiguity.
java ajax spring login spring-security
No comments:
Post a Comment