use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto 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);
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeyManagerHolder method addKeyManagerConfiguration.
public static void addKeyManagerConfiguration(String organization, String name, String type, KeyManagerConfiguration keyManagerConfiguration) throws APIManagementException {
String issuer = (String) keyManagerConfiguration.getParameter(APIConstants.KeyManager.ISSUER);
OrganizationKeyManagerDto organizationKeyManagerDto = organizationWiseMap.get(organization);
if (organizationKeyManagerDto == null) {
organizationKeyManagerDto = new OrganizationKeyManagerDto();
}
if (organizationKeyManagerDto.getKeyManagerByName(name) != null) {
log.warn("Key Manager " + name + " already initialized in tenant " + organization);
}
if (keyManagerConfiguration.isEnabled() && !KeyManagerConfiguration.TokenType.EXCHANGED.equals(keyManagerConfiguration.getTokenType())) {
KeyManager keyManager = null;
JWTValidator jwtValidator = null;
APIManagerConfiguration apiManagerConfiguration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
String defaultKeyManagerType = apiManagerConfiguration.getFirstProperty(APIConstants.DEFAULT_KEY_MANAGER_TYPE);
KeyManagerConnectorConfiguration keyManagerConnectorConfiguration = ServiceReferenceHolder.getInstance().getKeyManagerConnectorConfiguration(type);
if (keyManagerConnectorConfiguration != null) {
if (StringUtils.isNotEmpty(keyManagerConnectorConfiguration.getImplementation())) {
try {
keyManager = (KeyManager) Class.forName(keyManagerConnectorConfiguration.getImplementation()).newInstance();
keyManager.setTenantDomain(organization);
if (StringUtils.isNotEmpty(defaultKeyManagerType) && defaultKeyManagerType.equals(type)) {
keyManagerConfiguration.addParameter(APIConstants.KEY_MANAGER_USERNAME, apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_VALIDATOR_USERNAME));
keyManagerConfiguration.addParameter(APIConstants.KEY_MANAGER_PASSWORD, apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_VALIDATOR_PASSWORD));
}
keyManager.loadConfiguration(keyManagerConfiguration);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new APIManagementException("Error while loading keyManager configuration", e);
}
}
jwtValidator = getJWTValidator(keyManagerConfiguration, keyManagerConnectorConfiguration.getJWTValidator());
} else {
if (APIConstants.KeyManager.DEFAULT_KEY_MANAGER_TYPE.equals(type)) {
keyManager = new AMDefaultKeyManagerImpl();
keyManager.setTenantDomain(organization);
keyManager.loadConfiguration(keyManagerConfiguration);
jwtValidator = getJWTValidator(keyManagerConfiguration, null);
}
}
KeyManagerDto keyManagerDto = new KeyManagerDto();
keyManagerDto.setName(name);
keyManagerDto.setIssuer(issuer);
keyManagerDto.setJwtValidator(jwtValidator);
keyManagerDto.setKeyManager(keyManager);
organizationKeyManagerDto.putKeyManagerDto(keyManagerDto);
organizationWiseMap.put(organization, organizationKeyManagerDto);
}
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeymanagersApiServiceImpl method toKeyManagerDTO.
public static KeyManagerDTO toKeyManagerDTO(String tenantDomain, KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
KeyManagerDTO keyManagerDTO = new KeyManagerDTO();
keyManagerDTO.setEnabled(keyManagerConfigurationDTO.isEnabled());
keyManagerDTO.setName(keyManagerConfigurationDTO.getName());
keyManagerDTO.setTenantDomain(tenantDomain);
keyManagerDTO.setType(keyManagerConfigurationDTO.getType());
keyManagerDTO.setTokenType(KeyManagerDTO.TokenTypeEnum.fromValue(keyManagerConfigurationDTO.getTokenType()));
keyManagerDTO.setConfiguration(keyManagerConfigurationDTO.getAdditionalProperties());
return keyManagerDTO;
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class APIAdminImpl method mergeIdpWithKeyManagerConfiguration.
private void mergeIdpWithKeyManagerConfiguration(IdentityProvider identityProvider, KeyManagerConfigurationDTO keyManagerDTO) {
keyManagerDTO.setDisplayName(identityProvider.getDisplayName());
keyManagerDTO.setDescription(identityProvider.getIdentityProviderDescription());
IdentityProviderProperty[] identityProviderProperties = identityProvider.getIdpProperties();
if (identityProviderProperties.length > 0) {
for (IdentityProviderProperty identityProviderProperty : identityProviderProperties) {
if (StringUtils.equals(identityProviderProperty.getName(), APIConstants.JWKS_URI)) {
keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_TYPE, APIConstants.KeyManager.CERTIFICATE_TYPE_JWKS_ENDPOINT);
keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_VALUE, identityProviderProperty.getValue());
}
if (StringUtils.equals(identityProviderProperty.getName(), IdentityApplicationConstants.IDP_ISSUER_NAME)) {
keyManagerDTO.addProperty(APIConstants.KeyManager.ISSUER, identityProviderProperty.getValue());
}
}
} else if (StringUtils.isNotBlank(identityProvider.getCertificate())) {
keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_TYPE, APIConstants.KeyManager.CERTIFICATE_TYPE_PEM_FILE);
keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_VALUE, identityProvider.getCertificate());
}
keyManagerDTO.setEnabled(identityProvider.isEnable());
keyManagerDTO.setAlias(identityProvider.getAlias());
ClaimConfig claimConfig = identityProvider.getClaimConfig();
JsonArray claimArray = new JsonArray();
for (ClaimMapping claimMapping : claimConfig.getClaimMappings()) {
JsonObject claimMappingEntryDTO = new JsonObject();
claimMappingEntryDTO.addProperty("localClaim", claimMapping.getLocalClaim().getClaimUri());
claimMappingEntryDTO.addProperty("remoteClaim", claimMapping.getRemoteClaim().getClaimUri());
claimArray.add(claimMappingEntryDTO);
}
keyManagerDTO.addProperty(APIConstants.KeyManager.CLAIM_MAPPING, claimArray);
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersPost.
public Response keyManagersPost(KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
try {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = KeyManagerMappingUtil.toKeyManagerConfigurationDTO(organization, body);
KeyManagerConfigurationDTO createdKeyManagerConfiguration = apiAdmin.addKeyManagerConfiguration(keyManagerConfigurationDTO);
APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.CREATED, RestApiCommonUtil.getLoggedInUsername());
URI location = new URI(RestApiConstants.KEY_MANAGERS + "/" + createdKeyManagerConfiguration.getUuid());
return Response.created(location).entity(KeyManagerMappingUtil.toKeyManagerDTO(createdKeyManagerConfiguration)).build();
} catch (URISyntaxException e) {
String error = "Error while Creating Key Manager configuration in organization " + organization;
throw new APIManagementException(error, e, ExceptionCodes.INTERNAL_ERROR);
}
}
Aggregations