In my project certain users have dual roles, so if any such user logs in how can I make him switch between those 2 ROLES he has so that he can perform certain operations which that particular ROLE provides.
Appreciate step by step process as I am really new to Grails. Any such literature online with example is highly appreciated.
UPDATE:- WorkridersUser loadUserByUsername(String username, String roleName) throws UsernameNotFoundException { // def conf = SpringSecurityUtils.securityConfig //Class User = grailsApplication.getDomainClass("Person").clazz
SchemeUser.withTransaction { status ->
SchemeUser user = SchemeUser.findByUsername(username)
if (!user){ throw new UsernameNotFoundException('User not found', username)}
UserProfile userProfile = UserProfile.findByEmail(user.username)
Representative representative = Representative.findByUser(user)
Organization organization = Organization.get(representative.organization.id)
def authorities = user.authorities.collect {new GrantedAuthorityImpl(it.authority)}
return new WorkridersUser(user.username, user.password, user.enabled,
!user.accountExpired, !user.passwordExpired, !user.accountLocked,
authorities ?: roleName, user.id, organization.companyName,userProfile)
}
}
Thanks
Sri