Search in sources :

Example 1 with ImportResponse

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

the class ApplicationManagementServiceImpl method importApplication.

private ImportResponse importApplication(ServiceProvider serviceProvider, String tenantDomain, String username, boolean isUpdate) throws IdentityApplicationManagementException {
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    ServiceProvider savedSP = null;
    String appName = serviceProvider.getApplicationName();
    try {
        if (isUpdate) {
            savedSP = getApplicationExcludingFileBasedSPs(appName, tenantDomain);
            if (savedSP == null) {
                String errorMsg = String.format("Service provider %s@%s is not found", appName, tenantDomain);
                throw new IdentityApplicationManagementClientException(APPLICATION_NOT_FOUND.getCode(), errorMsg);
            }
        }
        if (!isUpdate) {
            ServiceProvider basicApplication = new ServiceProvider();
            basicApplication.setApplicationName(serviceProvider.getApplicationName());
            basicApplication.setDescription(serviceProvider.getDescription());
            String resourceId = createApplication(basicApplication, tenantDomain, username);
            savedSP = getApplicationByResourceId(resourceId, tenantDomain);
        }
        serviceProvider.setApplicationResourceId(savedSP.getApplicationResourceId());
        serviceProvider.setApplicationID(savedSP.getApplicationID());
        serviceProvider.setOwner(getUser(tenantDomain, username));
        for (ApplicationMgtListener listener : listeners) {
            if (listener.isEnable()) {
                listener.onPreCreateInbound(serviceProvider, isUpdate);
            }
        }
        updateApplication(serviceProvider, tenantDomain, username);
        for (ApplicationMgtListener listener : listeners) {
            if (listener.isEnable()) {
                listener.doImportServiceProvider(serviceProvider);
            }
        }
        ImportResponse importResponse = new ImportResponse();
        if (isUpdate) {
            importResponse.setResponseCode(ImportResponse.UPDATED);
        } else {
            importResponse.setResponseCode(ImportResponse.CREATED);
        }
        importResponse.setApplicationName(appName);
        importResponse.setApplicationResourceId(serviceProvider.getApplicationResourceId());
        importResponse.setErrors(new String[0]);
        return importResponse;
    } catch (IdentityApplicationManagementClientException e) {
        deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
        return buildImportErrorResponse(e);
    } catch (IdentityApplicationManagementException e) {
        deleteCreatedSP(savedSP, tenantDomain, username, isUpdate);
        String errorMsg = String.format("Error in importing provided service provider %s@%s from file ", appName, tenantDomain);
        throw new IdentityApplicationManagementException(errorMsg, e);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)

Example 2 with ImportResponse

use of org.wso2.carbon.identity.application.common.model.ImportResponse 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 3 with ImportResponse

use of org.wso2.carbon.identity.application.common.model.ImportResponse 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 ImportResponse

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

the class ApplicationManagementServiceImpl method buildImportErrorResponse.

private ImportResponse buildImportErrorResponse(IdentityApplicationManagementClientException e) {
    ImportResponse importResponse = new ImportResponse();
    importResponse.setResponseCode(ImportResponse.FAILED);
    importResponse.setApplicationName(null);
    String errorCode = e.getErrorCode() != null ? e.getErrorCode() : INVALID_REQUEST.getCode();
    importResponse.setErrorCode(errorCode);
    if (e instanceof IdentityApplicationManagementValidationException) {
        importResponse.setErrors(((IdentityApplicationManagementValidationException) e).getValidationMsg());
    } else {
        String message = e.getMessage();
        if (StringUtils.isNotBlank(message)) {
            importResponse.setErrors(new String[] { e.getMessage() });
        }
    }
    return importResponse;
}
Also used : ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)

Example 5 with ImportResponse

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

the class ServerApplicationManagementService method doImportApplication.

private String doImportApplication(InputStream fileInputStream, Attachment fileDetail, boolean isAppUpdate) {
    try {
        SpFileContent spFileContent = buildSpFileContent(fileInputStream, fileDetail);
        String tenantDomain = ContextLoader.getTenantDomainFromContext();
        String username = ContextLoader.getUsernameFromContext();
        ImportResponse importResponse = getApplicationManagementService().importSPApplication(spFileContent, tenantDomain, username, isAppUpdate);
        if (importResponse.getResponseCode() == ImportResponse.FAILED) {
            throw handleErrorResponse(importResponse);
        } else {
            return importResponse.getApplicationResourceId();
        }
    } catch (IOException e) {
        throw Utils.buildServerError("Error importing application from XML file.", e);
    } catch (IdentityApplicationManagementException e) {
        throw handleIdentityApplicationManagementException(e, "Error importing application from XML file.");
    } finally {
        IOUtils.closeQuietly(fileInputStream);
    }
}
Also used : SpFileContent(org.wso2.carbon.identity.application.common.model.SpFileContent) ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IOException(java.io.IOException)

Aggregations

ImportResponse (org.wso2.carbon.identity.application.common.model.ImportResponse)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 IOException (java.io.IOException)1 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)1 IdentityApplicationManagementValidationException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException)1 SpFileContent (org.wso2.carbon.identity.application.common.model.SpFileContent)1 ImportResponse (org.wso2.carbon.identity.application.common.model.xsd.ImportResponse)1 SpFileContent (org.wso2.carbon.identity.application.common.model.xsd.SpFileContent)1 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)1 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)1