use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class APIAdminImpl method getKeyManagerConfigurationByName.
@Override
public KeyManagerConfigurationDTO getKeyManagerConfigurationByName(String organization, String name) throws APIManagementException {
KeyManagerConfigurationDTO keyManagerConfiguration = apiMgtDAO.getKeyManagerConfigurationByName(organization, name);
if (keyManagerConfiguration != null && APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(keyManagerConfiguration.getName())) {
APIUtil.getAndSetDefaultKeyManagerConfiguration(keyManagerConfiguration);
}
maskValues(keyManagerConfiguration);
if (!StringUtils.equals(KeyManagerConfiguration.TokenType.EXCHANGED.toString(), keyManagerConfiguration.getTokenType())) {
getKeyManagerEndpoints(keyManagerConfiguration);
}
return keyManagerConfiguration;
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class APIAdminImpl method setAliasForTokenExchangeKeyManagers.
private void setAliasForTokenExchangeKeyManagers(List<KeyManagerConfigurationDTO> keyManagerConfigurationsByTenant, String tenantDomain) throws APIManagementException {
for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurationsByTenant) {
if (StringUtils.equals(KeyManagerConfiguration.TokenType.EXCHANGED.toString(), keyManagerConfigurationDTO.getTokenType()) || StringUtils.equals(KeyManagerConfiguration.TokenType.BOTH.toString(), keyManagerConfigurationDTO.getTokenType())) {
if (keyManagerConfigurationDTO.getExternalReferenceId() != null) {
IdentityProvider identityProvider;
try {
identityProvider = IdentityProviderManager.getInstance().getIdPByResourceId(keyManagerConfigurationDTO.getExternalReferenceId(), tenantDomain, Boolean.FALSE);
} catch (IdentityProviderManagementException e) {
throw new APIManagementException("IdP retrieval failed. " + e.getMessage(), e, ExceptionCodes.IDP_RETRIEVAL_FAILED);
}
// Set alias value since this will be used from the Devportal side.
keyManagerConfigurationDTO.setAlias(identityProvider.getAlias());
}
}
}
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class APIAdminImpl method getAllKeyManagerConfigurations.
@Override
public Map<String, List<KeyManagerConfigurationDTO>> getAllKeyManagerConfigurations() throws APIManagementException {
List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiMgtDAO.getKeyManagerConfigurations();
Map<String, List<KeyManagerConfigurationDTO>> keyManagerConfigurationsByTenant = new HashMap<>();
for (KeyManagerConfigurationDTO keyManagerConfiguration : keyManagerConfigurations) {
List<KeyManagerConfigurationDTO> keyManagerConfigurationDTOS;
if (keyManagerConfigurationsByTenant.containsKey(keyManagerConfiguration.getOrganization())) {
keyManagerConfigurationDTOS = keyManagerConfigurationsByTenant.get(keyManagerConfiguration.getOrganization());
} else {
keyManagerConfigurationDTOS = new ArrayList<>();
}
if (APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(keyManagerConfiguration.getName())) {
APIUtil.getAndSetDefaultKeyManagerConfiguration(keyManagerConfiguration);
}
keyManagerConfigurationDTOS.add(keyManagerConfiguration);
keyManagerConfigurationsByTenant.put(keyManagerConfiguration.getOrganization(), keyManagerConfigurationDTOS);
}
return keyManagerConfigurationsByTenant;
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class APIAdminImpl method setIdentityProviderRelatedInformation.
private void setIdentityProviderRelatedInformation(List<KeyManagerConfigurationDTO> keyManagerConfigurationsByOrganization, String organization) throws APIManagementException {
for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurationsByOrganization) {
if (StringUtils.equals(KeyManagerConfiguration.TokenType.EXCHANGED.toString(), keyManagerConfigurationDTO.getTokenType()) || StringUtils.equals(KeyManagerConfiguration.TokenType.BOTH.toString(), keyManagerConfigurationDTO.getTokenType())) {
try {
if (keyManagerConfigurationDTO.getExternalReferenceId() != null) {
IdentityProvider identityProvider = IdentityProviderManager.getInstance().getIdPByResourceId(keyManagerConfigurationDTO.getExternalReferenceId(), APIUtil.getTenantDomainFromTenantId(APIUtil.getInternalOrganizationId(organization)), Boolean.FALSE);
keyManagerConfigurationDTO.setDescription(identityProvider.getIdentityProviderDescription());
keyManagerConfigurationDTO.setEnabled(identityProvider.isEnable());
}
} catch (IdentityProviderManagementException e) {
// handled in this way in order to not break other key managers.
log.error("IdP retrieval failed. ", e);
}
}
}
}
use of org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO in project carbon-apimgt by wso2.
the class APIAdminImpl method getKeyManagerConfigurationsByOrganization.
@Override
public List<KeyManagerConfigurationDTO> getKeyManagerConfigurationsByOrganization(String organization) throws APIManagementException {
// For Choreo scenario (Choreo organization uses the same super tenant Resident Key Manager
// Hence no need to register the default key manager per organization)
String tenantDomain = organization;
try {
if (APIUtil.isInternalOrganization(organization)) {
KeyMgtRegistrationService.registerDefaultKeyManager(organization);
} else {
tenantDomain = APIUtil.getInternalOrganizationDomain(organization);
}
} catch (UserStoreException e) {
throw new APIManagementException("Error while retrieving tenant id for organization " + organization, e);
}
List<KeyManagerConfigurationDTO> keyManagerConfigurationsByTenant = apiMgtDAO.getKeyManagerConfigurationsByOrganization(tenantDomain);
Iterator<KeyManagerConfigurationDTO> iterator = keyManagerConfigurationsByTenant.iterator();
KeyManagerConfigurationDTO defaultKeyManagerConfiguration = null;
while (iterator.hasNext()) {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = iterator.next();
if (APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(keyManagerConfigurationDTO.getName())) {
defaultKeyManagerConfiguration = keyManagerConfigurationDTO;
iterator.remove();
break;
}
}
if (defaultKeyManagerConfiguration != null) {
APIUtil.getAndSetDefaultKeyManagerConfiguration(defaultKeyManagerConfiguration);
keyManagerConfigurationsByTenant.add(defaultKeyManagerConfiguration);
}
// and append those to the previous list
if (!StringUtils.equals(organization, tenantDomain)) {
List<KeyManagerConfigurationDTO> keyManagerConfigurationsByOrganization = apiMgtDAO.getKeyManagerConfigurationsByOrganization(organization);
keyManagerConfigurationsByTenant.addAll(keyManagerConfigurationsByOrganization);
}
setAliasForTokenExchangeKeyManagers(keyManagerConfigurationsByTenant, tenantDomain);
for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurationsByTenant) {
decryptKeyManagerConfigurationValues(keyManagerConfigurationDTO);
getKeyManagerEndpoints(keyManagerConfigurationDTO);
}
setIdentityProviderRelatedInformation(keyManagerConfigurationsByTenant, organization);
return keyManagerConfigurationsByTenant;
}
Aggregations