Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit dc0b6d1

Browse files
committed
Add ACL items for GSA version 7.0 and higher
1 parent 8f869d2 commit dc0b6d1

8 files changed

Lines changed: 248 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.mcplusa.google.feeder;
2+
3+
import com.mcplusa.google.feeder.enums.ACLCaseSensitivityType;
4+
import com.mcplusa.google.feeder.enums.ACLInheritanceType;
5+
import com.mcplusa.google.feeder.enums.ACLPrincipalAccess;
6+
import com.mcplusa.google.feeder.enums.ACLPrincipalScope;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public class GSAACLItem {
11+
private String url;
12+
private ACLInheritanceType inheritanceType;
13+
private String inheritFrom;
14+
private List<GSAACLPrincipal> principals;
15+
16+
public GSAACLItem() {
17+
this.principals = new ArrayList<GSAACLPrincipal>();
18+
}
19+
20+
public String getUrl() {
21+
return url;
22+
}
23+
24+
public void setUrl(String url) {
25+
this.url = url;
26+
}
27+
28+
public ACLInheritanceType getInheritanceType() {
29+
return inheritanceType;
30+
}
31+
32+
public void setInheritanceType(ACLInheritanceType inheritanceType) {
33+
this.inheritanceType = inheritanceType;
34+
}
35+
36+
public String getInheritFrom() {
37+
return inheritFrom;
38+
}
39+
40+
public void setInheritFrom(String inheritFrom) {
41+
this.inheritFrom = inheritFrom;
42+
}
43+
44+
public List<GSAACLPrincipal> getPrincipals() {
45+
return principals;
46+
}
47+
48+
public void addUserPrincipal(String username, ACLPrincipalAccess access) {
49+
this.addUserPrincipal(username, access,
50+
ACLCaseSensitivityType.ACL_PRINCIPAL_CASE_INSENSITIVE,
51+
"Default");
52+
}
53+
54+
public void addUserPrincipal(String username, ACLPrincipalAccess access,
55+
ACLCaseSensitivityType caseSensitivity, String namespace) {
56+
this.addPrincipal(username, access, caseSensitivity,
57+
namespace, ACLPrincipalScope.ACL_PRINCIPAL_SCOPE_USER);
58+
}
59+
60+
public void addGroupPrincipal(String groupName, ACLPrincipalAccess access) {
61+
this.addGroupPrincipal(groupName, access,
62+
ACLCaseSensitivityType.ACL_PRINCIPAL_CASE_INSENSITIVE,
63+
"Default");
64+
}
65+
66+
public void addGroupPrincipal(String groupName, ACLPrincipalAccess access,
67+
ACLCaseSensitivityType caseSensitivity, String namespace) {
68+
this.addPrincipal(groupName, access, caseSensitivity,
69+
namespace, ACLPrincipalScope.ACL_PRINCIPAL_SCOPE_GROUP);
70+
}
71+
72+
private void addPrincipal(String name, ACLPrincipalAccess access,
73+
ACLCaseSensitivityType caseSensitivity, String namespace,
74+
ACLPrincipalScope scope) {
75+
GSAACLPrincipal principal = new GSAACLPrincipal();
76+
principal.setAccess(access);
77+
principal.setCaseSensitivityType(caseSensitivity);
78+
principal.setContent(name);
79+
principal.setNamespace(namespace);
80+
principal.setScope(scope);
81+
this.principals.add(principal);
82+
}
83+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.mcplusa.google.feeder;
2+
3+
import com.mcplusa.google.feeder.enums.ACLCaseSensitivityType;
4+
import com.mcplusa.google.feeder.enums.ACLPrincipalAccess;
5+
import com.mcplusa.google.feeder.enums.ACLPrincipalScope;
6+
7+
public class GSAACLPrincipal {
8+
private String namespace;
9+
private ACLCaseSensitivityType caseSensitivityType;
10+
private ACLPrincipalScope scope;
11+
private ACLPrincipalAccess access;
12+
private String content;
13+
14+
public String getNamespace() {
15+
return namespace;
16+
}
17+
18+
public void setNamespace(String namespace) {
19+
this.namespace = namespace;
20+
}
21+
22+
public ACLCaseSensitivityType getCaseSensitivityType() {
23+
return caseSensitivityType;
24+
}
25+
26+
public void setCaseSensitivityType(ACLCaseSensitivityType caseSensitivityType) {
27+
this.caseSensitivityType = caseSensitivityType;
28+
}
29+
30+
public ACLPrincipalScope getScope() {
31+
return scope;
32+
}
33+
34+
public void setScope(ACLPrincipalScope scope) {
35+
this.scope = scope;
36+
}
37+
38+
public ACLPrincipalAccess getAccess() {
39+
return access;
40+
}
41+
42+
public void setAccess(ACLPrincipalAccess access) {
43+
this.access = access;
44+
}
45+
46+
public String getContent() {
47+
return content;
48+
}
49+
50+
public void setContent(String content) {
51+
this.content = content;
52+
}
53+
}

src/com/mcplusa/google/feeder/GSAContentItem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class GSAContentItem {
2323
protected Date lastModified;
2424
protected ArrayList metaData;
2525
protected String authMethod = GSAAuthMethodTypes.AUTH_METHOD_NONE;
26+
protected GSAACLItem acl;
2627

2728
public GSAContentItem()
2829
{
@@ -110,6 +111,14 @@ public void setAuthmethod(String newAuthMethod)
110111
{
111112
authMethod = newAuthMethod;
112113
}
114+
115+
public void setAcl(GSAACLItem acl) {
116+
this.acl = acl;
117+
}
118+
119+
public GSAACLItem getAcl() {
120+
return this.acl;
121+
}
113122

114123
public void addMetaData(String name, String content)
115124
{

src/com/mcplusa/google/feeder/GSAFeed.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ public void AddRecord(GSAContentItem item) {
158158
}
159159

160160
recordNode.setAttribute("authmethod", item.getAuthMethod());
161+
if (item.getAcl() != null) {
162+
this.AddACL(item.getAcl(), recordNode, true);
163+
}
161164
if (item.metaData.size() > 0) {
162165
Element metaData = doc.createElement("metadata");
163166
GSAMetaDataItem metaItem;
@@ -183,8 +186,42 @@ public void AddRecord(GSAContentItem item) {
183186
content.setTextContent(item.getContent());
184187
recordNode.appendChild(content);
185188
}
189+
186190
groupNode.appendChild(recordNode);
187191
count++;
188192

189193
}
194+
195+
public void AddACL(GSAACLItem item) {
196+
this.AddACL(item, groupNode, false);
197+
}
198+
199+
private void AddACL(GSAACLItem item, Node aclContainer, boolean aclInsideRecord) {
200+
Element aclNode = doc.createElement("acl");
201+
if (!aclInsideRecord) {
202+
aclNode.setAttribute("url", item.getUrl());
203+
}
204+
205+
if (item.getInheritanceType() != null) {
206+
aclNode.setAttribute("inheritance-type", item.getInheritanceType().getValue());
207+
}
208+
209+
if (item.getInheritFrom() != null && item.getInheritFrom().trim().length() != 0) {
210+
aclNode.setAttribute("inherit-from", item.getInheritFrom());
211+
}
212+
213+
if (item.getPrincipals().size() > 0) {
214+
for (GSAACLPrincipal principalItem : item.getPrincipals()) {
215+
Element principal = doc.createElement("principal");
216+
principal.setAttribute("namespace", principalItem.getNamespace());
217+
principal.setAttribute("case-sensitivity-type", principalItem.getCaseSensitivityType().getValue());
218+
principal.setAttribute("scope", principalItem.getScope().getValue());
219+
principal.setAttribute("access", principalItem.getAccess().getValue());
220+
principal.appendChild(doc.createTextNode(principalItem.getContent()));
221+
aclNode.appendChild(principal);
222+
}
223+
}
224+
225+
aclContainer.appendChild(aclNode);
226+
}
190227
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mcplusa.google.feeder.enums;
2+
3+
public enum ACLCaseSensitivityType {
4+
ACL_PRINCIPAL_CASE_SENSITIVE("everything-case-sensitive"),
5+
ACL_PRINCIPAL_CASE_INSENSITIVE("everything-case-insensitive");
6+
7+
private final String aclCaseSensitiveType;
8+
9+
ACLCaseSensitivityType(String aclCaseSensitiveType) {
10+
this.aclCaseSensitiveType = aclCaseSensitiveType;
11+
}
12+
13+
public String getValue() {
14+
return this.aclCaseSensitiveType;
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.mcplusa.google.feeder.enums;
2+
3+
public enum ACLInheritanceType {
4+
ACL_INHERITANCE_TYPE_PARENT_OVERRIDES("parent-overrides"),
5+
ACL_INHERITANCE_TYPE_CHILD_OVERRIDES("child-overrides"),
6+
ACL_INHERITANCE_TYPE_AND_BOTH_PERMIT("and-both-permit"),
7+
ACL_INHERITANCE_TYPE_LEAF_NODE("leaf-node");
8+
9+
private final String aclInheritanceType;
10+
11+
ACLInheritanceType(String aclInheritanceType) {
12+
this.aclInheritanceType = aclInheritanceType;
13+
}
14+
15+
public String getValue() {
16+
return this.aclInheritanceType;
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mcplusa.google.feeder.enums;
2+
3+
public enum ACLPrincipalAccess {
4+
ACL_PRINCIPAL_ACCESS_PERMIT("permit"),
5+
ACL_PRINCIPAL_ACCESS_DENY("deny");
6+
7+
private final String aclPrincipalAccess;
8+
9+
ACLPrincipalAccess(String aclPrincipalAccess) {
10+
this.aclPrincipalAccess = aclPrincipalAccess;
11+
}
12+
13+
public String getValue() {
14+
return this.aclPrincipalAccess;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mcplusa.google.feeder.enums;
2+
3+
public enum ACLPrincipalScope {
4+
ACL_PRINCIPAL_SCOPE_USER("user"),
5+
ACL_PRINCIPAL_SCOPE_GROUP("group");
6+
7+
private final String aclPrincipalScope;
8+
9+
ACLPrincipalScope(String aclPrincipalScope) {
10+
this.aclPrincipalScope = aclPrincipalScope;
11+
}
12+
13+
public String getValue() {
14+
return this.aclPrincipalScope;
15+
}
16+
}

0 commit comments

Comments
 (0)