One of the authority components (users)

xiaoxiao2021-03-06  106

First, I define a user interface that can be taken out from it. The code is as follows. The user must set its role and the group of groups in addition to a variety of different attributes.

A AbstractUser then processes the User commonality. All methods of acquiring properties are implemented. Users can inherit the properties to be defined according to the implementation of the properties that you want to define. (Because users of each system will have different Properties, so keep abstract classes for users their own extensions). As long as initialization variables Description, Name, Group, ID, Prop, Role, PropMAP can be initialized.

Finally, a class userimum is defined to implement a specific user for a User for general users. It is not recommended to use UserImpl directly, because later versions may overwrite the class. If you want to use, you can rename it You can.

This part involves a resourcelib class, which is in the class that I defined by the storage of various resource configurations, which can be used directly.

====================== User.java ========================== ======

Package org.fswan.Permission;

Import Org.fswan.Identity;

Import java.util.properties;

Import org.fswan.workflow.exception.cantfoundidexception;

Public Interface User

{

/ **

* Get username

* @Return username

* /

Public string getname ();

/ **

* Get user description

* @return description

* /

PUBLIC STRING GETDESCRIPTION ();

/ **

* Get user ID

* @Return user ID

* /

Public Identity GetId ();

/ **

* Get attribute

* @Return property value

* /

Public property getProperties ();

/ **

* Get the group

* @returN group list

* /

Public group [] getGroups () throws cantfoundidException;

/ **

* Get all roles

* @Return role array

* /

Public role [] getroles () throws CantfoundIDException;

/ **

* Get the properties that users used as authority judgment

* @Param PROP permission attribute

* @Return property value

* /

Public Object getPermissionProp (String Prop);

}

======================= ibstractuser =========================== =========

Package org.fswan.Permission; import java.util.hashmap;

Import java.util.properties;

Import Org.fswan.Identity;

Import org.fswan.workflow.exception.IdentityMappingerror;

/ **

*

* Some things that implement the class constructs of AbstractUser

* Initialization Variables Description, Name, Group, ID, PROP, ROLE, PROPMAP

* /

Public Class AbstractUser IMPLEMENTS User

