com.amazonaws.services.s3.model.Grant.getGrantee()方法的使用及代码示例

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

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

Grant.getGrantee介绍

[英]Gets the grantee being granted a permission by this grant.
[中]获取被此授予者授予的权限。

代码示例

代码示例来源: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: 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

/**
 * 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: 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: 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: 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: Alluxio/alluxio

for (Grant grant : acl.getGrantsAsList()) {
 Permission perm = grant.getPermission();
 Grantee grantee = grant.getGrantee();
 if (perm.equals(Permission.Read)) {
  if (isUserIdInGrantee(grantee, userId)) {

代码示例来源: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

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

/**
 * 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-amplify/aws-sdk-android

grantsByPermission.put(grant.getPermission(), new LinkedList<Grantee>());
grantsByPermission.get(grant.getPermission()).add(grant.getGrantee());

代码示例来源: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: 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: com.amazonaws/aws-android-sdk-s3

/**
 * 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: Nextdoor/bender

/**
 * 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: com.upplication/s3fs

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

代码示例来源:origin: tmobile/pacbot

/**
 * This method is to check whether s3 bucket has read/write/full control
 * 
 * @param grants
 * @param accessTypeToCheck
 * @return List<Permission>, if permissions found else empty
 */
private static List<Permission> checkAnyGrantHasOpenToReadOrWriteAccess(List<Grant> grants, String accessTypeToCheck) {
  List<Permission> permissions = new ArrayList<>();
  for (Grant grant : grants) {
    if ((PacmanRuleConstants.ANY_S3_AUTHENTICATED_USER_URI.equalsIgnoreCase(grant.getGrantee().getIdentifier()) || PacmanRuleConstants.ALL_S3_USER_URI
        .equalsIgnoreCase(grant.getGrantee().getIdentifier()))
        &&
        (grant.getPermission().toString().contains(accessTypeToCheck) || grant.getPermission().toString()
            .equalsIgnoreCase(PacmanRuleConstants.FULL_CONTROL))) {
      permissions.add(grant.getPermission());
    }
  }
  return permissions;
}

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

/**
 * 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: aws-amplify/aws-sdk-android

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

代码示例来源:origin: EMCECS/ecs-sync

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

相关文章