KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > permissions > impl > model > ModelPermissionEntry


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.security.permissions.impl.model;
18
19 import org.alfresco.repo.security.permissions.PermissionEntry;
20 import org.alfresco.repo.security.permissions.PermissionReference;
21 import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl;
22 import org.alfresco.service.cmr.repository.NodeRef;
23 import org.alfresco.service.cmr.security.AccessStatus;
24 import org.alfresco.service.namespace.NamespacePrefixResolver;
25 import org.alfresco.service.namespace.QName;
26 import org.dom4j.Attribute;
27 import org.dom4j.Element;
28
29 /**
30  * Support to read and store the definion of a permission entry.
31  *
32  * @author andyh
33  */

34 public class ModelPermissionEntry implements PermissionEntry, XMLModelInitialisable
35 {
36     // XML Constants
37

38     private static final String JavaDoc PERMISSION_REFERENCE = "permissionReference";
39
40     private static final String JavaDoc RECIPIENT = "recipient";
41
42     private static final String JavaDoc ACCESS = "access";
43
44     private static final String JavaDoc DENY = "deny";
45
46     private static final String JavaDoc ALLOW = "allow";
47
48     private static final String JavaDoc TYPE = "type";
49     
50     private static final String JavaDoc NAME = "name";
51
52     // Instance variables
53

54     private String JavaDoc recipient;
55
56     private AccessStatus access;
57
58     private PermissionReference permissionReference;
59
60     private NodeRef nodeRef;
61
62     public ModelPermissionEntry(NodeRef nodeRef)
63     {
64         super();
65         this.nodeRef = nodeRef;
66     }
67
68     public PermissionReference getPermissionReference()
69     {
70         return permissionReference;
71     }
72
73     public String JavaDoc getAuthority()
74     {
75         return getRecipient();
76     }
77
78     public String JavaDoc getRecipient()
79     {
80         return recipient;
81     }
82
83     public NodeRef getNodeRef()
84     {
85         return nodeRef;
86     }
87
88     public boolean isDenied()
89     {
90         return access == AccessStatus.DENIED;
91     }
92
93     public boolean isAllowed()
94     {
95         return access == AccessStatus.ALLOWED;
96     }
97
98     public AccessStatus getAccessStatus()
99     {
100         return access;
101     }
102
103     public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
104     {
105         Attribute recipientAttribute = element.attribute(RECIPIENT);
106         if (recipientAttribute != null)
107         {
108             recipient = recipientAttribute.getStringValue();
109         }
110         else
111         {
112             recipient = null;
113         }
114
115         Attribute accessAttribute = element.attribute(ACCESS);
116         if (accessAttribute != null)
117         {
118             if (accessAttribute.getStringValue().equalsIgnoreCase(ALLOW))
119             {
120                 access = AccessStatus.ALLOWED;
121             }
122             else if (accessAttribute.getStringValue().equalsIgnoreCase(DENY))
123             {
124                 access = AccessStatus.DENIED;
125             }
126             else
127             {
128                 throw new PermissionModelException("The default permission must be deny or allow");
129             }
130         }
131         else
132         {
133             access = AccessStatus.DENIED;
134         }
135         
136         
137         Element permissionReferenceElement = element.element(PERMISSION_REFERENCE);
138         QName typeQName = QName.createQName(permissionReferenceElement.attributeValue(TYPE), nspr);
139         String JavaDoc name = permissionReferenceElement.attributeValue(NAME);
140         permissionReference = new PermissionReferenceImpl(typeQName, name);
141     }
142 }
143
Popular Tags