Search in sources :

Example 1 with KeyMgtNotificationSender

use of org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender in project carbon-apimgt by wso2.

the class APIAdminImpl method deleteKeyManagerConfigurationById.

@Override
public void deleteKeyManagerConfigurationById(String organization, KeyManagerConfigurationDTO kmConfig) throws APIManagementException {
    if (kmConfig != null) {
        if (!APIConstants.KeyManager.DEFAULT_KEY_MANAGER.equals(kmConfig.getName())) {
            deleteIdentityProvider(organization, kmConfig);
            apiMgtDAO.deleteKeyManagerConfigurationById(kmConfig.getUuid(), organization);
            new KeyMgtNotificationSender().notify(kmConfig, APIConstants.KeyManager.KeyManagerEvent.ACTION_DELETE);
        } else {
            throw new APIManagementException(APIConstants.KeyManager.DEFAULT_KEY_MANAGER + " couldn't delete", ExceptionCodes.INTERNAL_ERROR);
        }
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) KeyMgtNotificationSender(org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender)

Example 2 with KeyMgtNotificationSender

use of org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender in project carbon-apimgt by wso2.

the class APIAdminImpl method addKeyManagerConfiguration.

@Override
public KeyManagerConfigurationDTO addKeyManagerConfiguration(KeyManagerConfigurationDTO keyManagerConfigurationDTO) throws APIManagementException {
    if (apiMgtDAO.isKeyManagerConfigurationExistByName(keyManagerConfigurationDTO.getName(), keyManagerConfigurationDTO.getOrganization())) {
        throw new APIManagementException("Key manager Already Exist by Name " + keyManagerConfigurationDTO.getName() + " in tenant " + keyManagerConfigurationDTO.getOrganization(), ExceptionCodes.KEY_MANAGER_ALREADY_EXIST);
    }
    if (!KeyManagerConfiguration.TokenType.valueOf(keyManagerConfigurationDTO.getTokenType().toUpperCase()).equals(KeyManagerConfiguration.TokenType.EXCHANGED)) {
        validateKeyManagerConfiguration(keyManagerConfigurationDTO);
        validateKeyManagerEndpointConfiguration(keyManagerConfigurationDTO);
    }
    if (StringUtils.equals(KeyManagerConfiguration.TokenType.EXCHANGED.toString(), keyManagerConfigurationDTO.getTokenType()) || StringUtils.equals(KeyManagerConfiguration.TokenType.BOTH.toString(), keyManagerConfigurationDTO.getTokenType())) {
        keyManagerConfigurationDTO.setUuid(UUID.randomUUID().toString());
        try {
            IdentityProvider identityProvider = IdentityProviderManager.getInstance().addIdPWithResourceId(createIdp(keyManagerConfigurationDTO), APIUtil.getInternalOrganizationDomain(keyManagerConfigurationDTO.getOrganization()));
            keyManagerConfigurationDTO.setExternalReferenceId(identityProvider.getResourceId());
        } catch (IdentityProviderManagementException e) {
            throw new APIManagementException("IdP adding failed. " + e.getMessage(), e, ExceptionCodes.IDP_ADDING_FAILED);
        }
    }
    if (StringUtils.isBlank(keyManagerConfigurationDTO.getUuid())) {
        keyManagerConfigurationDTO.setUuid(UUID.randomUUID().toString());
    }
    KeyManagerConfigurationDTO keyManagerConfigurationToStore = new KeyManagerConfigurationDTO(keyManagerConfigurationDTO);
    encryptKeyManagerConfigurationValues(null, keyManagerConfigurationToStore);
    apiMgtDAO.addKeyManagerConfiguration(keyManagerConfigurationToStore);
    new KeyMgtNotificationSender().notify(keyManagerConfigurationDTO, APIConstants.KeyManager.KeyManagerEvent.ACTION_ADD);
    return keyManagerConfigurationDTO;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) KeyMgtNotificationSender(org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender)

Example 3 with KeyMgtNotificationSender

use of org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender in project carbon-apimgt by wso2.

the class APIAdminImpl method updateKeyManagerConfiguration.

@Override
public KeyManagerConfigurationDTO updateKeyManagerConfiguration(KeyManagerConfigurationDTO keyManagerConfigurationDTO) throws APIManagementException {
    if (!KeyManagerConfiguration.TokenType.valueOf(keyManagerConfigurationDTO.getTokenType().toUpperCase()).equals(KeyManagerConfiguration.TokenType.EXCHANGED)) {
        validateKeyManagerConfiguration(keyManagerConfigurationDTO);
        validateKeyManagerEndpointConfiguration(keyManagerConfigurationDTO);
    }
    KeyManagerConfigurationDTO oldKeyManagerConfiguration = apiMgtDAO.getKeyManagerConfigurationByID(keyManagerConfigurationDTO.getOrganization(), keyManagerConfigurationDTO.getUuid());
    if (StringUtils.equals(KeyManagerConfiguration.TokenType.EXCHANGED.toString(), keyManagerConfigurationDTO.getTokenType()) || StringUtils.equals(KeyManagerConfiguration.TokenType.BOTH.toString(), keyManagerConfigurationDTO.getTokenType())) {
        IdentityProvider identityProvider;
        try {
            if (StringUtils.isNotEmpty(oldKeyManagerConfiguration.getExternalReferenceId())) {
                IdentityProvider retrievedIDP = IdentityProviderManager.getInstance().getIdPByResourceId(oldKeyManagerConfiguration.getExternalReferenceId(), APIUtil.getInternalOrganizationDomain(keyManagerConfigurationDTO.getOrganization()), Boolean.FALSE);
                identityProvider = IdentityProviderManager.getInstance().updateIdPByResourceId(oldKeyManagerConfiguration.getExternalReferenceId(), updatedIDP(retrievedIDP, keyManagerConfigurationDTO), APIUtil.getInternalOrganizationDomain(keyManagerConfigurationDTO.getOrganization()));
            } else {
                identityProvider = IdentityProviderManager.getInstance().addIdPWithResourceId(createIdp(keyManagerConfigurationDTO), APIUtil.getInternalOrganizationDomain(keyManagerConfigurationDTO.getOrganization()));
                keyManagerConfigurationDTO.setExternalReferenceId(identityProvider.getResourceId());
            }
        } catch (IdentityProviderManagementException e) {
            throw new APIManagementException("IdP adding failed. " + e.getMessage(), e, ExceptionCodes.IDP_ADDING_FAILED);
        }
        keyManagerConfigurationDTO.setExternalReferenceId(identityProvider.getResourceId());
    }
    if ((StringUtils.equals(KeyManagerConfiguration.TokenType.EXCHANGED.toString(), oldKeyManagerConfiguration.getTokenType()) || StringUtils.equals(KeyManagerConfiguration.TokenType.BOTH.toString(), oldKeyManagerConfiguration.getTokenType())) && StringUtils.equals(KeyManagerConfiguration.TokenType.DIRECT.toString(), keyManagerConfigurationDTO.getTokenType())) {
        // Delete Identity Provider Created.
        if (StringUtils.isNotEmpty(oldKeyManagerConfiguration.getExternalReferenceId())) {
            try {
                IdentityProviderManager.getInstance().deleteIdPByResourceId(oldKeyManagerConfiguration.getExternalReferenceId(), APIUtil.getInternalOrganizationDomain(keyManagerConfigurationDTO.getOrganization()));
                keyManagerConfigurationDTO.setExternalReferenceId(null);
            } catch (IdentityProviderManagementException e) {
                throw new APIManagementException("IdP deletion failed. " + e.getMessage(), e, ExceptionCodes.IDP_DELETION_FAILED);
            }
        }
    }
    encryptKeyManagerConfigurationValues(oldKeyManagerConfiguration, keyManagerConfigurationDTO);
    apiMgtDAO.updateKeyManagerConfiguration(keyManagerConfigurationDTO);
    KeyManagerConfigurationDTO decryptedKeyManagerConfiguration = decryptKeyManagerConfigurationValues(keyManagerConfigurationDTO);
    new KeyMgtNotificationSender().notify(decryptedKeyManagerConfiguration, APIConstants.KeyManager.KeyManagerEvent.ACTION_UPDATE);
    return keyManagerConfigurationDTO;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) KeyMgtNotificationSender(org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 KeyMgtNotificationSender (org.wso2.carbon.apimgt.impl.keymgt.KeyMgtNotificationSender)3 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)2 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)2 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)2