Search in sources :

Example 16 with KeyManagerConfigurationDTO

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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)

Example 17 with KeyManagerConfigurationDTO

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

Example 18 with KeyManagerConfigurationDTO

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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with KeyManagerConfigurationDTO

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);
            }
        }
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 20 with KeyManagerConfigurationDTO

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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Aggregations

KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)43 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)30 Gson (com.google.gson.Gson)16 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)11 JSONObject (org.json.simple.JSONObject)10 JsonObject (com.google.gson.JsonObject)9 PreparedStatement (java.sql.PreparedStatement)9 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)9 OAuthAppRequest (org.wso2.carbon.apimgt.api.model.OAuthAppRequest)9 Map (java.util.Map)8 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)8 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)7 LinkedHashMap (java.util.LinkedHashMap)6 Application (org.wso2.carbon.apimgt.api.model.Application)6