svn merge -c 1454517 Merging from trunk to branch-2 to fix HDFS-4577.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1454519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
50d493c89a
commit
95efc3d0fc
|
@ -2144,6 +2144,9 @@ Release 0.23.7 - UNRELEASED
|
|||
HDFS-4567. Webhdfs does not need a token for token operations (daryn via
|
||||
kihwal)
|
||||
|
||||
HDFS-4577. Webhdfs operations should declare if authentication is required
|
||||
(daryn via kihwal)
|
||||
|
||||
Release 0.23.6 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -344,10 +344,7 @@ public class WebHdfsFileSystem extends FileSystem
|
|||
// Skip adding delegation token for token operations because these
|
||||
// operations require authentication.
|
||||
Token<?> token = null;
|
||||
if (UserGroupInformation.isSecurityEnabled() &&
|
||||
op != GetOpParam.Op.GETDELEGATIONTOKEN &&
|
||||
op != PutOpParam.Op.RENEWDELEGATIONTOKEN &&
|
||||
op != PutOpParam.Op.CANCELDELEGATIONTOKEN) {
|
||||
if (UserGroupInformation.isSecurityEnabled() && !op.getRequireAuth()) {
|
||||
token = getDelegationToken();
|
||||
}
|
||||
if (token != null) {
|
||||
|
|
|
@ -38,6 +38,11 @@ public class DeleteOpParam extends HttpOpParam<DeleteOpParam.Op> {
|
|||
return HttpOpParam.Type.DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRequireAuth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDoOutput() {
|
||||
return false;
|
||||
|
|
|
@ -31,7 +31,7 @@ public class GetOpParam extends HttpOpParam<GetOpParam.Op> {
|
|||
GETFILECHECKSUM(true, HttpURLConnection.HTTP_OK),
|
||||
|
||||
GETHOMEDIRECTORY(false, HttpURLConnection.HTTP_OK),
|
||||
GETDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK),
|
||||
GETDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK, true),
|
||||
|
||||
/** GET_BLOCK_LOCATIONS is a private unstable op. */
|
||||
GET_BLOCK_LOCATIONS(false, HttpURLConnection.HTTP_OK),
|
||||
|
@ -40,10 +40,17 @@ public class GetOpParam extends HttpOpParam<GetOpParam.Op> {
|
|||
|
||||
final boolean redirect;
|
||||
final int expectedHttpResponseCode;
|
||||
final boolean requireAuth;
|
||||
|
||||
Op(final boolean redirect, final int expectedHttpResponseCode) {
|
||||
this(redirect, expectedHttpResponseCode, false);
|
||||
}
|
||||
|
||||
Op(final boolean redirect, final int expectedHttpResponseCode,
|
||||
final boolean requireAuth) {
|
||||
this.redirect = redirect;
|
||||
this.expectedHttpResponseCode = expectedHttpResponseCode;
|
||||
this.requireAuth = requireAuth;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +58,11 @@ public class GetOpParam extends HttpOpParam<GetOpParam.Op> {
|
|||
return HttpOpParam.Type.GET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRequireAuth() {
|
||||
return requireAuth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDoOutput() {
|
||||
return false;
|
||||
|
|
|
@ -43,6 +43,9 @@ public abstract class HttpOpParam<E extends Enum<E> & HttpOpParam.Op>
|
|||
/** @return the Http operation type. */
|
||||
public Type getType();
|
||||
|
||||
/** @return true if the operation cannot use a token */
|
||||
public boolean getRequireAuth();
|
||||
|
||||
/** @return true if the operation will do output. */
|
||||
public boolean getDoOutput();
|
||||
|
||||
|
@ -92,6 +95,11 @@ public abstract class HttpOpParam<E extends Enum<E> & HttpOpParam.Op>
|
|||
return op.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRequireAuth() {
|
||||
return op.getRequireAuth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDoOutput() {
|
||||
return op.getDoOutput();
|
||||
|
|
|
@ -42,6 +42,11 @@ public class PostOpParam extends HttpOpParam<PostOpParam.Op> {
|
|||
return Type.POST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRequireAuth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDoOutput() {
|
||||
return doOutputAndRedirect;
|
||||
|
|
|
@ -34,17 +34,24 @@ public class PutOpParam extends HttpOpParam<PutOpParam.Op> {
|
|||
SETPERMISSION(false, HttpURLConnection.HTTP_OK),
|
||||
SETTIMES(false, HttpURLConnection.HTTP_OK),
|
||||
|
||||
RENEWDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK),
|
||||
CANCELDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK),
|
||||
RENEWDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK, true),
|
||||
CANCELDELEGATIONTOKEN(false, HttpURLConnection.HTTP_OK, true),
|
||||
|
||||
NULL(false, HttpURLConnection.HTTP_NOT_IMPLEMENTED);
|
||||
|
||||
final boolean doOutputAndRedirect;
|
||||
final int expectedHttpResponseCode;
|
||||
final boolean requireAuth;
|
||||
|
||||
Op(final boolean doOutputAndRedirect, final int expectedHttpResponseCode) {
|
||||
this(doOutputAndRedirect, expectedHttpResponseCode, false);
|
||||
}
|
||||
|
||||
Op(final boolean doOutputAndRedirect, final int expectedHttpResponseCode,
|
||||
final boolean requireAuth) {
|
||||
this.doOutputAndRedirect = doOutputAndRedirect;
|
||||
this.expectedHttpResponseCode = expectedHttpResponseCode;
|
||||
this.requireAuth = requireAuth;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,6 +59,11 @@ public class PutOpParam extends HttpOpParam<PutOpParam.Op> {
|
|||
return HttpOpParam.Type.PUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRequireAuth() {
|
||||
return requireAuth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDoOutput() {
|
||||
return doOutputAndRedirect;
|
||||
|
|
|
@ -28,8 +28,10 @@ import java.net.URI;
|
|||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
||||
import org.apache.hadoop.hdfs.web.resources.DeleteOpParam;
|
||||
import org.apache.hadoop.hdfs.web.resources.GetOpParam;
|
||||
import org.apache.hadoop.hdfs.web.resources.HttpOpParam;
|
||||
import org.apache.hadoop.hdfs.web.resources.PostOpParam;
|
||||
import org.apache.hadoop.hdfs.web.resources.PutOpParam;
|
||||
import org.apache.hadoop.security.SecurityUtil;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
|
@ -166,4 +168,35 @@ public class TestWebHdfsTokens {
|
|||
verify(fs, never()).setDelegationToken(any(Token.class));
|
||||
verify(fs, never()).addRenewAction(fs);
|
||||
}
|
||||
|
||||
@Test(timeout=1000)
|
||||
public void testGetOpRequireAuth() {
|
||||
for (HttpOpParam.Op op : GetOpParam.Op.values()) {
|
||||
boolean expect = (op == GetOpParam.Op.GETDELEGATIONTOKEN);
|
||||
assertEquals(expect, op.getRequireAuth());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout=1000)
|
||||
public void testPutOpRequireAuth() {
|
||||
for (HttpOpParam.Op op : PutOpParam.Op.values()) {
|
||||
boolean expect = (op == PutOpParam.Op.RENEWDELEGATIONTOKEN ||
|
||||
op == PutOpParam.Op.CANCELDELEGATIONTOKEN);
|
||||
assertEquals(expect, op.getRequireAuth());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout=1000)
|
||||
public void testPostOpRequireAuth() {
|
||||
for (HttpOpParam.Op op : PostOpParam.Op.values()) {
|
||||
assertFalse(op.getRequireAuth());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout=1000)
|
||||
public void testDeleteOpRequireAuth() {
|
||||
for (HttpOpParam.Op op : DeleteOpParam.Op.values()) {
|
||||
assertFalse(op.getRequireAuth());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue