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.PermissionReference; 25 import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl; 26 import org.alfresco.service.cmr.security.AccessStatus; 27 import org.alfresco.service.namespace.NamespacePrefixResolver; 28 import org.alfresco.service.namespace.QName; 29 import org.dom4j.Attribute; 30 import org.dom4j.Element; 31 32 37 public class Permission extends AbstractPermission implements XMLModelInitialisable 38 { 39 41 private static final String GRANTED_TO_GROUP = "grantedToGroup"; 42 43 private static final String GTG_NAME = "permissionGroup"; 44 45 private static final String GTG_TYPE = "type"; 46 47 private Set <PermissionReference> grantedToGroups = new HashSet <PermissionReference>(); 48 49 private static final String DENY = "deny"; 50 51 private static final String ALLOW = "allow"; 52 53 private static final String DEFAULT_PERMISSION = "defaultPermission"; 54 55 private static final String EXPOSE = "expose"; 56 57 private static final String REQUIRES_TYPE = "requiresType"; 58 59 private AccessStatus defaultPermission; 60 61 private boolean isExposed; 62 63 private boolean requiresType; 64 65 public Permission(QName typeQName) 66 { 67 super(typeQName); 68 } 69 70 public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) 71 { 72 super.initialise(element, nspr, permissionModel); 73 74 Attribute att = element.attribute(EXPOSE); 75 if (att != null) 76 { 77 isExposed = Boolean.parseBoolean(att.getStringValue()); 78 } 79 else 80 { 81 isExposed = true; 82 } 83 84 att = element.attribute(REQUIRES_TYPE); 85 if (att != null) 86 { 87 requiresType = Boolean.parseBoolean(att.getStringValue()); 88 } 89 else 90 { 91 requiresType = true; 92 } 93 94 Attribute defaultPermissionAttribute = element.attribute(DEFAULT_PERMISSION); 95 if(defaultPermissionAttribute != null) 96 { 97 if(defaultPermissionAttribute.getStringValue().equalsIgnoreCase(ALLOW)) 98 { 99 defaultPermission = AccessStatus.ALLOWED; 100 } 101 else if(defaultPermissionAttribute.getStringValue().equalsIgnoreCase(DENY)) 102 { 103 defaultPermission = AccessStatus.DENIED; 104 } 105 else 106 { 107 throw new PermissionModelException("The default permission must be deny or allow"); 108 } 109 } 110 else 111 { 112 defaultPermission = AccessStatus.DENIED; 113 } 114 115 for (Iterator gtgit = element.elementIterator(GRANTED_TO_GROUP); gtgit.hasNext(); ) 116 { 117 QName qName; 118 Element grantedToGroupsElement = (Element) gtgit.next(); 119 Attribute typeAttribute = grantedToGroupsElement.attribute(GTG_TYPE); 120 if (typeAttribute != null) 121 { 122 qName = QName.createQName(typeAttribute.getStringValue(), nspr); 123 } 124 else 125 { 126 qName = getTypeQName(); 127 } 128 129 String grantedName = grantedToGroupsElement.attributeValue(GTG_NAME); 130 131 grantedToGroups.add(new PermissionReferenceImpl(qName, grantedName)); 132 } 133 } 134 135 public AccessStatus getDefaultPermission() 136 { 137 return defaultPermission; 138 } 139 140 public Set <PermissionReference> getGrantedToGroups() 141 { 142 return Collections.unmodifiableSet(grantedToGroups); 143 } 144 145 public boolean isExposed() 146 { 147 return isExposed; 148 } 149 150 public boolean isTypeRequired() 151 { 152 return requiresType; 153 } 154 } 155 | Popular Tags |