Search in sources :

Example 1 with SpFileContent

use of org.wso2.carbon.identity.application.common.model.xsd.SpFileContent in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method importSPApplication.

public ImportResponse importSPApplication(SpFileContent spFileContent, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Importing service provider from file " + spFileContent.getFileName());
    }
    ServiceProvider serviceProvider = unmarshalSP(spFileContent, tenantDomain);
    ImportResponse importResponse = importSPApplication(serviceProvider, tenantDomain, username, isUpdate);
    if (log.isDebugEnabled()) {
        log.debug(String.format("Service provider %s@%s created successfully from file %s", serviceProvider.getApplicationName(), tenantDomain, spFileContent.getFileName()));
    }
    return importResponse;
}
Also used : ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 2 with SpFileContent

use of org.wso2.carbon.identity.application.common.model.xsd.SpFileContent in project product-is by wso2.

the class ApplicationManagementServiceClient method importApplication.

/**
 * Import service provider from spFile.
 *
 * @param serviceProviderContent
 * @param fileName
 * @throws Exception
 */
public void importApplication(String serviceProviderContent, String fileName) throws Exception {
    try {
        if (debugEnabled) {
            log.debug("Importing Service Provider ");
        }
        SpFileContent spFileContent = new SpFileContent();
        spFileContent.setFileName(fileName);
        spFileContent.setContent(serviceProviderContent);
        stub.importApplication(spFileContent);
    } catch (RemoteException | IdentityApplicationManagementServiceIdentityApplicationManagementException e) {
        log.error(e.getMessage(), e);
        throw new Exception(e.getMessage());
    }
}
Also used : SpFileContent(org.wso2.carbon.identity.application.common.model.xsd.SpFileContent) IdentityApplicationManagementServiceIdentityApplicationManagementException(org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException) RemoteException(java.rmi.RemoteException) IdentityApplicationManagementServiceIdentityApplicationManagementException(org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException) IdentityApplicationManagementServiceIdentityApplicationManagementClientException(org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementClientException) RemoteException(java.rmi.RemoteException)

Example 3 with SpFileContent

use of org.wso2.carbon.identity.application.common.model.xsd.SpFileContent in project product-is by wso2.

the class ApplicationManagementServiceClient method importApplication.

/**
 * Import Service Provider
 *
 * @param fileName    file name
 * @param fileContent file content
 * @return true if created
 * @throws Exception exception
 */
public String importApplication(String fileName, String fileContent) throws Exception {
    SpFileContent spFileContent = new SpFileContent();
    spFileContent.setFileName(fileName);
    spFileContent.setContent(fileContent);
    ImportResponse importResponse = stub.importApplication(spFileContent);
    if (201 == importResponse.getResponseCode()) {
        return importResponse.getApplicationName();
    }
    return null;
}
Also used : SpFileContent(org.wso2.carbon.identity.application.common.model.xsd.SpFileContent) ImportResponse(org.wso2.carbon.identity.application.common.model.xsd.ImportResponse)

Example 4 with SpFileContent

use of org.wso2.carbon.identity.application.common.model.xsd.SpFileContent in project identity-api-server by wso2.

the class ServerApplicationManagementService method buildSpFileContent.

private SpFileContent buildSpFileContent(InputStream fileInputStream, Attachment fileDetail) throws IOException {
    SpFileContent spFileContent = new SpFileContent();
    spFileContent.setContent(IOUtils.toString(fileInputStream, StandardCharsets.UTF_8.name()));
    spFileContent.setFileName(fileDetail.getDataHandler().getName());
    return spFileContent;
}
Also used : SpFileContent(org.wso2.carbon.identity.application.common.model.SpFileContent)

Example 5 with SpFileContent

use of org.wso2.carbon.identity.application.common.model.xsd.SpFileContent in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method unmarshalSP.

/**
 * Convert xml file of service provider to object.
 *
 * @param spFileContent xml string of the SP and file name
 * @param tenantDomain  tenant domain name
 * @return Service Provider
 * @throws IdentityApplicationManagementException Identity Application Management Exception
 */
private ServiceProvider unmarshalSP(SpFileContent spFileContent, String tenantDomain) throws IdentityApplicationManagementException {
    if (StringUtils.isEmpty(spFileContent.getContent())) {
        throw new IdentityApplicationManagementException(String.format("Empty Service Provider configuration file" + " %s uploaded by tenant: %s", spFileContent.getFileName(), tenantDomain));
    }
    try {
        // Creating secure parser by disabling XXE.
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        spf.setXIncludeAware(false);
        try {
            spf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE, false);
            spf.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE, false);
            spf.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false);
            spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        } catch (SAXException | ParserConfigurationException e) {
            log.error("Failed to load XML Processor Feature " + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE + " or " + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE + " or " + Constants.LOAD_EXTERNAL_DTD_FEATURE + " or secure-processing.");
        }
        // Creating source object using the secure parser.
        Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(), new InputSource(new StringReader(spFileContent.getContent())));
        // Performing unmarshall operation by passing the generated source object to the unmarshaller.
        JAXBContext jaxbContext = JAXBContext.newInstance(ServiceProvider.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        return (ServiceProvider) unmarshaller.unmarshal(xmlSource);
    } catch (JAXBException | SAXException | ParserConfigurationException e) {
        throw new IdentityApplicationManagementException(String.format("Error in reading Service Provider " + "configuration file %s uploaded by tenant: %s", spFileContent.getFileName(), tenantDomain), e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) SAXException(org.xml.sax.SAXException) SAXSource(javax.xml.transform.sax.SAXSource) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Unmarshaller(javax.xml.bind.Unmarshaller) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 ImportResponse (org.wso2.carbon.identity.application.common.model.ImportResponse)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 SpFileContent (org.wso2.carbon.identity.application.common.model.SpFileContent)2 SpFileContent (org.wso2.carbon.identity.application.common.model.xsd.SpFileContent)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 RemoteException (java.rmi.RemoteException)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 SAXSource (javax.xml.transform.sax.SAXSource)1 ImportResponse (org.wso2.carbon.identity.application.common.model.xsd.ImportResponse)1 IdentityApplicationManagementServiceIdentityApplicationManagementClientException (org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementClientException)1 IdentityApplicationManagementServiceIdentityApplicationManagementException (org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException)1 InputSource (org.xml.sax.InputSource)1