use of org.wso2.carbon.apimgt.common.gateway.dto.TokenIssuerDto in project carbon-apimgt by wso2.
the class KeyManagerHolder method getJWTValidator.
private static JWTValidator getJWTValidator(KeyManagerConfiguration keyManagerConfiguration, String jwtValidatorImplementation) throws APIManagementException {
Object selfValidateJWT = keyManagerConfiguration.getParameter(APIConstants.KeyManager.SELF_VALIDATE_JWT);
if (selfValidateJWT != null && (Boolean) selfValidateJWT) {
Object issuer = keyManagerConfiguration.getParameter(APIConstants.KeyManager.ISSUER);
if (issuer != null) {
TokenIssuerDto tokenIssuerDto = new TokenIssuerDto((String) issuer);
Object claimMappings = keyManagerConfiguration.getParameter(APIConstants.KeyManager.CLAIM_MAPPING);
if (claimMappings instanceof List) {
Gson gson = new Gson();
JsonElement jsonElement = gson.toJsonTree(claimMappings);
ClaimMappingDto[] claimMappingDto = gson.fromJson(jsonElement, ClaimMappingDto[].class);
tokenIssuerDto.addClaimMappings(claimMappingDto);
}
Object consumerKeyClaim = keyManagerConfiguration.getParameter(APIConstants.KeyManager.CONSUMER_KEY_CLAIM);
if (consumerKeyClaim instanceof String && StringUtils.isNotEmpty((String) consumerKeyClaim)) {
tokenIssuerDto.setConsumerKeyClaim((String) consumerKeyClaim);
}
Object scopeClaim = keyManagerConfiguration.getParameter(APIConstants.KeyManager.SCOPES_CLAIM);
if (scopeClaim instanceof String && StringUtils.isNotEmpty((String) scopeClaim)) {
tokenIssuerDto.setScopesClaim((String) scopeClaim);
}
Object jwksEndpoint = keyManagerConfiguration.getParameter(APIConstants.KeyManager.JWKS_ENDPOINT);
if (jwksEndpoint != null) {
if (StringUtils.isNotEmpty((String) jwksEndpoint)) {
JWKSConfigurationDTO jwksConfigurationDTO = new JWKSConfigurationDTO();
jwksConfigurationDTO.setEnabled(true);
jwksConfigurationDTO.setUrl((String) jwksEndpoint);
tokenIssuerDto.setJwksConfigurationDTO(jwksConfigurationDTO);
}
}
Object certificateType = keyManagerConfiguration.getParameter(APIConstants.KeyManager.CERTIFICATE_TYPE);
Object certificateValue = keyManagerConfiguration.getParameter(APIConstants.KeyManager.CERTIFICATE_VALUE);
if (certificateType != null && StringUtils.isNotEmpty((String) certificateType) && certificateValue != null && StringUtils.isNotEmpty((String) certificateValue)) {
if (APIConstants.KeyManager.CERTIFICATE_TYPE_JWKS_ENDPOINT.equals(certificateType)) {
JWKSConfigurationDTO jwksConfigurationDTO = new JWKSConfigurationDTO();
jwksConfigurationDTO.setEnabled(true);
jwksConfigurationDTO.setUrl((String) certificateValue);
tokenIssuerDto.setJwksConfigurationDTO(jwksConfigurationDTO);
} else {
X509Certificate x509Certificate = APIUtil.retrieveCertificateFromContent((String) certificateValue);
if (x509Certificate != null) {
tokenIssuerDto.setCertificate(x509Certificate);
}
}
}
JWTValidator jwtValidator;
if (StringUtils.isEmpty(jwtValidatorImplementation)) {
jwtValidator = new JWTValidatorImpl();
} else {
try {
jwtValidator = (JWTValidator) Class.forName(jwtValidatorImplementation).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
log.error("Error while initializing JWT Validator", e);
throw new APIManagementException("Error while initializing JWT Validator", e);
}
}
jwtValidator.loadTokenIssuerConfiguration(tokenIssuerDto);
return jwtValidator;
}
}
return null;
}
use of org.wso2.carbon.apimgt.common.gateway.dto.TokenIssuerDto in project carbon-apimgt by wso2.
the class KeyManagerHolder method addGlobalJWTValidators.
public static void addGlobalJWTValidators(TokenIssuerDto tokenIssuerDto) {
KeyManagerDto keyManagerDto = new KeyManagerDto();
keyManagerDto.setIssuer(tokenIssuerDto.getIssuer());
keyManagerDto.setName(APIConstants.KeyManager.DEFAULT_KEY_MANAGER);
JWTValidator jwtValidator = new JWTValidatorImpl();
jwtValidator.loadTokenIssuerConfiguration(tokenIssuerDto);
keyManagerDto.setJwtValidator(jwtValidator);
globalJWTValidatorMap.put(tokenIssuerDto.getIssuer(), keyManagerDto);
}
Aggregations