use of org.wso2.carbon.identity.application.common.model.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;
}
use of org.wso2.carbon.identity.application.common.model.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());
}
}
use of org.wso2.carbon.identity.application.common.model.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;
}
use of org.wso2.carbon.identity.application.common.model.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;
}
use of org.wso2.carbon.identity.application.common.model.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);
}
}
Aggregations