com.amazonaws.services.s3.model.Grant类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中com.amazonaws.services.s3.model.Grant类的一些代码示例,展示了Grant类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Grant类的具体详情如下:
包路径:com.amazonaws.services.s3.model.Grant
类名称:Grant

Grant介绍

[英]Specifies a grant, consisting of one grantee and one permission.
[中]指定授予,包括一个被授予者和一个权限。

代码示例

代码示例来源:origin: aws/aws-sdk-java

/**
 * 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());
  }
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * 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));
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * 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);
}

代码示例来源:origin: com.upplication/s3fs

/**
 * 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;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * 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);
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * 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());
    }
  }
}

代码示例来源:origin: com.amazonaws/aws-android-sdk-s3

/**
 * 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);
}

代码示例来源:origin: apache/incubator-druid

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;
}

代码示例来源:origin: awsdocs/aws-doc-sdk-examples

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);
  }
}

代码示例来源:origin: Nextdoor/bender

/**
 * 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);
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * 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));
}

代码示例来源:origin: awsdocs/aws-doc-sdk-examples

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);
  }
}

代码示例来源:origin: com.amazonaws/aws-android-sdk-s3

/**
 * 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));
}

代码示例来源:origin: aws/aws-sdk-java

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();
}

代码示例来源:origin: Nextdoor/bender

/**
 * 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));
}

代码示例来源:origin: Alluxio/alluxio

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)) {

代码示例来源:origin: org.apache.druid.extensions/druid-s3-extensions

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;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * 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());
  }
}

代码示例来源:origin: aws/aws-sdk-java

for (Grant grant : acl.getGrantsAsList()) {
  xml.start("Grant");
  convertToXml(grant.getGrantee(), xml);
  xml.start("Permission").value(grant.getPermission().toString()).end();
  xml.end();

代码示例来源:origin: aws-amplify/aws-sdk-android

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());

相关文章