Search in sources :

Example 1 with MutualSSLAuthenticator

use of org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.MutualSSLAuthenticator in project carbon-apimgt by wso2.

the class APIAuthenticationHandler method initializeAuthenticators.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "LEST_LOST_EXCEPTION_STACK_TRACE", justification = "The exception needs to thrown for fault sequence invocation")
protected void initializeAuthenticators() {
    isAuthenticatorsInitialized = true;
    boolean isOAuthProtected = false;
    boolean isMutualSSLProtected = false;
    boolean isBasicAuthProtected = false;
    boolean isApiKeyProtected = false;
    boolean isMutualSSLMandatory = false;
    boolean isOAuthBasicAuthMandatory = false;
    // Set security conditions
    if (apiSecurity == null) {
        isOAuthProtected = true;
    } else {
        String[] apiSecurityLevels = apiSecurity.split(",");
        for (String apiSecurityLevel : apiSecurityLevels) {
            if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) {
                isOAuthProtected = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_MUTUAL_SSL)) {
                isMutualSSLProtected = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_BASIC_AUTH)) {
                isBasicAuthProtected = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY)) {
                isMutualSSLMandatory = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY)) {
                isOAuthBasicAuthMandatory = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase((APIConstants.API_SECURITY_API_KEY))) {
                isApiKeyProtected = true;
            }
        }
    }
    if (!isMutualSSLProtected && !isOAuthBasicAuthMandatory) {
        isOAuthBasicAuthMandatory = true;
    }
    if (!isBasicAuthProtected && !isOAuthProtected && !isMutualSSLMandatory && !isApiKeyProtected) {
        isMutualSSLMandatory = true;
    }
    // Set authenticators
    if (isMutualSSLProtected) {
        Authenticator authenticator = new MutualSSLAuthenticator(apiLevelPolicy, isMutualSSLMandatory, certificateInformation);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    if (isOAuthProtected) {
        Authenticator authenticator = new OAuthAuthenticator(authorizationHeader, isOAuthBasicAuthMandatory, removeOAuthHeadersFromOutMessage);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    if (isBasicAuthProtected) {
        Authenticator authenticator = new BasicAuthAuthenticator(authorizationHeader, isOAuthBasicAuthMandatory, apiLevelPolicy);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    if (isApiKeyProtected) {
        Authenticator authenticator = new ApiKeyAuthenticator(APIConstants.API_KEY_HEADER_QUERY_PARAM, apiLevelPolicy, isOAuthBasicAuthMandatory);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    Authenticator authenticator = new InternalAPIKeyAuthenticator(APIMgtGatewayConstants.INTERNAL_KEY);
    authenticator.init(synapseEnvironment);
    authenticators.add(authenticator);
    authenticators.sort(new Comparator<Authenticator>() {

        @Override
        public int compare(Authenticator o1, Authenticator o2) {
            return (o1.getPriority() - o2.getPriority());
        }
    });
}
Also used : InternalAPIKeyAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.InternalAPIKeyAuthenticator) MutualSSLAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.MutualSSLAuthenticator) BasicAuthAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.basicauth.BasicAuthAuthenticator) OAuthAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.oauth.OAuthAuthenticator) OAuthAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.oauth.OAuthAuthenticator) BasicAuthAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.basicauth.BasicAuthAuthenticator) InternalAPIKeyAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.InternalAPIKeyAuthenticator) MutualSSLAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.MutualSSLAuthenticator) ApiKeyAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.apikey.ApiKeyAuthenticator) ApiKeyAuthenticator(org.wso2.carbon.apimgt.gateway.handlers.security.apikey.ApiKeyAuthenticator)

Aggregations

ApiKeyAuthenticator (org.wso2.carbon.apimgt.gateway.handlers.security.apikey.ApiKeyAuthenticator)1 InternalAPIKeyAuthenticator (org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.InternalAPIKeyAuthenticator)1 MutualSSLAuthenticator (org.wso2.carbon.apimgt.gateway.handlers.security.authenticator.MutualSSLAuthenticator)1 BasicAuthAuthenticator (org.wso2.carbon.apimgt.gateway.handlers.security.basicauth.BasicAuthAuthenticator)1 OAuthAuthenticator (org.wso2.carbon.apimgt.gateway.handlers.security.oauth.OAuthAuthenticator)1