Reputation: 1
HOW to implement session for the user logged in
THIS IS THE CODE I HAVE IMPLEMENTED
def user=User.findByUserId(params.userId)
if(user)
{
def sessionUser=user
def sessionId=sessionUser.id
constSessionUser=sessionUser
constSessionId=sessionId
..........
}
But if I login using different username and password still the params.userId returned is of previous user even though i have terminated it with session.invalidate()
since iam using Springsecurity i just pass username and password but the session created is still of the PREVIOUS USER OR ANY OTHER USER WHO HAS CURRENTLY REGISTERED !
1)HOW DO I CREATE A SESSION FOR THE USER LOGGED IN USING SPRING SECURITY SINCE
def user=User.findByUserName(params.username)
is also leading to the same problem
2)HOW DO I TERMINATE A SESSION SO THAT SAME SESSION IS NOT IN PROCESS EVEN IF DIFFERENT USER HAS LOGGED IN
Any help will be truly appreciated plz...As iam new to Grails...
Upvotes: 0
Views: 1210
Reputation: 35951
You don't need to use session, or track user manually, if you're using Spring Security plugin. When you need, you can access user details through SpringSecurityService
(see docs), like:
class MyController() {
SpringSecurityService springSecurityService
def me() {
render model: [user: springSecurityService.currentUser]
}
}
Upvotes: 1