Search in sources :

Example 1 with CredentialDto

use of org.wso2.carbon.apimgt.api.gateway.CredentialDto in project carbon-apimgt by wso2.

the class TemplateBuilderUtil method addCredentialsToList.

private static void addCredentialsToList(String prefix, API api, GatewayAPIDTO gatewayAPIDTO, org.json.JSONObject endpointSecurity, String type) {
    if (APIConstants.ENDPOINT_SECURITY_TYPE_OAUTH.equalsIgnoreCase((String) endpointSecurity.get(APIConstants.ENDPOINT_SECURITY_TYPE))) {
        CredentialDto clientSecretDto = new CredentialDto();
        if (StringUtils.isNotEmpty(prefix)) {
            clientSecretDto.setAlias(prefix.concat("--").concat(GatewayUtils.retrieveOauthClientSecretAlias(api.getId().getApiName(), api.getId().getVersion(), type)));
        } else {
            clientSecretDto.setAlias(GatewayUtils.retrieveOauthClientSecretAlias(api.getId().getApiName(), api.getId().getVersion(), type));
        }
        clientSecretDto.setPassword((String) endpointSecurity.get(APIConstants.ENDPOINT_SECURITY_CLIENT_SECRET));
        gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(clientSecretDto, gatewayAPIDTO.getCredentialsToBeAdd()));
        if (endpointSecurity.has(APIConstants.ENDPOINT_SECURITY_PASSWORD)) {
            CredentialDto passwordDto = new CredentialDto();
            if (StringUtils.isNotEmpty(prefix)) {
                passwordDto.setAlias(prefix.concat("--").concat(GatewayUtils.retrieveOAuthPasswordAlias(api.getId().getApiName(), api.getId().getVersion(), type)));
            } else {
                passwordDto.setAlias(GatewayUtils.retrieveOAuthPasswordAlias(api.getId().getApiName(), api.getId().getVersion(), type));
            }
            passwordDto.setPassword((String) endpointSecurity.get(APIConstants.ENDPOINT_SECURITY_PASSWORD));
            gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(passwordDto, gatewayAPIDTO.getCredentialsToBeAdd()));
        }
    } else if (APIConstants.ENDPOINT_SECURITY_TYPE_BASIC.equalsIgnoreCase((String) endpointSecurity.get(APIConstants.ENDPOINT_SECURITY_TYPE))) {
        CredentialDto credentialDto = new CredentialDto();
        if (StringUtils.isNotEmpty(prefix)) {
            credentialDto.setAlias(prefix.concat("--").concat(GatewayUtils.retrieveBasicAuthAlias(api.getId().getApiName(), api.getId().getVersion(), type)));
        } else {
            credentialDto.setAlias(GatewayUtils.retrieveBasicAuthAlias(api.getId().getApiName(), api.getId().getVersion(), type));
        }
        credentialDto.setPassword((String) endpointSecurity.get(APIConstants.ENDPOINT_SECURITY_PASSWORD));
        gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(credentialDto, gatewayAPIDTO.getCredentialsToBeAdd()));
    }
}
Also used : CredentialDto(org.wso2.carbon.apimgt.api.gateway.CredentialDto)

Example 2 with CredentialDto

use of org.wso2.carbon.apimgt.api.gateway.CredentialDto in project carbon-apimgt by wso2.

the class TemplateBuilderUtil method addAWSCredentialsToList.

private static void addAWSCredentialsToList(String prefix, API api, GatewayAPIDTO gatewayAPIDTO, org.json.JSONObject endpointConfig) {
    if (StringUtils.isNotEmpty((String) endpointConfig.get(APIConstants.AMZN_SECRET_KEY))) {
        CredentialDto awsSecretDto = new CredentialDto();
        if (StringUtils.isNotEmpty(prefix)) {
            awsSecretDto.setAlias(prefix.concat("--").concat(GatewayUtils.retrieveAWSCredAlias(api.getId().getApiName(), api.getId().getVersion(), APIConstants.ENDPOINT_TYPE_AWSLAMBDA)));
        } else {
            awsSecretDto.setAlias(GatewayUtils.retrieveAWSCredAlias(api.getId().getApiName(), api.getId().getVersion(), APIConstants.ENDPOINT_TYPE_AWSLAMBDA));
        }
        awsSecretDto.setPassword((String) endpointConfig.get(APIConstants.AMZN_SECRET_KEY));
        gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(awsSecretDto, gatewayAPIDTO.getCredentialsToBeAdd()));
    }
}
Also used : CredentialDto(org.wso2.carbon.apimgt.api.gateway.CredentialDto)

Example 3 with CredentialDto

use of org.wso2.carbon.apimgt.api.gateway.CredentialDto in project carbon-apimgt by wso2.

the class APIGatewayAdmin method deployAPI.

