@Override public String toString() { return "AccessControlList [owner=" + owner + ", grants=" + getGrantsAsList() + "]"; }
/** * Adds a grantee to the access control list (ACL) with the given permission. * If this access control list already * contains the grantee (i.e. the same grantee object) the permission for the * grantee will be updated. * * @param grantee * The grantee to whom the permission will apply. * @param permission * The permission to apply to the grantee. */ public void grantPermission(Grantee grantee, Permission permission) { getGrantsAsList().add(new Grant(grantee, permission)); }
/** * Revokes the permissions of a grantee by removing the grantee from the access control list (ACL). * * @param grantee * The grantee to remove from this ACL. */ public void revokeAllPermissions(Grantee grantee) { ArrayList<Grant> grantsToRemove = new ArrayList<Grant>(); List<Grant> existingGrants = getGrantsAsList(); for (Grant gap : existingGrants) { if (gap.getGrantee().equals(grantee)) { grantsToRemove.add(gap); } } grantList.removeAll(grantsToRemove); }
/** * Sets the access control headers for the request given. */ private static void addAclHeaders(Request<? extends AmazonWebServiceRequest> request, AccessControlList acl) { List<Grant> grants = acl.getGrantsAsList(); Map<Permission, Collection<Grantee>> grantsByPermission = new HashMap<Permission, Collection<Grantee>>(); for ( Grant grant : grants ) { if ( !grantsByPermission.containsKey(grant.getPermission()) ) { grantsByPermission.put(grant.getPermission(), new LinkedList<Grantee>()); } grantsByPermission.get(grant.getPermission()).add(grant.getGrantee()); } for ( Permission permission : Permission.values() ) { if ( grantsByPermission.containsKey(permission) ) { Collection<Grantee> grantees = grantsByPermission.get(permission); boolean seenOne = false; StringBuilder granteeString = new StringBuilder(); for ( Grantee grantee : grantees ) { if ( !seenOne ) seenOne = true; else granteeString.append(", "); granteeString.append(grantee.getTypeIdentifier()).append("=").append("\"") .append(grantee.getIdentifier()).append("\""); } request.addHeader(permission.getHeaderName(), granteeString.toString()); } } }
public static void getObjectAcl(String bucket_name, String object_key) { System.out.println("Retrieving ACL for object: " + object_key); System.out.println(" in bucket: " + bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try { AccessControlList acl = s3.getObjectAcl(bucket_name, object_key); List<Grant> grants = acl.getGrantsAsList(); for (Grant grant : grants) { System.out.format(" %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString()); } } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } }
public static void getBucketAcl(String bucket_name) { System.out.println("Retrieving ACL for bucket: " + bucket_name); final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try { AccessControlList acl = s3.getBucketAcl(bucket_name); List<Grant> grants = acl.getGrantsAsList(); for (Grant grant : grants) { System.out.format(" %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString()); } } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } }
for (Grant grant : acl.getGrantsAsList()) { Permission perm = grant.getPermission(); Grantee grantee = grant.getGrantee();
@Override public String toString() { return "AccessControlList [owner=" + owner + ", grants=" + getGrantsAsList() + "]"; }
private static void addGrantsIfNotNull(XmlWriter xml, AccessControlList accessControlList) { if (accessControlList == null) { return; } AclXmlFactory aclXmlFactory = new AclXmlFactory(); xml.start("AccessControlList"); for(Grant grant: accessControlList.getGrantsAsList()) { xml.start("Grant"); if (grant.getGrantee() != null) { aclXmlFactory.convertToXml(grant.getGrantee(), xml); } addIfNotNull(xml, "Permission", grant.getPermission()); xml.end(); } xml.end(); }
/** * Adds a grantee to the access control list (ACL) with the given permission. * If this access control list already * contains the grantee (i.e. the same grantee object) the permission for the * grantee will be updated. * * @param grantee The grantee to whom the permission will apply. * @param permission The permission to apply to the grantee. */ public void grantPermission(Grantee grantee, Permission permission) { getGrantsAsList().add(new Grant(grantee, permission)); }
/** * Revokes the permissions of a grantee by removing the grantee from the * access control list (ACL). * * @param grantee The grantee to remove from this ACL. */ public void revokeAllPermissions(Grantee grantee) { final ArrayList<Grant> grantsToRemove = new ArrayList<Grant>(); final List<Grant> existingGrants = getGrantsAsList(); for (final Grant gap : existingGrants) { if (gap.getGrantee().equals(grantee)) { grantsToRemove.add(gap); } } grantList.removeAll(grantsToRemove); }
for (Grant grant : acl.getGrantsAsList()) { xml.start("Grant"); convertToXml(grant.getGrantee(), xml);
@Override public String toString() { return "AccessControlList [owner=" + owner + ", grants=" + getGrantsAsList() + "]"; }
@Override public String toString() { return "AccessControlList [owner=" + owner + ", grants=" + getGrantsAsList() + "]"; }
/** * Adds a grantee to the access control list (ACL) with the given permission. * If this access control list already * contains the grantee (i.e. the same grantee object) the permission for the * grantee will be updated. * * @param grantee The grantee to whom the permission will apply. * @param permission The permission to apply to the grantee. */ public void grantPermission(Grantee grantee, Permission permission) { getGrantsAsList().add(new Grant(grantee, permission)); }
/** * Adds a grantee to the access control list (ACL) with the given permission. * If this access control list already * contains the grantee (i.e. the same grantee object) the permission for the * grantee will be updated. * * @param grantee * The grantee to whom the permission will apply. * @param permission * The permission to apply to the grantee. */ public void grantPermission(Grantee grantee, Permission permission) { getGrantsAsList().add(new Grant(grantee, permission)); }
/** * Revokes the permissions of a grantee by removing the grantee from the * access control list (ACL). * * @param grantee The grantee to remove from this ACL. */ public void revokeAllPermissions(Grantee grantee) { final ArrayList<Grant> grantsToRemove = new ArrayList<Grant>(); final List<Grant> existingGrants = getGrantsAsList(); for (final Grant gap : existingGrants) { if (gap.getGrantee().equals(grantee)) { grantsToRemove.add(gap); } } grantList.removeAll(grantsToRemove); }
/** * have almost one of the permission set in the parameter permissions * * @param permissions almost one * @return */ private boolean hasPermission(EnumSet<Permission> permissions) { for (Grant grant : acl.getGrantsAsList()) if (grant.getGrantee().getIdentifier().equals(owner.getId()) && permissions.contains(grant.getPermission())) return true; return false; }
private void verifyAcls(AccessControlList acl1, AccessControlList acl2) { Assert.assertEquals(acl1.getOwner(), acl2.getOwner()); for (Grant grant : acl1.getGrantsAsList()) { Assert.assertTrue(acl2.getGrantsAsList().contains(grant)); } for (Grant grant : acl2.getGrantsAsList()) { Assert.assertTrue(acl1.getGrantsAsList().contains(grant)); } }
private ObjectAcl syncAclFromS3Acl(AccessControlList s3Acl) { ObjectAcl syncAcl = new ObjectAcl(); syncAcl.setOwner(s3Acl.getOwner().getId()); for (Grant grant : s3Acl.getGrantsAsList()) { Grantee grantee = grant.getGrantee(); if (grantee instanceof GroupGrantee || grantee.getTypeIdentifier().equals(ACL_GROUP_TYPE)) syncAcl.addGroupGrant(grantee.getIdentifier(), grant.getPermission().toString()); else if (grantee instanceof CanonicalGrantee || grantee.getTypeIdentifier().equals(ACL_CANONICAL_USER_TYPE)) syncAcl.addUserGrant(grantee.getIdentifier(), grant.getPermission().toString()); } return syncAcl; }