Grails Spring Security: Switching between dual ROLEs -
in project users have dual roles, if such user logs in how can make him switch between 2 roles has can perform operations particular role provides.
appreciate step step process new grails. such literature online example 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
you need override loaduserbyusername method follows:
userdetails loaduserbyusername(string username, string selectedrole) { // current selected role stored in member variable of userdetail class this.selectedrole = selectedrole return loaduserbyusername(username) }
to show roles of current user within select box write own tag lib should like:
def authorities = springsecurityservice.principal.originalauthorities if (authorities.size() > 1) { out << "<form name='switchroleform' action='switchrole' method='post'>" out << "<select name='roles'>" role tmprole authorities.each { tmprole = role.findbyauthority(it.authority) // access current select role if (springsecurityservice.principal.selectedrole== it.authority) out << "<option selected value='${it.authority}'>${tmprole.name}</option>" else out << "<option value='${it.authority}'>${tmprole.name}</option>" } out << "</select>" out << '<input class="switch" type="submit" value="switch"/></span>' out << "</form>" }
i described switch logic in previous post.
Comments
Post a Comment