HADOOP-13417. Fix javac and checkstyle warnings in hadoop-auth package.
This commit is contained in:
parent
d9f73f1b7c
commit
5a5a724731
@ -20,14 +20,15 @@
|
|||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
import org.apache.http.auth.Credentials;
|
import org.apache.http.auth.Credentials;
|
||||||
|
import org.apache.http.client.CredentialsProvider;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.client.params.AuthPolicy;
|
|
||||||
import org.apache.http.entity.InputStreamEntity;
|
import org.apache.http.entity.InputStreamEntity;
|
||||||
import org.apache.http.impl.auth.SPNegoSchemeFactory;
|
import org.apache.http.impl.auth.SPNegoScheme;
|
||||||
import org.apache.http.impl.client.SystemDefaultHttpClient;
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.mortbay.jetty.Server;
|
import org.mortbay.jetty.Server;
|
||||||
import org.mortbay.jetty.servlet.Context;
|
import org.mortbay.jetty.servlet.Context;
|
||||||
@ -53,6 +54,7 @@
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
public class AuthenticatorTestCase {
|
public class AuthenticatorTestCase {
|
||||||
@ -241,22 +243,29 @@ protected void _testAuthentication(Authenticator authenticator, boolean doPost)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SystemDefaultHttpClient getHttpClient() {
|
private HttpClient getHttpClient() {
|
||||||
final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
|
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||||
httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
|
// Register auth schema
|
||||||
Credentials use_jaas_creds = new Credentials() {
|
builder.setDefaultAuthSchemeRegistry(
|
||||||
public String getPassword() {
|
s-> httpContext -> new SPNegoScheme(true, true)
|
||||||
return null;
|
);
|
||||||
}
|
|
||||||
|
|
||||||
public Principal getUserPrincipal() {
|
Credentials useJaasCreds = new Credentials() {
|
||||||
return null;
|
public String getPassword() {
|
||||||
}
|
return null;
|
||||||
};
|
}
|
||||||
|
public Principal getUserPrincipal() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
httpClient.getCredentialsProvider().setCredentials(
|
CredentialsProvider jaasCredentialProvider
|
||||||
AuthScope.ANY, use_jaas_creds);
|
= new BasicCredentialsProvider();
|
||||||
return httpClient;
|
jaasCredentialProvider.setCredentials(AuthScope.ANY, useJaasCreds);
|
||||||
|
// Set credential provider
|
||||||
|
builder.setDefaultCredentialsProvider(jaasCredentialProvider);
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doHttpClientRequest(HttpClient httpClient, HttpUriRequest request) throws Exception {
|
private void doHttpClientRequest(HttpClient httpClient, HttpUriRequest request) throws Exception {
|
||||||
@ -273,7 +282,7 @@ private void doHttpClientRequest(HttpClient httpClient, HttpUriRequest request)
|
|||||||
protected void _testAuthenticationHttpClient(Authenticator authenticator, boolean doPost) throws Exception {
|
protected void _testAuthenticationHttpClient(Authenticator authenticator, boolean doPost) throws Exception {
|
||||||
start();
|
start();
|
||||||
try {
|
try {
|
||||||
SystemDefaultHttpClient httpClient = getHttpClient();
|
HttpClient httpClient = getHttpClient();
|
||||||
doHttpClientRequest(httpClient, new HttpGet(getBaseURL()));
|
doHttpClientRequest(httpClient, new HttpGet(getBaseURL()));
|
||||||
|
|
||||||
// Always do a GET before POST to trigger the SPNego negotiation
|
// Always do a GET before POST to trigger the SPNego negotiation
|
||||||
|
Loading…
Reference in New Issue
Block a user