1 17 package org.alfresco.repo.security.permissions.impl.model; 18 19 import java.util.Collections ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 import org.alfresco.repo.security.permissions.impl.AbstractPermissionReference; 25 import org.alfresco.repo.security.permissions.impl.RequiredPermission; 26 import org.alfresco.service.namespace.NamespacePrefixResolver; 27 import org.alfresco.service.namespace.QName; 28 import org.dom4j.Attribute; 29 import org.dom4j.Element; 30 31 36 public abstract class AbstractPermission extends AbstractPermissionReference implements XMLModelInitialisable 37 { 38 39 40 private static final String NAME = "name"; 41 42 private static final String REQUIRED_PERMISSION = "requiredPermission"; 43 44 private static final String RP_NAME = "name"; 45 46 private static final String RP_TYPE = "type"; 47 48 private static final String RP_ON = "on"; 49 50 private static final String RP_IMPLIES = "implies"; 51 52 private static final String NODE_ENTRY = "node"; 53 54 private static final String PARENT_ENTRY = "parent"; 55 56 private static final String CHILDREN_ENTRY = "children"; 57 58 59 60 private String name; 61 62 private QName typeQName; 63 64 private Set <RequiredPermission> requiredPermissions = new HashSet <RequiredPermission>(); 65 66 public AbstractPermission(QName typeQName) 67 { 68 super(); 69 this.typeQName = typeQName; 70 } 71 72 public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) 73 { 74 name = element.attributeValue(NAME); 75 76 for (Iterator rpit = element.elementIterator(REQUIRED_PERMISSION); rpit.hasNext(); ) 77 { 78 QName qName; 79 Element requiredPermissionElement = (Element) rpit.next(); 80 Attribute typeAttribute = requiredPermissionElement.attribute(RP_TYPE); 81 if (typeAttribute != null) 82 { 83 qName = QName.createQName(typeAttribute.getStringValue(), nspr); 84 } 85 else 86 { 87 qName = typeQName; 88 } 89 90 String requiredName = requiredPermissionElement.attributeValue(RP_NAME); 91 92 RequiredPermission.On on; 93 String onString = requiredPermissionElement.attributeValue(RP_ON); 94 if (onString.equalsIgnoreCase(NODE_ENTRY)) 95 { 96 on = RequiredPermission.On.NODE; 97 } 98 else if (onString.equalsIgnoreCase(PARENT_ENTRY)) 99 { 100 on = RequiredPermission.On.PARENT; 101 } 102 else if (onString.equalsIgnoreCase(CHILDREN_ENTRY)) 103 { 104 on = RequiredPermission.On.CHILDREN; 105 } 106 else 107 { 108 throw new PermissionModelException("Required permission must specify parent or node for the on attribute."); 109 } 110 111 boolean implies = false; 112 Attribute impliesAttribute = requiredPermissionElement.attribute(RP_IMPLIES); 113 if (impliesAttribute != null) 114 { 115 implies = Boolean.parseBoolean(impliesAttribute.getStringValue()); 116 } 117 118 RequiredPermission rq = new RequiredPermission(qName, requiredName, on, implies); 119 120 requiredPermissions.add(rq); 121 } 122 } 123 124 public final String getName() 125 { 126 return name; 127 } 128 129 public final Set <RequiredPermission> getRequiredPermissions() 130 { 131 return Collections.unmodifiableSet(requiredPermissions); 132 } 133 134 public final QName getTypeQName() 135 { 136 return typeQName; 137 } 138 139 public final QName getQName() 140 { 141 return getTypeQName(); 142 } 143 } 144 | Popular Tags |