Four (rules) of authority components

xiaoxiao2021-03-06  90

After defining User, Group, Role, I define the rules for permission judgment.

First define the rule interface, see Rule.java.rule only to do one thing to determine if the user has permission.

Then I realized a Rule, see RuleImpl.java.

This part involves an Input class, which is an input class, interface such as Input.java. This can use various way data (HTTP, XML, SOAP ...) as input data by inheriting the interface.

Permission is the authority class, which will be introduced below.

====================== rule.java ========================== ======

Package org.fswan.Permission;

Import java.util.hashmap;

Import org.fswan.input;

/ **

* Rules used to make judgments.

* For Permission calls

* /

Public Interface Rule

{

Public Boolean Pass (Permission Permission, User, Hashmap Olddata, Input Input);

}

======================= rleImpl ========================== =========

Package org.fswan.Permission;

Import java.util.arraylist;

Import java.util.hashmap;

Import java.util.properties;

Import org.fswan.input;

/ **

*

* /

Public Class RuleImpl IMPLEMENTS RULE

{

/ * (non-javadoc)

* @see org.fswan.permission.rule # pass (org.fswan.permission.permission, org.fswan.permission.r, org.fswan.Permission.Role, Org.FSwan.Permission.group, java.util.hashmap Org.fswan.input)

* /

Public Boolean Pass (Permission Permission, User, Hashmap OldData, Input Input)

{

Try

{

Role [] Roles = User.getroles ();

IF (Roles! = NULL)

{

For (int i = 0; i

{

IF (Haspermission (Permission, User, Roles [I], OldData, Input) // has permission

Return True;

}

}

Group [] groups = user.getgroups ();

IF (groups! = null)

For (int i = 0; i

{

IF (PASS (Permission, Groups [I], OldData, Input))

Return True;

}

Return False;

} catch (Exception EX)

{

EX.PrintStackTrace ();

}

Return False;

}

/ **

* Determine if a role of the user has permission to perform actions

* @Param permission permissions

* @Param User user

* @Param role role

* @Param OldData data

* @Param INPUT input

* @return has permission

* /

Private Boolean Haspermission (Permission Permission, User User, Role Role, Hashmap Olddata, Input Input)

{

/ / If the role does not have this permission ID, there is no authority

IF (Role.GetPermissionProp (Permission.getPermissionname ()) == NULL)

Return False;

// If the permissions are also judged

IF (permission.getPermissionItem ()! = null)

{

ArrayList item = permission.getPermissionItem ();

Boolean Accept = TRUE;

ArrayList RoleItem = (arraylist) role.getPermissionProp (Permission.getPermissionName ());

TTT: for (INT i = 0; I

{

Properties P = (Properties) RoleItem.get (i);

Accept = true;

For (int J = 0; j

{

IF (p.getproperty (item.get (j)! = null

&& p.getProperty (item.get (j) .tostring ()). Indexof (Item.get (j) .tostring ()). Tostring ())

! = -1) // If there is no authority

Continue TTT;

}

Return True;

}

Return False;

}

Return True;

}

}

============================= input.java ================================================================================================================================================================================================= =====

Package org.fswan;

/ **

* @Author Fang Zhiwen

*

* Enter the interface of the data, as the data input of the primary class,

* You can get data from XML, HTTPSERVLETREQUEST and JSPUPLOAD *

* /

Public interface infut {

/ **

* Get the value of the parameters, return null if this parameter is returned, and if the parameter corresponds to multiple values, return its first value.

* @Param parameter parameter

* @Return value

* /

Public String getParameter (String parameter);

/ **

* Get the list of values ​​for parameters

* @Param parameter parameter

* @Return value

* /

Public String [] getParameterValues ​​(String parameter);

/ **

* Get a list of parameter names

* @Return all parameters

* /

PUBLIC STRING [] getParameterNames ();

/ **

* Get data source

* @return data source

* /

Public Object getSource ();

/ **

* Setting parameters, if this parameter already exists, the original invalid

* @Param parameter parameter

* @Param Value Value

* /

Public void setParameter (String parameter, string value);

/ **

* Setting parameters, if this parameter already exists, the original invalid

* @Param parameter parameter

* @Param VALUES value

* /

Public void setParameter (String parameter);

/ **

* Add parameters, if this parameter already exists, the value is added to the original value.

* @Param parameter parameter

* @Param Value Value

* /

Public void addparameter (String parameter, string value);

/ **

* Add parameters (multiple values), if this parameter already exists, add this value to the original value into an array

* @Param parameter parameter

* @Param VALUES value

* /

Public void addparameter (String parameter);

}

转载请注明原文地址:https://www.9cbs.com/read-96535.html

New Post(0)