From dc0b6d1a9d9a507e8ab38cbe08cc704a9567cbb7 Mon Sep 17 00:00:00 2001 From: Bruna Vuicik Mocelin Date: Thu, 26 Jun 2014 12:32:33 -0300 Subject: [PATCH] Add ACL items for GSA version 7.0 and higher --- src/com/mcplusa/google/feeder/GSAACLItem.java | 83 +++++++++++++++++++ .../google/feeder/GSAACLPrincipal.java | 53 ++++++++++++ .../mcplusa/google/feeder/GSAContentItem.java | 9 ++ src/com/mcplusa/google/feeder/GSAFeed.java | 37 +++++++++ .../feeder/enums/ACLCaseSensitivityType.java | 16 ++++ .../feeder/enums/ACLInheritanceType.java | 18 ++++ .../feeder/enums/ACLPrincipalAccess.java | 16 ++++ .../feeder/enums/ACLPrincipalScope.java | 16 ++++ 8 files changed, 248 insertions(+) create mode 100644 src/com/mcplusa/google/feeder/GSAACLItem.java create mode 100644 src/com/mcplusa/google/feeder/GSAACLPrincipal.java create mode 100644 src/com/mcplusa/google/feeder/enums/ACLCaseSensitivityType.java create mode 100644 src/com/mcplusa/google/feeder/enums/ACLInheritanceType.java create mode 100644 src/com/mcplusa/google/feeder/enums/ACLPrincipalAccess.java create mode 100644 src/com/mcplusa/google/feeder/enums/ACLPrincipalScope.java diff --git a/src/com/mcplusa/google/feeder/GSAACLItem.java b/src/com/mcplusa/google/feeder/GSAACLItem.java new file mode 100644 index 0000000..856061b --- /dev/null +++ b/src/com/mcplusa/google/feeder/GSAACLItem.java @@ -0,0 +1,83 @@ +package com.mcplusa.google.feeder; + +import com.mcplusa.google.feeder.enums.ACLCaseSensitivityType; +import com.mcplusa.google.feeder.enums.ACLInheritanceType; +import com.mcplusa.google.feeder.enums.ACLPrincipalAccess; +import com.mcplusa.google.feeder.enums.ACLPrincipalScope; +import java.util.ArrayList; +import java.util.List; + +public class GSAACLItem { + private String url; + private ACLInheritanceType inheritanceType; + private String inheritFrom; + private List principals; + + public GSAACLItem() { + this.principals = new ArrayList(); + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public ACLInheritanceType getInheritanceType() { + return inheritanceType; + } + + public void setInheritanceType(ACLInheritanceType inheritanceType) { + this.inheritanceType = inheritanceType; + } + + public String getInheritFrom() { + return inheritFrom; + } + + public void setInheritFrom(String inheritFrom) { + this.inheritFrom = inheritFrom; + } + + public List getPrincipals() { + return principals; + } + + public void addUserPrincipal(String username, ACLPrincipalAccess access) { + this.addUserPrincipal(username, access, + ACLCaseSensitivityType.ACL_PRINCIPAL_CASE_INSENSITIVE, + "Default"); + } + + public void addUserPrincipal(String username, ACLPrincipalAccess access, + ACLCaseSensitivityType caseSensitivity, String namespace) { + this.addPrincipal(username, access, caseSensitivity, + namespace, ACLPrincipalScope.ACL_PRINCIPAL_SCOPE_USER); + } + + public void addGroupPrincipal(String groupName, ACLPrincipalAccess access) { + this.addGroupPrincipal(groupName, access, + ACLCaseSensitivityType.ACL_PRINCIPAL_CASE_INSENSITIVE, + "Default"); + } + + public void addGroupPrincipal(String groupName, ACLPrincipalAccess access, + ACLCaseSensitivityType caseSensitivity, String namespace) { + this.addPrincipal(groupName, access, caseSensitivity, + namespace, ACLPrincipalScope.ACL_PRINCIPAL_SCOPE_GROUP); + } + + private void addPrincipal(String name, ACLPrincipalAccess access, + ACLCaseSensitivityType caseSensitivity, String namespace, + ACLPrincipalScope scope) { + GSAACLPrincipal principal = new GSAACLPrincipal(); + principal.setAccess(access); + principal.setCaseSensitivityType(caseSensitivity); + principal.setContent(name); + principal.setNamespace(namespace); + principal.setScope(scope); + this.principals.add(principal); + } +} diff --git a/src/com/mcplusa/google/feeder/GSAACLPrincipal.java b/src/com/mcplusa/google/feeder/GSAACLPrincipal.java new file mode 100644 index 0000000..303443a --- /dev/null +++ b/src/com/mcplusa/google/feeder/GSAACLPrincipal.java @@ -0,0 +1,53 @@ +package com.mcplusa.google.feeder; + +import com.mcplusa.google.feeder.enums.ACLCaseSensitivityType; +import com.mcplusa.google.feeder.enums.ACLPrincipalAccess; +import com.mcplusa.google.feeder.enums.ACLPrincipalScope; + +public class GSAACLPrincipal { + private String namespace; + private ACLCaseSensitivityType caseSensitivityType; + private ACLPrincipalScope scope; + private ACLPrincipalAccess access; + private String content; + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public ACLCaseSensitivityType getCaseSensitivityType() { + return caseSensitivityType; + } + + public void setCaseSensitivityType(ACLCaseSensitivityType caseSensitivityType) { + this.caseSensitivityType = caseSensitivityType; + } + + public ACLPrincipalScope getScope() { + return scope; + } + + public void setScope(ACLPrincipalScope scope) { + this.scope = scope; + } + + public ACLPrincipalAccess getAccess() { + return access; + } + + public void setAccess(ACLPrincipalAccess access) { + this.access = access; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/src/com/mcplusa/google/feeder/GSAContentItem.java b/src/com/mcplusa/google/feeder/GSAContentItem.java index 5c378c0..bc85c13 100644 --- a/src/com/mcplusa/google/feeder/GSAContentItem.java +++ b/src/com/mcplusa/google/feeder/GSAContentItem.java @@ -23,6 +23,7 @@ public class GSAContentItem { protected Date lastModified; protected ArrayList metaData; protected String authMethod = GSAAuthMethodTypes.AUTH_METHOD_NONE; + protected GSAACLItem acl; public GSAContentItem() { @@ -110,6 +111,14 @@ public void setAuthmethod(String newAuthMethod) { authMethod = newAuthMethod; } + + public void setAcl(GSAACLItem acl) { + this.acl = acl; + } + + public GSAACLItem getAcl() { + return this.acl; + } public void addMetaData(String name, String content) { diff --git a/src/com/mcplusa/google/feeder/GSAFeed.java b/src/com/mcplusa/google/feeder/GSAFeed.java index 625393c..1d300d2 100644 --- a/src/com/mcplusa/google/feeder/GSAFeed.java +++ b/src/com/mcplusa/google/feeder/GSAFeed.java @@ -158,6 +158,9 @@ public void AddRecord(GSAContentItem item) { } recordNode.setAttribute("authmethod", item.getAuthMethod()); + if (item.getAcl() != null) { + this.AddACL(item.getAcl(), recordNode, true); + } if (item.metaData.size() > 0) { Element metaData = doc.createElement("metadata"); GSAMetaDataItem metaItem; @@ -183,8 +186,42 @@ public void AddRecord(GSAContentItem item) { content.setTextContent(item.getContent()); recordNode.appendChild(content); } + groupNode.appendChild(recordNode); count++; } + + public void AddACL(GSAACLItem item) { + this.AddACL(item, groupNode, false); + } + + private void AddACL(GSAACLItem item, Node aclContainer, boolean aclInsideRecord) { + Element aclNode = doc.createElement("acl"); + if (!aclInsideRecord) { + aclNode.setAttribute("url", item.getUrl()); + } + + if (item.getInheritanceType() != null) { + aclNode.setAttribute("inheritance-type", item.getInheritanceType().getValue()); + } + + if (item.getInheritFrom() != null && item.getInheritFrom().trim().length() != 0) { + aclNode.setAttribute("inherit-from", item.getInheritFrom()); + } + + if (item.getPrincipals().size() > 0) { + for (GSAACLPrincipal principalItem : item.getPrincipals()) { + Element principal = doc.createElement("principal"); + principal.setAttribute("namespace", principalItem.getNamespace()); + principal.setAttribute("case-sensitivity-type", principalItem.getCaseSensitivityType().getValue()); + principal.setAttribute("scope", principalItem.getScope().getValue()); + principal.setAttribute("access", principalItem.getAccess().getValue()); + principal.appendChild(doc.createTextNode(principalItem.getContent())); + aclNode.appendChild(principal); + } + } + + aclContainer.appendChild(aclNode); + } } diff --git a/src/com/mcplusa/google/feeder/enums/ACLCaseSensitivityType.java b/src/com/mcplusa/google/feeder/enums/ACLCaseSensitivityType.java new file mode 100644 index 0000000..f7ba312 --- /dev/null +++ b/src/com/mcplusa/google/feeder/enums/ACLCaseSensitivityType.java @@ -0,0 +1,16 @@ +package com.mcplusa.google.feeder.enums; + +public enum ACLCaseSensitivityType { + ACL_PRINCIPAL_CASE_SENSITIVE("everything-case-sensitive"), + ACL_PRINCIPAL_CASE_INSENSITIVE("everything-case-insensitive"); + + private final String aclCaseSensitiveType; + + ACLCaseSensitivityType(String aclCaseSensitiveType) { + this.aclCaseSensitiveType = aclCaseSensitiveType; + } + + public String getValue() { + return this.aclCaseSensitiveType; + } +} diff --git a/src/com/mcplusa/google/feeder/enums/ACLInheritanceType.java b/src/com/mcplusa/google/feeder/enums/ACLInheritanceType.java new file mode 100644 index 0000000..b916b24 --- /dev/null +++ b/src/com/mcplusa/google/feeder/enums/ACLInheritanceType.java @@ -0,0 +1,18 @@ +package com.mcplusa.google.feeder.enums; + +public enum ACLInheritanceType { + ACL_INHERITANCE_TYPE_PARENT_OVERRIDES("parent-overrides"), + ACL_INHERITANCE_TYPE_CHILD_OVERRIDES("child-overrides"), + ACL_INHERITANCE_TYPE_AND_BOTH_PERMIT("and-both-permit"), + ACL_INHERITANCE_TYPE_LEAF_NODE("leaf-node"); + + private final String aclInheritanceType; + + ACLInheritanceType(String aclInheritanceType) { + this.aclInheritanceType = aclInheritanceType; + } + + public String getValue() { + return this.aclInheritanceType; + } +} \ No newline at end of file diff --git a/src/com/mcplusa/google/feeder/enums/ACLPrincipalAccess.java b/src/com/mcplusa/google/feeder/enums/ACLPrincipalAccess.java new file mode 100644 index 0000000..26fd281 --- /dev/null +++ b/src/com/mcplusa/google/feeder/enums/ACLPrincipalAccess.java @@ -0,0 +1,16 @@ +package com.mcplusa.google.feeder.enums; + +public enum ACLPrincipalAccess { + ACL_PRINCIPAL_ACCESS_PERMIT("permit"), + ACL_PRINCIPAL_ACCESS_DENY("deny"); + + private final String aclPrincipalAccess; + + ACLPrincipalAccess(String aclPrincipalAccess) { + this.aclPrincipalAccess = aclPrincipalAccess; + } + + public String getValue() { + return this.aclPrincipalAccess; + } +} diff --git a/src/com/mcplusa/google/feeder/enums/ACLPrincipalScope.java b/src/com/mcplusa/google/feeder/enums/ACLPrincipalScope.java new file mode 100644 index 0000000..c95c727 --- /dev/null +++ b/src/com/mcplusa/google/feeder/enums/ACLPrincipalScope.java @@ -0,0 +1,16 @@ +package com.mcplusa.google.feeder.enums; + +public enum ACLPrincipalScope { + ACL_PRINCIPAL_SCOPE_USER("user"), + ACL_PRINCIPAL_SCOPE_GROUP("group"); + + private final String aclPrincipalScope; + + ACLPrincipalScope(String aclPrincipalScope) { + this.aclPrincipalScope = aclPrincipalScope; + } + + public String getValue() { + return this.aclPrincipalScope; + } +}