1 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 34 public class ModelPermissionEntry implements PermissionEntry, XMLModelInitialisable 35 { 36 38 private static final String PERMISSION_REFERENCE = "permissionReference"; 39 40 private static final String RECIPIENT = "recipient"; 41 42 private static final String ACCESS = "access"; 43 44 private static final String DENY = "deny"; 45 46 private static final String ALLOW = "allow"; 47 48 private static final String TYPE = "type"; 49 50 private static final String NAME = "name"; 51 52 54 private String 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 getAuthority() 74 { 75 return getRecipient(); 76 } 77 78 public String 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 name = permissionReferenceElement.attributeValue(NAME); 140 permissionReference = new PermissionReferenceImpl(typeQName, name); 141 } 142 } 143 | Popular Tags |