Permission ideas and code implementation __ Management

Source: Internet
Author: User
Rights Management Ideas & code implementation Authority Idea: Page Prototypes:

!
Figure 1

The page contains a username, password, role, and authentication code. A character is the data that is loaded in the background by Ajax when accessing the login page. When the login is clicked, the form passes the user name, password, role ID and authentication code in the page to the background for verification.


Figure 2


Figure 3


Figure 4


Figure 5


Figure 6


Figure 7

Jump Logic:

When the login is successful, the page will display as shown in Figure 2, first click on user management, jump to Figure 3 , and then role assignment, when the role is assigned, click on the left side of the role management jump to Figure 4 Show all the roles, Then click on the Role list of the menu allocation jump to Figure 5 To assign the menu, after the allocation is completed will return to the role list, click the allocation module to jump to Figure 7 , you can click on the corresponding permissions of the checkbox to authorize the module. database table Design:

The database is designed as shown below:

Figure 8

controller and Method list:

The following is a list of methods in each action: loginaction:
Login Authentication Login Logout for safe exit menuaction:
FindAll Query all menu Data Findallinroletojson query Role of all the menus, for the successful login after the left menu, JSON findallofdistributetojson query all menus, for the role of the menu allocation, Returns the JSON Findallofdistribute returns the view of the allocation menu roleaction:
FindAll query all role data Findalloflogintojson query all roles, return JSON data, select roles for login Findallofdistribute query all roles, use for role assignment in user management Distributemenu allocation menu Distributemodule allocation module usersaction:
FindAll query all user data Findallroleinusertojson query corresponding user role, user assigned role is data echo, JSON distributerole assign role moduleaction:
FindAll query all the module information findallofdistribute query all the modules, used in role management to allocate module core code ideas:

When you filter permissions after authorization, you need to know the action to be executed and the object's method has the corresponding permissions, first of all, after the successful login to the background to query the user's corresponding menu list and module list, menu list for display in the left menu, The module list is used to filter the requested action intent at the time of the visit.
The menu shown in the left menu is the assigned menu
In the filtering request inside the operation intention is assigns to the role the module permission filtering mentality:

Define a note (Permissions) and enumeration class (Permission) in the system

Permissions:

    /**  
     * Permission annotations  are used for methods and classes above  
     * @author Administrator  
     *  
    /@Target ({elementtype.type, Elementtype.method})  
    @Retention (retentionpolicy.runtime) public  
    @interface Permissions {  
        Permission Value () default Permission.none;  
    }  

Permission:

    /**
     * Permission Enumeration class
     * @author Administrator
     * * */public
    enum Permission {

        without ( -1),    // No Permissions required
        None (0),//        No permissions Query
        (1),//       query permission Create
        (2),//      Create permission
        UPDATE (4),      // Update Permission
        DELETE (8);      Delete permission

        private int code;

        Private Permission (int code) {
            this.code = code;
        }

        public int GetCode () {return
            This.code
        }}
    }

When used, the @permissions annotation is used in the action class or the inside method, and if used on the action, means that the method in the action that is not annotated by the @permissions annotation has the corresponding permission, if the annotation is on the method, This is subject to the annotation, such as:

    @Permissions (permission.query) Public
    class roleaction{public
        String FindAll () {return
            "FindAll";
        }
        @Permissions (permission.update) public
        void Updaterole () {
            System.out.print ("UPDATE");
        }
    

In the above code indicates that FindAll has query permission, Updaterole has update permissions.

In the process of permission filtering, the main logic in the Powerintercepter: to intercept each request, need to get the current execution of the action, method, and then according to all the permissions of the user to compare, if there is passed, otherwise returned to the page without permissions, First, according to the action to the right to query whether there is a corresponding permission, if there is the above method according to the annotation and permission code to calculate, if not, then determine whether the method above has a corresponding ignore the right of the callout, if there is a direct pass, otherwise return to the page configuration file without permissions

    <package name= "CRM" namespace= "/" extends= "Json-default" > <interceptors> <intercept or name= "Powerintercepter" class= "Powerintercepter" ></interceptor> <interceptor-stack name= "Securi" Ty "> <interceptor-ref name=" powerintercepter "></interceptor-ref> <interc Eptor-ref name= "Defaultstack" ></interceptor-ref> </interceptor-stack> </interceptors > <default-interceptor-ref name= "Security" ></default-interceptor-ref> <global-results&
            Gt
            <result name= "error" >/error.jsp</result> <result name= "Login" >/login.jsp</result> <result name= "Logout" type= "redirect" >/login.jsp</result> <result name= "main" type= "red
        Irect ">/main/main.jsp</result> <result name=" Nopower ">/common/nopower.jsp</result> </global-results> </package> <package name= "Default" namespace= "/power" extends= "CRM" > <ac tion name= "loginaction" class= "loginaction" method= "Login" ></action> <action name= "roleaction" class= "
            Roleaction "method=" FindAll "> <result name=" FindAll ">/power/role/queryList.jsp</result> <result name= "Findallofdistribute" >/power/users/distributeRole.jsp</result> <result name= " Distributemenu "type=" redirectaction >roleAction</result> <result name= "Findalloflogintojson" type = "JSON" > <param name= "root" >roles</param> </result> </action&

        Gt <action name= "usersaction" class= "usersaction" method= "FindAll" > <result name= "FindAll" >/power/use rs/querylist.jsp</result> <result name= "Distributerole" type= "Redirectaction" >usersAction</resu
    Lt>        <result name= "Findallroleinusertojson" type= "JSON" > <param name= "root" >roles</param
            > </result> </action> <action name= "menuaction" class= "Menuaction" > <result name= "Findallofdistribute" >/power/role/distributeMenu.jsp</result> <result name = "Findallofdistributetojson" type= "JSON" > <param name= "root" >menuVos</param> &L
                T;/result> <!--the left menu after successful login--> <result name= "Findallinroletojson" type= "JSON" > <param name= "root" >menuVos</param> </result> </action> ; Action name= "moduleaction" class= "moduleaction" > <result name= "Findallofdistribute" >/power/role/dist Ributemodule.jsp</result> </action> </package>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.