/** * 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()); } } }
/** * Returns an XML fragment representing the specified Grantee. * * @param grantee * The grantee to convert to an XML representation that can be * sent to Amazon S3 as part of a request. * @param xml * The XmlWriter to which to concatenate this node to. * * @return The given XmlWriter containing the specified grantee. * * @throws SdkClientException * If the specified grantee type isn't recognized. */ protected XmlWriter convertToXml(Grantee grantee, XmlWriter xml) throws SdkClientException { if (grantee instanceof CanonicalGrantee) { return convertToXml((CanonicalGrantee)grantee, xml); } else if (grantee instanceof EmailAddressGrantee) { return convertToXml((EmailAddressGrantee)grantee, xml); } else if (grantee instanceof GroupGrantee) { return convertToXml((GroupGrantee)grantee, xml); } else { throw new SdkClientException("Unknown Grantee type: " + grantee.getClass().getName()); } }