Using shiro to do an account before a character login, this is no problem,
But the new system,
a user has multiple roles, but must choose one of the characters when login (check in advance and then pop-up role selection window) And then want to use Shiro login only the specified character (that is, only has the function of this role permission Don't know if you could do it? How to do it?
CodePudding user response:
In shiro login check AuthorizingRealm doGetAuthorizationInfo of (in) the AuthorizationInfo here is to configure the information about the current user
The part of AuthorizationInfo object. AddRole (selected);
It only add designated the selected object, other configuration,
The results you want?
CodePudding user response:
I try upstairs
CodePudding user response:
reference 1st floor dkwuxiang response: when shiro login check AuthorizingRealm doGetAuthorizationInfo of (in) the AuthorizationInfo here is the configuration of the current user's information The part of AuthorizationInfo object. AddRole (selected); It only add designated the selected object, other configuration, The results you want? Can give a user logs in a certain roles (a role) only the default menu, After the user to select the he wanted to climb, the role of me to him with this role to log in again, Allowed to login after login again? How to do this? thank you CodePudding user response:
reference banditgao reply: 3/f Quote: refer to 1st floor dkwuxiang response: In shiro login check AuthorizingRealm doGetAuthorizationInfo of (in) the AuthorizationInfo here is to configure the information about the current user The part of AuthorizationInfo object. AddRole (selected); It only add designated the selected object, other configuration, The results you want? Can give a user logs in a certain roles (a role) only the default menu, After the user to select the he wanted to climb, the role of me to him with this role to log in again, Allowed to login after login again? How to do this? Thank you Is to add a default role, this role is not selected, the default display directly, CodePudding user response:
reference NANU 4 floor, NANA reply: Quote: refer to the third floor banditgao response: Quote: refer to 1st floor dkwuxiang response: In shiro login check AuthorizingRealm doGetAuthorizationInfo of (in) the AuthorizationInfo here is to configure the information about the current user The part of AuthorizationInfo object. AddRole (selected); It only add designated the selected object, other configuration, The results you want? Can give a user logs in a certain roles (a role) only the default menu, After the user to select the he wanted to climb, the role of me to him with this role to log in again, Allowed to login after login again? How to do this? Thank you Is to add a default role, this role is not selected, the default display directly, Yo, moderators lucky?? CodePudding user response:
Solved, let user authentication and authorization is assigned to a virtual character (without any menu and permissions), used to log in, just call the default. You don't even need to such a character data, And then let the user choose roles, The role of the user selected Session transmission LoginController Long targetRoleId=Long. ParseLong (map) get (" roleId "));//optional Subject. GetSession (). The setAttribute (" targetRoleId, "targetRoleId);//in the Session MyShiroRealm doGetAuthorizationInfo () The Subject a Subject=the SecurityUtils. GetSubject (); The Object targetRoleId=subject. GetSession (). The getAttribute (" targetRoleId "); //CbStaff CbStaff=(CbStaff) principals. GetPrimaryPrincipal (); CbRole CbRole=null; If (targetRoleId!=null)//specified role { CbRole=roleRepo. GetOne (Long. ParseLong (targetRoleId. The toString ())); AuthorizationInfo. AddRole (cbRole getRoleCode ()); Set ResSet=cbRole. GetCbRoleResources (); Iterator ResIt=resSet. The iterator (); While (resIt. HasNext ()) { CbResource res=resIt. Next (). GetCbResource (); If (res) getResourceType () & gt; 1 & amp; & StringUtils. IsNotEmpty (res) getPermission ()))//submenu AuthorizationInfo. AddStringPermission (res) getPermission ()); } } The else//the default role { CbRole=roleRepo. FindByRoleCode (" default "); AuthorizationInfo. AddRole (" default "); } In this way, can even switch roles in the application, all permissions validation is also in accordance with the selected role, I've tried, CodePudding user response:
Thank you I also encountered similar problems blogger wrote this post, there is a problem can explain CbRole this class, I want to know if the specified character is not null, is how to operate the CodePudding user response:
That learning. Various operating shiro.