/** * Adds a set of grantee/permission pairs to the access control list (ACL), where each item in the * set is a {@link Grant} object. * * @param grantsVarArg * A collection of {@link Grant} objects */ public void grantAllPermissions(Grant... grantsVarArg) { for (Grant gap : grantsVarArg) { grantPermission(gap.getGrantee(), gap.getPermission()); } }
/** * 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); }
/** * transform com.amazonaws.services.s3.model.Grant to java.nio.file.attribute.PosixFilePermission * @see #toPosixFilePermission(Permission) * @param grants Set grants mandatory, must be not null * @return Set PosixFilePermission never null */ public Set<PosixFilePermission> toPosixFilePermissions(List<Grant> grants) { Set<PosixFilePermission> filePermissions = new HashSet<>(); for (Grant grant : grants) { filePermissions.addAll(toPosixFilePermission(grant.getPermission())); } return filePermissions; }
/** * 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); }
/** * 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()); } } }
/** * 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); }
static AccessControlList grantFullControlToBucketOwner(ServerSideEncryptingAmazonS3 s3Client, String bucket) { final AccessControlList acl = s3Client.getBucketAcl(bucket); acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl)); return acl; }
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); } }
/** * 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); }
/** * 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)); }
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); } }
/** * 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)); }
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)); }
short mode = (short) 0; for (Grant grant : acl.getGrantsAsList()) { Permission perm = grant.getPermission(); Grantee grantee = grant.getGrantee(); if (perm.equals(Permission.Read)) { if (isUserIdInGrantee(grantee, userId)) {
static AccessControlList grantFullControlToBucketOwner(ServerSideEncryptingAmazonS3 s3Client, String bucket) { final AccessControlList acl = s3Client.getBucketAcl(bucket); acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl)); return acl; }
/** * Adds a set of grantee/permission pairs to the access control list (ACL), * where each item in the set is a {@link Grant} object. * * @param grants A collection of {@link Grant} objects */ public void grantAllPermissions(Grant... grantsVarArg) { for (final Grant gap : grantsVarArg) { grantPermission(gap.getGrantee(), gap.getPermission()); } }
for (Grant grant : acl.getGrantsAsList()) { xml.start("Grant"); convertToXml(grant.getGrantee(), xml); xml.start("Permission").value(grant.getPermission().toString()).end(); xml.end();
final Map<Permission, Collection<Grantee>> grantsByPermission = new HashMap<Permission, Collection<Grantee>>(); for (final Grant grant : grants) { if (!grantsByPermission.containsKey(grant.getPermission())) { grantsByPermission.put(grant.getPermission(), new LinkedList<Grantee>()); grantsByPermission.get(grant.getPermission()).add(grant.getGrantee());