use of org.wso2.carbon.identity.api.server.application.management.v1.Authenticator in project azure-sdk-for-java by Azure.
the class KeyVaultCredentials method applyCredentialsFilter.
@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
clientBuilder.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
HttpUrl url = chain.request().url();
Map<String, String> challengeMap = cache.getCachedChallenge(url);
if (challengeMap != null) {
// Get the bearer token
String credential = getAuthenticationCredentials(challengeMap);
Request newRequest = chain.request().newBuilder().header(AUTHENTICATE, BEARER_TOKEP_REFIX + credential).build();
return chain.proceed(newRequest);
} else {
// response
return chain.proceed(chain.request());
}
}
});
// Caches the challenge for failed request and re-send the request with
// access token.
clientBuilder.authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
// if challenge is not cached then extract and cache it
String authenticateHeader = response.header(WWW_AUTHENTICATE);
Map<String, String> challengeMap = extractChallenge(authenticateHeader, BEARER_TOKEP_REFIX);
// Cache the challenge
cache.addCachedChallenge(response.request().url(), challengeMap);
// Get the bearer token from the callback by providing the
// challenges
String credential = getAuthenticationCredentials(challengeMap);
if (credential == null) {
return null;
}
// be cached anywhere in our code.
return response.request().newBuilder().header(AUTHENTICATE, BEARER_TOKEP_REFIX + credential).build();
}
});
}
use of org.wso2.carbon.identity.api.server.application.management.v1.Authenticator in project couchbase-lite-android by couchbase.
the class CBLWebSocket method setupOkHttpClient.
// -------------------------------------------------------------------------
// private methods
// -------------------------------------------------------------------------
private OkHttpClient setupOkHttpClient() throws GeneralSecurityException {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// timeouts
builder.connectTimeout(10, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS);
// redirection
builder.followRedirects(true).followSslRedirects(true);
// authenticator
Authenticator authenticator = setupAuthenticator();
if (authenticator != null)
builder.authenticator(authenticator);
// trusted certificate (pinned certificate)
setupTrustedCertificate(builder);
return builder.build();
}
use of org.wso2.carbon.identity.api.server.application.management.v1.Authenticator in project couchbase-lite-android by couchbase.
the class CBLWebSocket method setupAuthenticator.
private Authenticator setupAuthenticator() {
if (options != null && options.containsKey(kC4ReplicatorOptionAuthentication)) {
Map<String, Object> auth = (Map<String, Object>) options.get(kC4ReplicatorOptionAuthentication);
if (auth != null) {
final String username = (String) auth.get(kC4ReplicatorAuthUserName);
final String password = (String) auth.get(kC4ReplicatorAuthPassword);
if (username != null && password != null) {
return new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
// http://www.ietf.org/rfc/rfc2617.txt
Log.v(TAG, "Authenticating for response: " + response);
// If failed 3 times, give up.
if (responseCount(response) >= 3)
return null;
List<Challenge> challenges = response.challenges();
Log.v(TAG, "Challenges: " + challenges);
if (challenges != null) {
for (Challenge challenge : challenges) {
if (challenge.scheme().equals("Basic")) {
String credential = Credentials.basic(username, password);
return response.request().newBuilder().header("Authorization", credential).build();
}
// NOTE: Not implemented Digest authentication
// https://github.com/rburgst/okhttp-digest
// else if(challenge.scheme().equals("Digest")){
// }
}
}
return null;
}
};
}
}
}
return null;
}
use of org.wso2.carbon.identity.api.server.application.management.v1.Authenticator in project hub-fortify-ssc-integration-service by blackducksoftware.
the class FortifyService method getHeader.
public static Builder getHeader(String userName, String password) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(Level.BASIC);
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.authenticator(new Authenticator() {
@Override
public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(userName, password);
if (credential.equals(response.request().header("Authorization"))) {
try {
FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
} catch (IntegrationException e) {
throw new IOException(e);
}
return null;
}
return response.request().newBuilder().header("Authorization", credential).build();
}
});
okBuilder.addInterceptor(logging);
return okBuilder;
}
use of org.wso2.carbon.identity.api.server.application.management.v1.Authenticator in project carbon-apimgt by wso2.
the class APIAuthenticationHandler method isAuthenticate.
/**
* Authenticates the given request using the authenticators which have been initialized.
*
* @param messageContext The message to be authenticated
* @return true if the authentication is successful (never returns false)
* @throws APISecurityException If an authentication failure or some other error occurs
*/
protected boolean isAuthenticate(MessageContext messageContext) throws APISecurityException, APIManagementException {
boolean authenticated = false;
AuthenticationResponse authenticationResponse;
List<AuthenticationResponse> authResponses = new ArrayList<>();
for (Authenticator authenticator : authenticators) {
authenticationResponse = authenticator.authenticate(messageContext);
if (authenticationResponse.isMandatoryAuthentication()) {
// Update authentication status only if the authentication is a mandatory one
authenticated = authenticationResponse.isAuthenticated();
}
if (!authenticationResponse.isAuthenticated()) {
authResponses.add(authenticationResponse);
}
if (!authenticationResponse.isContinueToNextAuthenticator()) {
break;
}
}
if (!authenticated) {
Pair<Integer, String> error = getError(authResponses);
throw new APISecurityException(error.getKey(), error.getValue());
}
return true;
}
Aggregations