public boolean deployAPI(GatewayAPIDTO gatewayAPIDTO) throws AxisFault {
    CertificateManager certificateManager = CertificateManagerImpl.getInstance();
    SequenceAdminServiceProxy sequenceAdminServiceProxy = getSequenceAdminServiceClient(gatewayAPIDTO.getTenantDomain());
    RESTAPIAdminServiceProxy restapiAdminServiceProxy = getRestapiAdminClient(gatewayAPIDTO.getTenantDomain());
    LocalEntryServiceProxy localEntryServiceProxy = new LocalEntryServiceProxy(gatewayAPIDTO.getTenantDomain());
    EndpointAdminServiceProxy endpointAdminServiceProxy = new EndpointAdminServiceProxy(gatewayAPIDTO.getTenantDomain());
    MediationSecurityAdminServiceProxy mediationSecurityAdminServiceProxy = new MediationSecurityAdminServiceProxy(gatewayAPIDTO.getTenantDomain());
    if (log.isDebugEnabled()) {
        log.debug("Start to undeploy API" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    unDeployAPI(certificateManager, sequenceAdminServiceProxy, restapiAdminServiceProxy, localEntryServiceProxy, endpointAdminServiceProxy, gatewayAPIDTO, mediationSecurityAdminServiceProxy);
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " undeployed");
        log.debug("Start to deploy Local entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Add Local Entries
    if (gatewayAPIDTO.getLocalEntriesToBeAdd() != null) {
        for (GatewayContentDTO localEntry : gatewayAPIDTO.getLocalEntriesToBeAdd()) {
            if (localEntryServiceProxy.isEntryExists(localEntry.getName())) {
                localEntryServiceProxy.deleteEntry(localEntry.getName());
                localEntryServiceProxy.addLocalEntry(localEntry.getContent());
            } else {
                localEntryServiceProxy.addLocalEntry(localEntry.getContent());
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Local Entries deployed");
        log.debug("Start to deploy Endpoint entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Add Endpoints
    if (gatewayAPIDTO.getEndpointEntriesToBeAdd() != null) {
        for (GatewayContentDTO endpointEntry : gatewayAPIDTO.getEndpointEntriesToBeAdd()) {
            if (endpointAdminServiceProxy.isEndpointExist(endpointEntry.getName())) {
                endpointAdminServiceProxy.deleteEndpoint(endpointEntry.getName());
                endpointAdminServiceProxy.addEndpoint(endpointEntry.getContent());
            } else {
                endpointAdminServiceProxy.addEndpoint(endpointEntry.getContent());
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Endpoints deployed");
        log.debug("Start to deploy Client certificates" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Add Client Certificates
    if (gatewayAPIDTO.getClientCertificatesToBeAdd() != null) {
        for (GatewayContentDTO certificate : gatewayAPIDTO.getClientCertificatesToBeAdd()) {
            certificateManager.addClientCertificateToGateway(certificate.getContent(), certificate.getName());
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " client certificates deployed");
        log.debug("Start to add vault entries " + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Add vault entries
    if (gatewayAPIDTO.getCredentialsToBeAdd() != null) {
        for (CredentialDto certificate : gatewayAPIDTO.getCredentialsToBeAdd()) {
            try {
                String encryptedValue = mediationSecurityAdminServiceProxy.doEncryption(certificate.getPassword());
                if (mediationSecurityAdminServiceProxy.isAliasExist(certificate.getAlias())) {
                    setRegistryProperty(gatewayAPIDTO.getTenantDomain(), certificate.getAlias(), encryptedValue);
                } else {
                    setRegistryProperty(gatewayAPIDTO.getTenantDomain(), certificate.getAlias(), encryptedValue);
                }
            } catch (APIManagementException e) {
                log.error("Exception occurred while encrypting password.", e);
                throw new AxisFault(e.getMessage());
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Vault Entries Added successfully");
        log.debug("Start to deploy custom sequences" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Add Sequences
    if (gatewayAPIDTO.getSequenceToBeAdd() != null) {
        for (GatewayContentDTO sequence : gatewayAPIDTO.getSequenceToBeAdd()) {
            OMElement element;
            try {
                element = AXIOMUtil.stringToOM(sequence.getContent());
            } catch (XMLStreamException e) {
                log.error("Exception occurred while converting String to an OM.", e);
                throw new AxisFault(e.getMessage());
            }
            if (sequenceAdminServiceProxy.isExistingSequence(sequence.getName())) {
                sequenceAdminServiceProxy.deleteSequence(sequence.getName());
                sequenceAdminServiceProxy.addSequence(element);
            } else {
                sequenceAdminServiceProxy.addSequence(element);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " custom sequences deployed");
        log.debug("Start to deploy API Definition" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Add API
    if (StringUtils.isNotEmpty(gatewayAPIDTO.getApiDefinition())) {
        restapiAdminServiceProxy.addApi(gatewayAPIDTO.getApiDefinition());
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " API Definition deployed");
        log.debug("Start to deploy Default API Definition" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Default API Definition deployed");
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + "Deployed successfully");
    }
    return true;
}
Also used : AxisFault(org.apache.axis2.AxisFault) MediationSecurityAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.MediationSecurityAdminServiceProxy) CertificateManager(org.wso2.carbon.apimgt.impl.certificatemgt.CertificateManager) OMElement(org.apache.axiom.om.OMElement) RESTAPIAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.RESTAPIAdminServiceProxy) CredentialDto(org.wso2.carbon.apimgt.api.gateway.CredentialDto) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) XMLStreamException(javax.xml.stream.XMLStreamException) LocalEntryServiceProxy(org.wso2.carbon.apimgt.gateway.utils.LocalEntryServiceProxy) EndpointAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy) GatewayContentDTO(org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO) SequenceAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.SequenceAdminServiceProxy)

Aggregations

CredentialDto (org.wso2.carbon.apimgt.api.gateway.CredentialDto)3 XMLStreamException (javax.xml.stream.XMLStreamException)1 OMElement (org.apache.axiom.om.OMElement)1 AxisFault (org.apache.axis2.AxisFault)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 GatewayContentDTO (org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)1 EndpointAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy)1 LocalEntryServiceProxy (org.wso2.carbon.apimgt.gateway.utils.LocalEntryServiceProxy)1 MediationSecurityAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.MediationSecurityAdminServiceProxy)1 RESTAPIAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.RESTAPIAdminServiceProxy)1 SequenceAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.SequenceAdminServiceProxy)1 CertificateManager (org.wso2.carbon.apimgt.impl.certificatemgt.CertificateManager)1