java - auto login for spring security 2.0 RC4 -


I am using grails 2.4.2 and spring security 2.0 RC4 and for automatic login for registration purposes I am trying. The form used in the GSP page is as follows:

  & lt; G: form controller = "register" action = "save" & gt; Username: & lt; Input type = "text" name = "username" & gt; Password: & lt; Input type = "password" name = "pwd" & gt; & Lt; Input type = "submit" value = "register" & gt; & Lt; / G: form & gt;  

and in the admin code

  def save () {def person = new secUser (username: params.username, password: params.pwd, enable : True, account, expiration: false, account lock: falls, password proof: fresace) person.save () def sec = secular.gate (interaction) Def roles = New SecureSec (Secure: SecureGet (second .ID), SecondRole: SecRole.get (2)) role.save () Authentication Authentication = New User Name Password Authentication token (params.user.username, params.user .password); . SecurityContextHolder.getContext () setAuthentication (Authentication);  

and the following is imported: Import org.springframework.security.core.Authentication Import org.springframework.security.core.authority.AuthorityUtils Import org.springframework.security.core.context. SecurityContextHolder

but it does not work and shows an error in SecurityContextHolder.getContext () as can not apply to null object < / Code> Please help.

This resolved my problem for auto-login using Spring Security

 def signUser = new secUser (Username: params.user Email, Password: Parameters UserPassword) signUser.save () Authentication Authentication = New User Name Password Authentication token (Signuser, blank, Authorization UT.ContentAuthority list ("ROLE_USER ")); . SecurityContextHolder.getContext () setAuthentication (Authentication);  

Authorization utility.ContentAuthorityList ("ROLE_USER") is used to assign a role to the user for auto-login, authorization as per your requirement Update on

Import the following files for this

Import org.springframework.security.core.authority.AuthorityUtils Import org.springframework.security.authentication.UsernamePasswordAuthenticationToken Import org. Springframework.security.Score.Amplementation Import org.springframework.security.core.context.SecurityContextHolder

After these tasks, you sec_user_id to springSecurityService. Principal can use. ID


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -