public void endElement(String uri, String name, String qName) { if (qName.equals("TargetBucket")) { this.targetBucket = currentOrNull(currentText); } else if (qName.equals("TargetPrefix")) { this.targetPrefix = currentOrNull(currentText); } else if (qName.equals("Grantee")) { if ("AmazonCustomerByEmail".equals(currentGranteeType)) { currentGrantee = new EmailAddressGrantee(currentId); } else if ("CanonicalUser".equals(currentGranteeType)) { currentGrantee = new CanonicalUserGrantee(currentId, currentDisplayName); } else if ("Group".equals(currentGranteeType)) { currentGrantee = new GroupGrantee(URI.create(currentId)); } } else if (qName.equals("Grant")) { targetGrants.add(new Grant(currentGrantee, currentPermission)); } else if (qName.equals("ID") || qName.equals("EmailAddress") || qName.equals("URI")) { currentId = currentOrNull(currentText); } else if (qName.equals("DisplayName")) { currentDisplayName = currentOrNull(currentText); } else if (qName.equals("Permission")) { currentPermission = currentOrNull(currentText); } currentText.setLength(0); }
/** * Revoke a permission for the given grantee, if this specific permission was granted. * * Note that you must be very explicit about the permissions you revoke, you cannot revoke * partial permissions and expect this class to determine the implied remaining permissions. For * example, if you revoke the {@link Permission#READ} permission from a grantee with * {@link Permission#FULL_CONTROL} access, <strong>the revocation will do nothing</strong> and * the grantee will retain full access. To change the access settings for this grantee, you must * first remove the {@link Permission#FULL_CONTROL} permission the add back the * {@link Permission#READ} permission. * * @param grantee * @param permission */ public AccessControlList revokePermission(Grantee grantee, String permission) { for (Iterator<Grant> it = grants.iterator(); it.hasNext();) { Grant grant = it.next(); if (grant.getGrantee().equals(grantee) && grant.getPermission().equals(permission)) { it.remove(); } } return this; }
ImmutableSet.<Grant> of(new Grant(new EmailAddressGrantee(TEST_ACL_EMAIL), FULL_CONTROL)));
ImmutableSet.<Grant> of(new Grant(new EmailAddressGrantee(StubS3AsyncClient.TEST_ACL_EMAIL), Permission.FULL_CONTROL)));
"http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); grantBuilder.elem("Permission").text(grant.getPermission().toString());
"http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); grantBuilder.elem("Permission").text(grant.getPermission().toString());
"http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); grantBuilder.elem("Permission").text(grant.getPermission().toString());
"http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); grantBuilder.elem("Permission").text(grant.getPermission().toString());
"http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); grantBuilder.elem("Permission").text(grant.getPermission().toString());
public void endElement(String uri, String name, String qName) { if (qName.equals("TargetBucket")) { this.targetBucket = currentOrNull(currentText); } else if (qName.equals("TargetPrefix")) { this.targetPrefix = currentOrNull(currentText); } else if (qName.equals("Grantee")) { if ("AmazonCustomerByEmail".equals(currentGranteeType)) { currentGrantee = new EmailAddressGrantee(currentId); } else if ("CanonicalUser".equals(currentGranteeType)) { currentGrantee = new CanonicalUserGrantee(currentId, currentDisplayName); } else if ("Group".equals(currentGranteeType)) { currentGrantee = new GroupGrantee(URI.create(currentId)); } } else if (qName.equals("Grant")) { targetGrants.add(new Grant(currentGrantee, currentPermission)); } else if (qName.equals("ID") || qName.equals("EmailAddress") || qName.equals("URI")) { currentId = currentOrNull(currentText); } else if (qName.equals("DisplayName")) { currentDisplayName = currentOrNull(currentText); } else if (qName.equals("Permission")) { currentPermission = currentOrNull(currentText); } currentText.setLength(0); }
protected XMLBuilder generateBuilder(BucketLogging bucketLogging) throws ParserConfigurationException, FactoryConfigurationError { XMLBuilder rootBuilder = XMLBuilder.create("BucketLoggingStatus") .attr("xmlns", S3Constants.S3_REST_API_XML_NAMESPACE).e("LoggingEnabled"); rootBuilder.e("TargetBucket").t(bucketLogging.getTargetBucket()); rootBuilder.e("TargetPrefix").t(bucketLogging.getTargetPrefix()); XMLBuilder grantsBuilder = rootBuilder.elem("TargetGrants"); for (Grant grant : bucketLogging.getTargetGrants()) { XMLBuilder grantBuilder = grantsBuilder.elem("Grant"); XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); } grantBuilder.elem("Permission").text(grant.getPermission().toString()); } return grantsBuilder; }
protected XMLBuilder generateBuilder(BucketLogging bucketLogging) throws ParserConfigurationException, FactoryConfigurationError { XMLBuilder rootBuilder = XMLBuilder.create("BucketLoggingStatus") .attr("xmlns", S3Constants.S3_REST_API_XML_NAMESPACE).e("LoggingEnabled"); rootBuilder.e("TargetBucket").t(bucketLogging.getTargetBucket()); rootBuilder.e("TargetPrefix").t(bucketLogging.getTargetPrefix()); XMLBuilder grantsBuilder = rootBuilder.elem("TargetGrants"); for (Grant grant : bucketLogging.getTargetGrants()) { XMLBuilder grantBuilder = grantsBuilder.elem("Grant"); XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); } grantBuilder.elem("Permission").text(grant.getPermission().toString()); } return grantsBuilder; }
public void endElement(String uri, String name, String qName) { if (qName.equals("TargetBucket")) { this.targetBucket = currentOrNull(currentText); } else if (qName.equals("TargetPrefix")) { this.targetPrefix = currentOrNull(currentText); } else if (qName.equals("Grantee")) { if ("AmazonCustomerByEmail".equals(currentGranteeType)) { currentGrantee = new EmailAddressGrantee(currentId); } else if ("CanonicalUser".equals(currentGranteeType)) { currentGrantee = new CanonicalUserGrantee(currentId, currentDisplayName); } else if ("Group".equals(currentGranteeType)) { currentGrantee = new GroupGrantee(URI.create(currentId)); } } else if (qName.equals("Grant")) { targetGrants.add(new Grant(currentGrantee, currentPermission)); } else if (qName.equals("ID") || qName.equals("EmailAddress") || qName.equals("URI")) { currentId = currentOrNull(currentText); } else if (qName.equals("DisplayName")) { currentDisplayName = currentOrNull(currentText); } else if (qName.equals("Permission")) { currentPermission = currentOrNull(currentText); } currentText = new StringBuilder(); }
protected XMLBuilder generateBuilder(BucketLogging bucketLogging) throws ParserConfigurationException, FactoryConfigurationError { XMLBuilder rootBuilder = XMLBuilder.create("BucketLoggingStatus") .attr("xmlns", S3Constants.S3_REST_API_XML_NAMESPACE).e("LoggingEnabled"); rootBuilder.e("TargetBucket").t(bucketLogging.getTargetBucket()); rootBuilder.e("TargetPrefix").t(bucketLogging.getTargetPrefix()); XMLBuilder grantsBuilder = rootBuilder.elem("TargetGrants"); for (Grant grant : bucketLogging.getTargetGrants()) { XMLBuilder grantBuilder = grantsBuilder.elem("Grant"); XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); } grantBuilder.elem("Permission").text(grant.getPermission().toString()); } return grantsBuilder; }
public void endElement(String uri, String name, String qName) { if (qName.equals("TargetBucket")) { this.targetBucket = currentOrNull(currentText); } else if (qName.equals("TargetPrefix")) { this.targetPrefix = currentOrNull(currentText); } else if (qName.equals("Grantee")) { if ("AmazonCustomerByEmail".equals(currentGranteeType)) { currentGrantee = new EmailAddressGrantee(currentId); } else if ("CanonicalUser".equals(currentGranteeType)) { currentGrantee = new CanonicalUserGrantee(currentId, currentDisplayName); } else if ("Group".equals(currentGranteeType)) { currentGrantee = new GroupGrantee(URI.create(currentId)); } } else if (qName.equals("Grant")) { targetGrants.add(new Grant(currentGrantee, currentPermission)); } else if (qName.equals("ID") || qName.equals("EmailAddress") || qName.equals("URI")) { currentId = currentOrNull(currentText); } else if (qName.equals("DisplayName")) { currentDisplayName = currentOrNull(currentText); } else if (qName.equals("Permission")) { currentPermission = currentOrNull(currentText); } currentText.setLength(0); }
protected XMLBuilder generateBuilder(BucketLogging bucketLogging) throws ParserConfigurationException, FactoryConfigurationError { XMLBuilder rootBuilder = XMLBuilder.create("BucketLoggingStatus") .attr("xmlns", S3Constants.S3_REST_API_XML_NAMESPACE).e("LoggingEnabled"); rootBuilder.e("TargetBucket").t(bucketLogging.getTargetBucket()); rootBuilder.e("TargetPrefix").t(bucketLogging.getTargetPrefix()); XMLBuilder grantsBuilder = rootBuilder.elem("TargetGrants"); for (Grant grant : bucketLogging.getTargetGrants()) { XMLBuilder grantBuilder = grantsBuilder.elem("Grant"); XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); } grantBuilder.elem("Permission").text(grant.getPermission().toString()); } return grantsBuilder; }
/** * Revoke a permission for the given grantee, if this specific permission was granted. * * Note that you must be very explicit about the permissions you revoke, you cannot revoke * partial permissions and expect this class to determine the implied remaining permissions. For * example, if you revoke the {@link Permission#READ} permission from a grantee with * {@link Permission#FULL_CONTROL} access, <strong>the revocation will do nothing</strong> and * the grantee will retain full access. To change the access settings for this grantee, you must * first remove the {@link Permission#FULL_CONTROL} permission the add back the * {@link Permission#READ} permission. * * @param grantee * @param permission */ public AccessControlList revokePermission(Grantee grantee, String permission) { Collection<Grant> grantsForGrantee = findGrantsForGrantee(grantee.getIdentifier()); for (Grant grant : grantsForGrantee) { if (grant.getPermission().equals(permission)) { grants.remove(grant); } } return this; }
/** * Revoke a permission for the given grantee, if this specific permission was granted. * * Note that you must be very explicit about the permissions you revoke, you cannot revoke * partial permissions and expect this class to determine the implied remaining permissions. For * example, if you revoke the {@link Permission#READ} permission from a grantee with * {@link Permission#FULL_CONTROL} access, <strong>the revocation will do nothing</strong> and * the grantee will retain full access. To change the access settings for this grantee, you must * first remove the {@link Permission#FULL_CONTROL} permission the add back the * {@link Permission#READ} permission. * * @param grantee * @param permission */ public AccessControlList revokePermission(Grantee grantee, String permission) { for (Iterator<Grant> it = grants.iterator(); it.hasNext();) { Grant grant = it.next(); if (grant.getGrantee().equals(grantee) && grant.getPermission().equals(permission)) { it.remove(); } } return this; }
protected XMLBuilder generateBuilder(BucketLogging bucketLogging) throws ParserConfigurationException, FactoryConfigurationError { XMLBuilder rootBuilder = XMLBuilder.create("BucketLoggingStatus") .attr("xmlns", S3Constants.S3_REST_API_XML_NAMESPACE).e("LoggingEnabled"); rootBuilder.e("TargetBucket").t(bucketLogging.getTargetBucket()); rootBuilder.e("TargetPrefix").t(bucketLogging.getTargetPrefix()); XMLBuilder grantsBuilder = rootBuilder.elem("TargetGrants"); for (Grant grant : bucketLogging.getTargetGrants()) { XMLBuilder grantBuilder = grantsBuilder.elem("Grant"); XMLBuilder granteeBuilder = grantBuilder.elem("Grantee").attr("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); if (grant.getGrantee() instanceof GroupGrantee) { granteeBuilder.attr("xsi:type", "Group").elem("URI").text(grant.getGrantee().getIdentifier()); } else if (grant.getGrantee() instanceof CanonicalUserGrantee) { CanonicalUserGrantee grantee = (CanonicalUserGrantee) grant.getGrantee(); granteeBuilder.attr("xsi:type", "CanonicalUser").elem("ID").text(grantee.getIdentifier()).up(); if (grantee.getDisplayName() != null) { granteeBuilder.elem("DisplayName").text(grantee.getDisplayName()); } } else if (grant.getGrantee() instanceof EmailAddressGrantee) { granteeBuilder.attr("xsi:type", "AmazonCustomerByEmail").elem("EmailAddress") .text(grant.getGrantee().getIdentifier()); } grantBuilder.elem("Permission").text(grant.getPermission().toString()); } return grantsBuilder; }
public void run() { try { BucketLogging newLogging = getApi().getBucketLogging(bucketName); assert newLogging != null; AccessControlList acl = new AccessControlList(); for (Grant grant : newLogging.getTargetGrants()) { // TODO: add permission // checking features to // bucketlogging acl.addPermission(grant.getGrantee(), grant.getPermission()); } // EmailAddressGrantee is replaced by a CanonicalUserGrantee, so we cannot test by // email addr assertTrue(acl.hasPermission(TEST_ACL_ID, FULL_CONTROL), acl.toString()); assertEquals(logging.getTargetBucket(), newLogging.getTargetBucket()); assertEquals(logging.getTargetPrefix(), newLogging.getTargetPrefix()); } catch (Exception e) { Throwables.propagateIfPossible(e); } } });