spring - Auto login after successful registration -


hey want make auto login after successful registration in spring meaning: have protected page requires login access them , want after registration skip login page , make auto login user can see protected page, got me ? using spring 3.0 , spring security 3.0.2 how ?

this can done spring security in following manner(semi-psuedocode):

import org.springframework.security.web.savedrequest.requestcache; import org.springframework.security.web.savedrequest.savedrequest;  @controller public class signupcontroller {      @autowired     requestcache requestcache;      @autowired     protected authenticationmanager authenticationmanager;      @requestmapping(value = "/account/signup/", method = requestmethod.post)     public string createnewuser(@modelattribute("user") user user, bindingresult result,  httpservletrequest request, httpservletresponse response) {         //after creating user         authenticateuserandsetsession(user, request);          return "redirect:/home/";     }      private void authenticateuserandsetsession(user user, httpservletrequest request) {         string username = user.getusername();         string password = user.getpassword();         usernamepasswordauthenticationtoken token = new usernamepasswordauthenticationtoken(username, password);          // generate session if 1 doesn't exist         request.getsession();          token.setdetails(new webauthenticationdetails(request));         authentication authenticateduser = authenticationmanager.authenticate(token);          securitycontextholder.getcontext().setauthentication(authenticateduser);     } } 

update: contain how create session after registration


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -