Search in sources :

Example 16 with JWTConfigurationDto

use of org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto in project carbon-apimgt by wso2.

the class APIAuthenticationHandler method initOAuthParams.

protected void initOAuthParams() {
    setKeyValidator();
    APIManagerConfiguration config = getApiManagerConfiguration();
    String value = config.getFirstProperty(APIConstants.REMOVE_OAUTH_HEADERS_FROM_MESSAGE);
    if (value != null) {
        removeOAuthHeadersFromOutMessage = Boolean.parseBoolean(value);
    }
    JWTConfigurationDto jwtConfigurationDto = config.getJwtConfigurationDto();
    if (jwtConfigurationDto != null) {
        value = jwtConfigurationDto.getJwtHeader();
    }
    if (value != null) {
        setSecurityContextHeader(value);
    }
    isOauthParamsInitialized = true;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) JWTConfigurationDto(org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto)

Example 17 with JWTConfigurationDto

use of org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto in project carbon-apimgt by wso2.

the class ApiKeyAuthenticator method getContextHeader.

public String getContextHeader() {
    APIManagerConfiguration apimConf = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration();
    JWTConfigurationDto jwtConfigDto = apimConf.getJwtConfigurationDto();
    return jwtConfigDto.getJwtHeader();
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) JWTConfigurationDto(org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto)

Example 18 with JWTConfigurationDto

use of org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto in project carbon-apimgt by wso2.

the class APIKeyMgtDataHolder method isJwtGenerationEnabled.

public static boolean isJwtGenerationEnabled() {
    APIManagerConfiguration configuration = org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    if (configuration == null) {
        return false;
    }
    JWTConfigurationDto jwtConfigurationDto = configuration.getJwtConfigurationDto();
    return jwtConfigurationDto.isEnabled();
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ExtendedJWTConfigurationDto(org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto) JWTConfigurationDto(org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto)

Example 19 with JWTConfigurationDto

use of org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto in project carbon-apimgt by wso2.

the class APIKeyMgtDataHolder method initData.

public static void initData() {
    try {
        APIKeyMgtDataHolder.isKeyCacheEnabledKeyMgt = getInitValues(APIConstants.KEY_MANAGER_TOKEN_CACHE);
        APIManagerConfiguration configuration = org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
        if (configuration == null) {
            log.error("API Manager configuration is not initialized");
        } else {
            ExtendedJWTConfigurationDto jwtConfigurationDto = configuration.getJwtConfigurationDto();
            if (log.isDebugEnabled()) {
                log.debug("JWTGeneration enabled : " + jwtConfigurationDto.isEnabled());
            }
            if (jwtConfigurationDto.isEnabled()) {
                if (jwtConfigurationDto.getJwtGeneratorImplClass() == null) {
                    tokenGenerator = new JWTGenerator();
                } else {
                    try {
                        tokenGenerator = (TokenGenerator) APIUtil.getClassInstance(jwtConfigurationDto.getJwtGeneratorImplClass());
                    } catch (InstantiationException e) {
                        log.error("Error while instantiating class " + jwtConfigurationDto.getJwtGeneratorImplClass(), e);
                    } catch (IllegalAccessException e) {
                        log.error(e);
                    } catch (ClassNotFoundException e) {
                        log.error("Cannot find the class " + jwtConfigurationDto.getJwtGeneratorImplClass() + e);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Error occur while initializing API KeyMgt Data Holder.Default configuration will be used." + e.toString());
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ExtendedJWTConfigurationDto(org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto) JWTGenerator(org.wso2.carbon.apimgt.keymgt.token.JWTGenerator)

Aggregations

APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)15 ExtendedJWTConfigurationDto (org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto)13 SignedJWTInfo (org.wso2.carbon.apimgt.impl.jwt.SignedJWTInfo)11 SignedJWT (com.nimbusds.jwt.SignedJWT)10 Cache (javax.cache.Cache)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 JWTValidationInfo (org.wso2.carbon.apimgt.common.gateway.dto.JWTValidationInfo)10 APIKeyValidator (org.wso2.carbon.apimgt.gateway.handlers.security.APIKeyValidator)10 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 JWTValidationService (org.wso2.carbon.apimgt.impl.jwt.JWTValidationService)10 HashMap (java.util.HashMap)9 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9 APIKeyValidationInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO)9 MessageContext (org.apache.synapse.MessageContext)8 APISecurityException (org.wso2.carbon.apimgt.gateway.handlers.security.APISecurityException)8 TokenValidationContext (org.wso2.carbon.apimgt.keymgt.service.TokenValidationContext)8 JWTConfigurationDto (org.wso2.carbon.apimgt.common.gateway.dto.JWTConfigurationDto)6 OpenAPI (io.swagger.v3.oas.models.OpenAPI)4 OpenAPIParser (io.swagger.parser.OpenAPIParser)3