Handle null AccessControlPolicy.aclList

Also add toString methods.
pull/139/merge
Andrew Gaul 2016-06-06 16:08:28 -07:00
rodzic 99d8e5e8d7
commit 72138e1278
2 zmienionych plików z 58 dodań i 13 usunięć

Wyświetl plik

@ -20,6 +20,7 @@ import java.util.Collection;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.google.common.base.Objects;
/** Represent an Amazon AccessControlPolicy for a container or object. */ /** Represent an Amazon AccessControlPolicy for a container or object. */
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
@ -29,11 +30,27 @@ final class AccessControlPolicy {
@JacksonXmlProperty(localName = "AccessControlList") @JacksonXmlProperty(localName = "AccessControlList")
AccessControlList aclList; AccessControlList aclList;
@Override
public String toString() {
return Objects.toStringHelper(AccessControlList.class)
.add("owner", owner)
.add("aclList", aclList)
.toString();
}
static final class Owner { static final class Owner {
@JacksonXmlProperty(localName = "ID") @JacksonXmlProperty(localName = "ID")
String id; String id;
@JacksonXmlProperty(localName = "DisplayName") @JacksonXmlProperty(localName = "DisplayName")
String displayName; String displayName;
@Override
public String toString() {
return Objects.toStringHelper(Owner.class)
.add("id", id)
.add("displayName", displayName)
.toString();
}
} }
static final class AccessControlList { static final class AccessControlList {
@ -41,12 +58,27 @@ final class AccessControlPolicy {
@JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlElementWrapper(useWrapping = false)
Collection<Grant> grants; Collection<Grant> grants;
@Override
public String toString() {
return Objects.toStringHelper(AccessControlList.class)
.add("grants", grants)
.toString();
}
static final class Grant { static final class Grant {
@JacksonXmlProperty(localName = "Grantee") @JacksonXmlProperty(localName = "Grantee")
Grantee grantee; Grantee grantee;
@JacksonXmlProperty(localName = "Permission") @JacksonXmlProperty(localName = "Permission")
String permission; String permission;
@Override
public String toString() {
return Objects.toStringHelper(Grant.class)
.add("grantee", grantee)
.add("permission", permission)
.toString();
}
static final class Grantee { static final class Grantee {
@JacksonXmlProperty(namespace = "xsi", localName = "type", @JacksonXmlProperty(namespace = "xsi", localName = "type",
isAttribute = true) isAttribute = true)
@ -59,6 +91,17 @@ final class AccessControlPolicy {
String emailAddress; String emailAddress;
@JacksonXmlProperty(localName = "URI") @JacksonXmlProperty(localName = "URI")
String uri; String uri;
@Override
public String toString() {
return Objects.toStringHelper(Grantee.class)
.add("type", type)
.add("id", id)
.add("displayName", displayName)
.add("emailAddress", emailAddress)
.add("uri", uri)
.toString();
}
} }
} }
} }

Wyświetl plik

@ -889,19 +889,21 @@ final class S3ProxyHandler extends AbstractHandler {
boolean ownerFullControl = false; boolean ownerFullControl = false;
boolean allUsersRead = false; boolean allUsersRead = false;
for (AccessControlPolicy.AccessControlList.Grant grant : if (policy.aclList != null) {
policy.aclList.grants) { for (AccessControlPolicy.AccessControlList.Grant grant :
if (grant.grantee.type.equals("CanonicalUser") && policy.aclList.grants) {
grant.grantee.id.equals(FAKE_OWNER_ID) && if (grant.grantee.type.equals("CanonicalUser") &&
grant.permission.equals("FULL_CONTROL")) { grant.grantee.id.equals(FAKE_OWNER_ID) &&
ownerFullControl = true; grant.permission.equals("FULL_CONTROL")) {
} else if (grant.grantee.type.equals("Group") && ownerFullControl = true;
grant.grantee.uri.equals("http://acs.amazonaws.com/" + } else if (grant.grantee.type.equals("Group") &&
"groups/global/AllUsers") && grant.grantee.uri.equals("http://acs.amazonaws.com/" +
grant.permission.equals("READ")) { "groups/global/AllUsers") &&
allUsersRead = true; grant.permission.equals("READ")) {
} else { allUsersRead = true;
throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED); } else {
throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED);
}
} }
} }