{

/ **

* Description

* /

Protected string description;

/ **

* Name

* /

Protected string name;

/ **

* Identification of the group

* /

Protected Identity [] Group;

/ **

* User ID

* /

Protected Identity ID;

/ **

* Attributes

* /

Protected Properties Prop;

/ **

* Character

* /

Protected Identity [] role;

/ **

* Permissions attribute storage location

* /

Protected hashmap propMap;

/ * (non-javadoc)

* @see org.fswan.Permission.user # getdescription ()

* /

Public string getdescription ()

{

Return description;

}

/ * (non-javadoc)

* @see org.fswan.Permission.user # getGroups ()

* /

Public group [] getGroups ()

{

Group [] groups = new group [group.Length];

For (int i = 0; i

{

Try

{

Groups [i] = (group) group [i] .newinstance ();

} catch (IdentityMAppinger E)

{

E.PrintStackTrace ();

}

}

Return Groups;

}

/ * (non-javadoc)

* @see org.fswan.Permission.user # getId ()

* /

Public Identity GetId ()

{

Return ID;

}

/ * (non-javadoc)

* @see org.fswan.Permission.user # getname ()

* /

Public string getName ()

{

Return Name;

}

/ * (non-javadoc)

* @see org.fswan.Permission.user # getproperties ()

* /

Public property getProperties ()

{

Return Prop;

}

/ * (non-javadoc)

* @see org.fswan.Permission.user # getroles ()

* /

Public role [] getroles ()

{

Role [] roles = new role [role.length];

For (int i = 0; i

{

Try

{

Roles [i] = (role) Role [i] .newinstance ();

} catch (IdentityMappinger E) {

E.PrintStackTrace ();

}

}

Return Roles;

}

Public String Tostring ()

{

String retstr = id.getidname ();

Retstr = ":" Name;

Retstr = " Description " / N ";

Retstr = "Group:";

Group [] groups = this.getGroups ();

IF (groups! = null)

{

For (int i = 0; i

{

IF (Groups [i]! = null)

Retstr = groups [i] .GetId (). getidName () "/ t";

}

}

Properties P = getProperties ();

Object [] obj = p.keyset (). Toarray ();

For (int i = 0; i

{

RetStr = Obj [i] ":" p.getProperty (obj [i] .tostring ()) "/ n";

}

Return Retstr;

}

/ * (non-javadoc)

* @see org.fswan.Permission.user # getMissionProp (java.lang.string)

* /

Public Object getPermissionProp (String Prop)

{

Return PropMap.get (Prop);

}

}

============================== UserImpl.java ================= ==========

Package org.fswan.Permission;

Import java.util.arraylist;

Import java.util.properties;

Import javax.xml.parsers.documentBuilderFactory;

Import Org.fswan.Identity;

Import Org.fswan.IdentityImpl;

Import org.fswan.implementIndIndIndity;

Import Org.fswan.ResourcesLib;

Import org.fswan.workflow.exception.IdentityMappingerror;

Import org.w3c.dom.document;

Import Org.w3c.dom.Element;

Import org.w3c.dom.nodeelist;

Public Class XMLUser Extends AbstractUser Implements ImplementIdentity

{

/ *** XML definition user's label

* /

Public static final string user = "user";

Public Object NewInstance (Identity ID)

{

ArrayList Sources = ResourceLib.getxmlResource ();

For (int i = 0; i

{

Try

{

Document Doc = DocumentBuilderFactory.newInstance (). NewDocumentBuilder (). Parse (Sources.get (i) .tostring ());

Nodelist nl = doc.getElementsBytagname (user);

For (int J = 0; j

{

Element Tempel = (Element) nl.Item (j);

String idstr = Tempel.getaTribute ("ID");

IF (idStr! = null&&! idstr.equals ("))

{

IF (idStr.equals (id.getidname ())))

{

THIS.ID = New IdentityImpl (Identity.Switch, Identity.xmluser, IDSTR);

Nodelist Tempnl = Tempel.GetElementsBytagname ("Name");

Name = tempnl.Item (0) .GetchildNodes (). Item (0) .GetnodeValue ();

Tempnl = Tempel.getElementsBytagname ("description");

Description = tempnl.item (0) .GetIldNodes (). Item (0) .GetnodeValue ();

Tempnl = Tempel.GtelementsBytagname ("ParentGroup");

Identity [] groups = new identity [tempnl.getLength ()];

For (int g = 0; Igroup

{

ELEMENT TEMPEL2 = (ELEMENT) TEMPNL.ITEM (IGroup);

String subType = Tempel.getaTribute ("subtype");

IF (Subtype == Null || Subtype.equals (")) Subtype = Identity.xmlGroup;

Groups [iGroup] = new identityImpl (Identity.Group, Subtype, Tempel2.GetaTRibute ("ID"));

}

THIS.GROUP = groups;

Tempnl = Tempel.GtelementsBytagname ("role");

Identity [] roles = new identity [tempnl.getLength ()];

For (int Irole = 0; Irole

{

Element Tempel2 = (Element) tempnl.item (Irole); string subtype = Tempel.getaTRibute ("subtype");

IF (Subtype == Null || Subtype.equals (")) Subtype = Identity.xmlrole;

Roles [Irole] = New IdentityIMPL (Identity.Role, Subtype, Tempel2.GetaTRibute ("ID"));

}

THIS.ROLE = Roles;

THIS.PROP = New property ();

Tempnl = Tempel.GtelementsBytagname ("property");

IF (TempnL! = NULL)

For (int K = 0; K

{

ELEMENT TEMPELEMENT = (Element) TEMPNL.Item (K);

System.out.println (Templement.getaTRibute ("name");

THIS.Prop.SetProperty ("Name"), Templement.getaTribute ("Value");

}

Return this;

}

}

}

} catch (Exception E)

{

E.PrintStackTrace ();

}

}

Return NULL;

}

Public static void main (string [] args)

{

Try

{

ResourceLib.AddResource ("D: //workflows//Workspace//Workflow//Workflow.xml");

User u = (user) New IdentityImpl (Identity.user, Identity.xmluser, "U01"). NewInstance ();

System.out.println (U);

} catch (IdentityMAppinger E)

{

E.PrintStackTrace ();

}

}

}

==================================================================================================================================================================

swan

Fang Zhiwen

==================================================

User Name

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

New Post(0)