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.JacksonXmlProperty;
import com.google.common.base.Objects;
/** Represent an Amazon AccessControlPolicy for a container or object. */
// CHECKSTYLE:OFF
@ -29,11 +30,27 @@ final class AccessControlPolicy {
@JacksonXmlProperty(localName = "AccessControlList")
AccessControlList aclList;
@Override
public String toString() {
return Objects.toStringHelper(AccessControlList.class)
.add("owner", owner)
.add("aclList", aclList)
.toString();
}
static final class Owner {
@JacksonXmlProperty(localName = "ID")
String id;
@JacksonXmlProperty(localName = "DisplayName")
String displayName;
@Override
public String toString() {
return Objects.toStringHelper(Owner.class)
.add("id", id)
.add("displayName", displayName)
.toString();
}
}
static final class AccessControlList {
@ -41,12 +58,27 @@ final class AccessControlPolicy {
@JacksonXmlElementWrapper(useWrapping = false)
Collection<Grant> grants;
@Override
public String toString() {
return Objects.toStringHelper(AccessControlList.class)
.add("grants", grants)
.toString();
}
static final class Grant {
@JacksonXmlProperty(localName = "Grantee")
Grantee grantee;
@JacksonXmlProperty(localName = "Permission")
String permission;
@Override
public String toString() {
return Objects.toStringHelper(Grant.class)
.add("grantee", grantee)
.add("permission", permission)
.toString();
}
static final class Grantee {
@JacksonXmlProperty(namespace = "xsi", localName = "type",
isAttribute = true)
@ -59,6 +91,17 @@ final class AccessControlPolicy {
String emailAddress;
@JacksonXmlProperty(localName = "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 allUsersRead = false;
for (AccessControlPolicy.AccessControlList.Grant grant :
policy.aclList.grants) {
if (grant.grantee.type.equals("CanonicalUser") &&
grant.grantee.id.equals(FAKE_OWNER_ID) &&
grant.permission.equals("FULL_CONTROL")) {
ownerFullControl = true;
} else if (grant.grantee.type.equals("Group") &&
grant.grantee.uri.equals("http://acs.amazonaws.com/" +
"groups/global/AllUsers") &&
grant.permission.equals("READ")) {
allUsersRead = true;
} else {
throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED);
if (policy.aclList != null) {
for (AccessControlPolicy.AccessControlList.Grant grant :
policy.aclList.grants) {
if (grant.grantee.type.equals("CanonicalUser") &&
grant.grantee.id.equals(FAKE_OWNER_ID) &&
grant.permission.equals("FULL_CONTROL")) {
ownerFullControl = true;
} else if (grant.grantee.type.equals("Group") &&
grant.grantee.uri.equals("http://acs.amazonaws.com/" +
"groups/global/AllUsers") &&
grant.permission.equals("READ")) {
allUsersRead = true;
} else {
throw new S3Exception(S3ErrorCode.NOT_IMPLEMENTED);
}
}
}