Based on the Permission base table, the permission base data operation.
A brief description of the process:
Login account: Gets the current account binding role, according to role to get this role associated with the action,action as the menu when what to do when the button.
One of the simplest methods is presented here for informational purposes only.
First Step Login
Process:
Front desk:
1. Send account password to action (various validations no longer tell)
Actiong Layer
1. According to the account password to inquire
2. Get role saved to session
3. Get action saved to session
4. Login Failure prompt
PublicString Login () {string R= ""; T_user u= SERVICE.GETBYHQL ("From T_user where t_name= '" + data.gett_name () + "' and t_password= '" +Data.gett_password ()+ "'"); if(U! =NULL) {Set<T_role> roles =U.getrole (); for(Iterator<t_role> Iterator =Roles.iterator (); iterator. Hasnext ();) {t_role Role=Iterator.next (); GetSession (). SetAttribute ("Role", Role.getname ()); GetSession (). SetAttribute ("Roleid", Role.getid ()); Set<Menu> Menu =Role.getmenu (); List<Menu> list =NewArraylist<menu>(menu); GetSession (). SetAttribute ("Action", list); } R= "Login"; } Else{R= "Loginout"; } returnR; }
In this case, all actions are saved to the session (there are no buttons here, you will do an optimization later, there is no time)
The Permissions menu tree then generates different menus based on the role
Front desk
1.easyui Asynchronous Tree
Action Layer
1. Get the Role ID
2. Eradicate the role ID check the associated node
3. Generating an asynchronous tree
//gets the permission tree for the current role Public voidGetroletree () {String Roleid= (String) getsession (). getattribute ("Roleid"); Jsonarray Jsonarray=NewJsonarray (); String hql=""; Try { if(id!=NULL&&!id.equals ("") ) {hql= "from Menu Where pid= '" +id+ "'"; } Else{hql= "From Menu Where pid=null"; } List<Menu> list=Service.find (HQL); for(intI=0;i<list.size (); i++) {Set<T_role> role =NewHashset<>(); Role=List.get (i). Getrole (); Jsonobject JSON=NewJsonobject (); for(Iterator<t_role> Iterator =role.iterator (); Iterator.hasnext ();) {T_role R=Iterator.next (); if(R.getid (). Equals (Roleid)) {Json.put ("id", List.get (i). GetId ()); Json.put ("Text", List.get (i). GetName ()); if(Service.find ("from menu Where pid= '" +list.get (i). GetId () + "'"). Size () ==0) {Json.put ("State", "open"); } Else if(Service.find ("from menu Where pid= '" +list.get (i). GetId () + "'"). Size () >0) {Json.put ("State", "closed"); } Jsonobject J=NewJsonobject (); J.put ("url", List.get (i). GETURL ()); Json.put ("Attributes", J); Jsonarray.add (JSON); } } } } Catch(Exception e) {//Todo:handle ExceptionLogger.info (e.tostring ()); } Writejson (Jsonarray); }
For the idea of saving the button to the session again
GetSession (). SetAttribute ("Quanxian", "none"); the identification of the corresponding button in the session is displayed or hidden
button on style= "Disply:${sessionscope.quanxian}"
In this case, the corresponding button is hidden. Of course, there are better ways to write here first, and there's a better way back.
SSH Integrated Easyui permissions design (login to different accounts associated with different role to get different permissions)