use of org.apache.http.auth.Credentials in project camel by apache.
the class PreemptiveAuthInterceptor method process.
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// If no auth scheme avaialble yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
if (authScheme != null) {
Credentials creds = credsProvider.getCredentials(AuthScope.ANY);
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}
use of org.apache.http.auth.Credentials in project hadoop by apache.
the class AuthenticatorTestCase method getHttpClient.
private HttpClient getHttpClient() {
HttpClientBuilder builder = HttpClientBuilder.create();
// Register auth schema
builder.setDefaultAuthSchemeRegistry(s -> httpContext -> new SPNegoScheme(true, true));
Credentials useJaasCreds = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
CredentialsProvider jaasCredentialProvider = new BasicCredentialsProvider();
jaasCredentialProvider.setCredentials(AuthScope.ANY, useJaasCreds);
// Set credential provider
builder.setDefaultCredentialsProvider(jaasCredentialProvider);
return builder.build();
}
use of org.apache.http.auth.Credentials in project OpenMEAP by OpenMEAP.
the class OmSlicCredentialsProvider method getCredentials.
@Override
public Credentials getCredentials(final AuthScope authScope) {
this.authScope = authScope;
if (memory.containsKey(authScope)) {
return memory.get(authScope);
}
synchronized (this) {
try {
launcher.launchLoginForm(this);
wait();
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
}
if (username == null || password == null) {
return super.getCredentials(authScope);
}
Credentials creds = new UsernamePasswordCredentials(username, password);
if (remember == null || remember == false) {
password = null;
username = null;
} else {
memory.put(authScope, creds);
}
return creds;
}
use of org.apache.http.auth.Credentials in project robovm by robovm.
the class RequestProxyAuthentication method process.
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
return;
}
// Obtain authentication state
AuthState authState = (AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE);
if (authState == null) {
return;
}
AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null) {
return;
}
Credentials creds = authState.getCredentials();
if (creds == null) {
this.log.debug("User credentials not available");
return;
}
if (authState.getAuthScope() != null || !authScheme.isConnectionBased()) {
try {
request.addHeader(authScheme.authenticate(creds, request));
} catch (AuthenticationException ex) {
if (this.log.isErrorEnabled()) {
this.log.error("Proxy authentication error: " + ex.getMessage());
}
}
}
}
use of org.apache.http.auth.Credentials in project robolectric by robolectric.
the class DefaultRequestDirector method updateAuthState.
private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) {
if (!authState.isValid()) {
return;
}
String hostname = host.getHostName();
int port = host.getPort();
if (port < 0) {
Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
port = scheme.getDefaultPort();
}
AuthScheme authScheme = authState.getAuthScheme();
AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName());
if (this.log.isDebugEnabled()) {
this.log.debug("Authentication scope: " + authScope);
}
Credentials creds = authState.getCredentials();
if (creds == null) {
creds = credsProvider.getCredentials(authScope);
if (this.log.isDebugEnabled()) {
if (creds != null) {
this.log.debug("Found credentials");
} else {
this.log.debug("Credentials not found");
}
}
} else {
if (authScheme.isComplete()) {
this.log.debug("Authentication failed");
creds = null;
}
}
authState.setAuthScope(authScope);
authState.setCredentials(creds);
}
Aggregations