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;
}
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());
}
}
Aggregations