for (GrantAndPermission gp : acl.getGrantAndPermissions()) { Permission perm = gp.getPermission(); GranteeInterface grantee = gp.getGrantee(); if (perm.equals(Permission.PERMISSION_READ)) { if (isUserIdInGrantee(grantee, userId)) {
/** * Revokes the permissions of a grantee by removing the grantee from the ACL. * * @param grantee * the grantee to remove from this ACL. */ public void revokeAllPermissions(GranteeInterface grantee) { List<GrantAndPermission> grantsToRemove = new ArrayList<GrantAndPermission>(); for (GrantAndPermission gap: grants) { if (gap.getGrantee().equals(grantee)) { grantsToRemove.add(gap); } } grants.removeAll(grantsToRemove); }
/** * Revokes the permissions of a grantee by removing the grantee from the ACL. * * @param grantee * the grantee to remove from this ACL. */ public void revokeAllPermissions(GranteeInterface grantee) { List<GrantAndPermission> grantsToRemove = new ArrayList<GrantAndPermission>(); for (GrantAndPermission gap: grants) { if (gap.getGrantee().equals(grantee)) { grantsToRemove.add(gap); } } grants.removeAll(grantsToRemove); }
public int compare(Object o1, Object o2) { GrantAndPermission g1 = (GrantAndPermission) o1; GrantAndPermission g2 = (GrantAndPermission) o2; return g1.getGrantee().getIdentifier().compareToIgnoreCase( g2.getGrantee().getIdentifier()); } });
public GranteeInterface getGrantee(int index) { GrantAndPermission originalGAP = (GrantAndPermission) currentGrantees.get(index); Object updatedGrantee = super.getValueAt(index, 0); if (updatedGrantee instanceof GroupGrantee) { // We can return this as-is, because GroupGrantees are actually stored in the table. return (GroupGrantee) updatedGrantee; } else { // Non-group Grantees are stored as Strings in the table, so update the original's ID. originalGAP.getGrantee().setIdentifier((String) updatedGrantee); return originalGAP.getGrantee(); } }
public int compare(Object o1, Object o2) { GrantAndPermission g1 = (GrantAndPermission) o1; GrantAndPermission g2 = (GrantAndPermission) o2; return g1.getGrantee().getIdentifier().compareToIgnoreCase( g2.getGrantee().getIdentifier()); } });
public GranteeInterface getGrantee(int index) { GrantAndPermission originalGAP = (GrantAndPermission) currentGrantees.get(index); Object updatedGrantee = super.getValueAt(index, 0); if (updatedGrantee instanceof GroupGrantee) { // We can return this as-is, because GroupGrantees are actually stored in the table. return (GroupGrantee) updatedGrantee; } else { // Non-group Grantees are stored as Strings in the table, so update the original's ID. originalGAP.getGrantee().setIdentifier((String) updatedGrantee); return originalGAP.getGrantee(); } }
/** * @param grantee * the grantee to whom the permission will apply * @return list of permissions assigned to the given grantee in this ACL */ public List<Permission> getPermissionsForGrantee(GranteeInterface grantee) { List<Permission> permissions = new ArrayList<Permission>(); for (GrantAndPermission gap: grants) { if (gap.getGrantee().equals(grantee)) { permissions.add(gap.getPermission()); } } return permissions; }
/** * @param grantee * the grantee to whom the permission will apply * @return list of permissions assigned to the given grantee in this ACL */ public List<Permission> getPermissionsForGrantee(GranteeInterface grantee) { List<Permission> permissions = new ArrayList<Permission>(); for (GrantAndPermission gap: grants) { if (gap.getGrantee().equals(grantee)) { permissions.add(gap.getPermission()); } } return permissions; }
public boolean equals(Object obj) { return (obj instanceof GrantAndPermission && this.getGrantee().equals(((GrantAndPermission)obj).getGrantee()) && this.getPermission().equals(((GrantAndPermission)obj).getPermission()) ); }
public boolean equals(Object obj) { return (obj instanceof GrantAndPermission && this.getGrantee().equals(((GrantAndPermission)obj).getGrantee()) && this.getPermission().equals(((GrantAndPermission)obj).getPermission()) ); }
/** * @param permission Permission * @return list of grantees assigned the given permission in this ACL */ public List<GranteeInterface> getGranteesWithPermission(Permission permission) { List<GranteeInterface> grantees = new ArrayList<GranteeInterface>(); for (GrantAndPermission gap: grants) { if (gap.getPermission().equals(permission)) { grantees.add(gap.getGrantee()); } } return grantees; }
/** * @param permission Permission * @return list of grantees assigned the given permission in this ACL */ public List<GranteeInterface> getGranteesWithPermission(Permission permission) { List<GranteeInterface> grantees = new ArrayList<GranteeInterface>(); for (GrantAndPermission gap: grants) { if (gap.getPermission().equals(permission)) { grantees.add(gap.getGrantee()); } } return grantees; }
/** * Adds a set of grantee/permission pairs to the ACL, where each item in the set is a * {@link GrantAndPermission} object. * * @param grantAndPermissions * the grant and permission combinations to add. */ public void grantAllPermissions(GrantAndPermission[] grantAndPermissions) { for(GrantAndPermission gap : grantAndPermissions) { grantPermission(gap.getGrantee(), gap.getPermission()); } }
/** * Adds a set of grantee/permission pairs to the ACL, where each item in the set is a * {@link GrantAndPermission} object. * * @param grantAndPermissions * the grant and permission combinations to add. */ public void grantAllPermissions(GrantAndPermission[] grantAndPermissions) { for(GrantAndPermission gap : grantAndPermissions) { grantPermission(gap.getGrantee(), gap.getPermission()); } }
public static String getAclDescription(AccessControlList acl) { if (acl == null) { return ACL_UNKNOWN_DESCRIPTION; } for (GrantAndPermission gap: acl.getGrantAndPermissions()) { if (GroupGrantee.ALL_USERS.equals(gap.getGrantee()) && Permission.PERMISSION_READ.equals(gap.getPermission())) { return ACL_PUBLIC_DESCRIPTION; } } if (AccessControlList.REST_CANNED_PUBLIC_READ.equals(acl)) { return ACL_PUBLIC_DESCRIPTION; } return ACL_PRIVATE_DESCRIPTION; }
public static String getAclDescription(AccessControlList acl) { if (acl == null) { return ACL_UNKNOWN_DESCRIPTION; } for (GrantAndPermission gap: acl.getGrantAndPermissions()) { if (GroupGrantee.ALL_USERS.equals(gap.getGrantee()) && Permission.PERMISSION_READ.equals(gap.getPermission())) { return ACL_PUBLIC_DESCRIPTION; } } if (AccessControlList.REST_CANNED_PUBLIC_READ.equals(acl)) { return ACL_PUBLIC_DESCRIPTION; } return ACL_PRIVATE_DESCRIPTION; }
public XMLBuilder toXMLBuilder() throws ParserConfigurationException, FactoryConfigurationError, TransformerException { XMLBuilder builder = XMLBuilder.create("BucketLoggingStatus") .attr("xmlns", Constants.XML_NAMESPACE); if (isLoggingEnabled()) { XMLBuilder enabledBuilder = builder.elem("LoggingEnabled") .elem("TargetBucket").text(getTargetBucketName()).up() .elem("TargetPrefix").text(getLogfilePrefix()).up(); if (targetGrantsList.size() > 0) { Iterator<GrantAndPermission> targetGrantsIter = targetGrantsList.iterator(); XMLBuilder grantsBuilder = enabledBuilder.elem("TargetGrants"); while (targetGrantsIter.hasNext()) { GrantAndPermission gap = targetGrantsIter.next(); grantsBuilder.elem("Grant") .importXMLBuilder(gap.getGrantee().toXMLBuilder()) .elem("Permission").text(gap.getPermission().toString()); } } } return builder; } }
public XMLBuilder toXMLBuilder() throws ServiceException, ParserConfigurationException, FactoryConfigurationError, TransformerException { if (owner == null) { throw new ServiceException("Invalid AccessControlList: missing an owner"); } if (owner.getId() == null || "".equals(owner.getId())) { throw new ServiceException("Invalid AccessControlList: missing owner ID"); } String ownerDisplayName = owner.getDisplayName() == null ? "" : owner.getDisplayName(); XMLBuilder builder = XMLBuilder.create("AccessControlPolicy") .attr("xmlns", Constants.XML_NAMESPACE) .elem("Owner") .elem("ID").text(owner.getId()).up() .elem("DisplayName").text(ownerDisplayName).up() .up(); XMLBuilder accessControlList = builder.elem("AccessControlList"); for (GrantAndPermission gap: grants) { GranteeInterface grantee = gap.getGrantee(); Permission permission = gap.getPermission(); accessControlList .elem("Grant") .importXMLBuilder(grantee.toXMLBuilder()) .elem("Permission").text(permission.toString()); } return builder; }
@Override public XMLBuilder toXMLBuilder() throws ServiceException, ParserConfigurationException, FactoryConfigurationError, TransformerException { XMLBuilder builder = XMLBuilder.create("AccessControlList"); // Owner if (owner != null) { XMLBuilder ownerBuilder = builder.elem("Owner"); ownerBuilder.elem("ID").text(owner.getId()).up(); if (owner.getDisplayName() != null) { ownerBuilder.elem("Name").text(owner.getDisplayName()); } } XMLBuilder accessControlList = builder.elem("Entries"); for (GrantAndPermission gap: grants) { GranteeInterface grantee = gap.getGrantee(); Permission permission = gap.getPermission(); accessControlList .elem("Entry") .importXMLBuilder(grantee.toXMLBuilder()) .elem("Permission").text(permission.toString()); } return builder; }