Search in sources :

Example 1 with TokenGenerator

use of org.wso2.carbon.apimgt.keymgt.token.TokenGenerator in project carbon-apimgt by wso2.

the class AbstractKeyValidationHandler method generateConsumerToken.

@Override
public boolean generateConsumerToken(TokenValidationContext validationContext) throws APIKeyMgtException {
    TokenGenerator generator = APIKeyMgtDataHolder.getTokenGenerator();
    try {
        String jwt = generator.generateToken(validationContext);
        validationContext.getValidationInfoDTO().setEndUserToken(jwt);
        return true;
    } catch (APIManagementException e) {
        log.error("Error occurred while generating JWT. ", e);
    }
    return false;
}
Also used : TokenGenerator(org.wso2.carbon.apimgt.keymgt.token.TokenGenerator) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 2 with TokenGenerator

use of org.wso2.carbon.apimgt.keymgt.token.TokenGenerator 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

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 ExtendedJWTConfigurationDto (org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto)1 JWTGenerator (org.wso2.carbon.apimgt.keymgt.token.JWTGenerator)1 TokenGenerator (org.wso2.carbon.apimgt.keymgt.token.TokenGenerator)1