LOGGER.log(Level.WARNING, "Either entityUrl [ " + entityUrl
+ " ] is unavailable or No ACE found in the ACL. WSLog [ "
+ acl.getLogMessage() + " ] ");
continue;
}
SPDocument document = urlToDocMap.get(entityUrl);
if (document == null) {
LOGGER.warning(
"No document found in urlToDocMap map for the entityUrl [ "
+ entityUrl + " ], WSLog [ " + acl.getLogMessage() + " ] ");
continue;
}
LOGGER.log(Level.CONFIG, "WsLog [ " + acl.getLogMessage() + " ] ");
boolean allowAnonymousAccess = Boolean.parseBoolean(
acl.getAnonymousAccess());
if (allowAnonymousAccess) {
LOGGER.log(Level.INFO, "Document [ " + document.getUrl()
+ " ] is identified as Public Document");
document.setPublicDocument(allowAnonymousAccess);
continue;
}
boolean largeAcl = Boolean.parseBoolean(acl.getLargeAcl());
if (largeAcl) {
boolean inheritPermissions =
Boolean.parseBoolean(acl.getInheritPermissions());
if (inheritPermissions) {
String parentUrl = acl.getParentUrl();
// if parentUrl is null or empty then document will be processed
// as largeAcl document.
if (!Strings.isNullOrEmpty(parentUrl)) {
LOGGER.log(Level.INFO, "Document [ " + document.getUrl()
+ " ] is idenified as Large ACL but with inherit permissions, "
+ "with Parent URL as " + parentUrl);
List<SPDocument> childList =
reprocessDocs.get(parentUrl);
if (childList == null) {
childList = Lists.newArrayList();
}
childList.add(document);
reprocessDocs.put(parentUrl, childList);
continue ACL;
}
}
LOGGER.log(Level.INFO, "Document [ " + document.getUrl()
+ " ] needs to be reprocessed as Large ACL Document");
largeAclUrlsToReprocess.add(document.getUrl());
largeACLUrlToDocMap.put(document.getUrl(), document);
continue ACL;
}
Set<Principal> aclUsers = Sets.newHashSet();
Set<Principal> aclGroups = Sets.newHashSet();
Set<Principal> aclDenyUsers = Sets.newHashSet();
Set<Principal> aclDenyGroups = Sets.newHashSet();
document.setUniquePermissions(
!Boolean.parseBoolean(acl.getInheritPermissions()));
if (!Strings.isNullOrEmpty(acl.getParentUrl())) {
if (sharepointClientContext.isIncludedUrl(acl.getParentUrl())) {
document.setParentUrl(acl.getParentUrl());
document.setParentId(acl.getParentId());
} else {
if (document.isUniquePermissions()) {
document.setParentUrl(sharepointClientContext.getSiteURL());
document.setParentId(acl.getParentId());
} else {
LOGGER.log(Level.INFO, "Document [ " + document.getUrl()
+ " ] needs to be reprocessed as Parent Url ["
+ acl.getParentUrl() + "] is not included for Traversal");
docUrlsToReprocess.add(document.getUrl());
excludedParentUrlToDocMap.put(document.getUrl(), document);
continue ACL;
}
}
}
for (GssAce ace : allAces) {
// Handle Principal
GssPrincipal principal = ace.getPrincipal();
if (null == principal) {
LOGGER.log(Level.WARNING, "No Principal found in ace.");
continue;
}
if (null == principal.getType() || null == principal.getName()) {
LOGGER.log(Level.WARNING, "Either Principal Name [ "
+ principal.getName() + " ] or Principal Type [ "
+ principal.getType() + " ] is unavailable");
continue;
}
// Handle Permissions
GssSharepointPermission permissions = ace.getPermission();
if (null == permissions) {
LOGGER.log(Level.WARNING, "No permissions found for Principal [ "
+ principal.getName() + " ] ");
continue;
}
// Check to determine whether the object-type of the document is list
// list-item or site.
ObjectType objectType = ObjectType.ITEM;
if (document.getObjType().equals(SPConstants.SITE)) {
objectType = ObjectType.SITE_LANDING_PAGE;
} else if (null != document.getParentList()) {
if (document.getParentList().getPrimaryKey().equals(
Util.getOriginalDocId(document.getDocId(),
document.getFeedType()))) {
objectType = ObjectType.LIST;
}
}
final String principalName = getPrincipalName(principal);
String siteCollUrl = wsResult.getSiteCollectionUrl();
String[] deniedPermissions = permissions.getDeniedPermission();
if (null != deniedPermissions) {
Set<RoleType> deniedRoleTypes =
getRoleTypesFor(deniedPermissions, objectType);
if (deniedRoleTypes.size() > 0) {
LOGGER.fine("Denied Permission list "
+ Arrays.asList(permissions.getDeniedPermission())
+ " for the User " + principalName);
LOGGER.fine("Principal [" + principalName
+ "] Denied Role Types [ " + deniedRoleTypes + " ]");
// Pass denied permissions only if Peeker or Reader role is denied.
if (deniedRoleTypes.contains(RoleType.PEEKER)
|| deniedRoleTypes.contains(RoleType.READER)) {
if (supportsDenyAcls) {
LOGGER.fine("Processing Deny permissions"
+ " for Principal ["+ principalName + "]");
processPrincipal(principal, aclDenyUsers, aclDenyGroups,
principalName, siteCollUrl, memberships, webState);
} else {
// Skipping ACL as denied ACLs are not supported as per
// Traversal Context.
LOGGER.warning("Skipping ACL as Deny permissions are detected"
+ "for Document [" + entityUrl + "] for Principal ["
+ principalName + " ] when Supports Deny ACL ["
+ supportsDenyAcls + "].");
continue ACL;
}
}
}
}
LOGGER.fine("Permission list "
+ Arrays.asList(permissions.getAllowedPermissions())
+ " for the User " + principalName);
Set<RoleType> allowedRoleTypes =
getRoleTypesFor(permissions.getAllowedPermissions(), objectType);
if (!allowedRoleTypes.isEmpty()) {
LOGGER.fine("Principal [ "+ principalName
+ " ] Allowed Role Types [ "+ allowedRoleTypes + " ]");
// Pass allowed permissions only if role other than Peeker is allowed.
if (allowedRoleTypes.contains(RoleType.READER)
|| allowedRoleTypes.contains(RoleType.WRITER)
|| allowedRoleTypes.contains(RoleType.OWNER)) {
processPrincipal(principal, aclUsers, aclGroups,
principalName, siteCollUrl, memberships, webState);
}
}
}
document.setAclUsers(aclUsers);
document.setAclGroups(aclGroups);
document.setAclDenyUsers(aclDenyUsers);
document.setAclDenyGroups(aclDenyGroups);
}
if (!reprocessDocs.isEmpty()) {
for (String parentUrl : reprocessDocs.keySet()) {
LOGGER.fine("Processing Parent URL [ "+ parentUrl + " ] ");
SPDocument parent = new SPDocument(parentUrl, parentUrl,
Calendar.getInstance(), ActionType.ADD);
fetchAclForSPDocument(parentUrl, parent, webState);
List<SPDocument> childList = reprocessDocs.get(parentUrl);
if (childList != null) {
for(SPDocument child : childList) {
copyAcls(parent, child);
}
}
}
}
if (!largeAclUrlsToReprocess.isEmpty()) {
for (String largeACLUrl : largeAclUrlsToReprocess) {
SPDocument documentToPass = largeACLUrlToDocMap.get(largeACLUrl);
if (documentToPass != null) {
fetchAclForSPDocument(largeACLUrl, documentToPass, webState);
}
}
}