use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException 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);
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method getApplicationTemplate.
@Override
public SpTemplate getApplicationTemplate(String templateName, String tenantDomain) throws IdentityApplicationManagementException {
String retrievedTemplateName = templateName;
if (StringUtils.isBlank(retrievedTemplateName)) {
retrievedTemplateName = ApplicationConstants.TENANT_DEFAULT_SP_TEMPLATE_NAME;
}
SpTemplate spTemplate = doGetApplicationTemplate(retrievedTemplateName, tenantDomain);
if (spTemplate == null) {
if (StringUtils.isBlank(templateName)) {
return null;
} else {
throw new IdentityApplicationManagementClientException(new String[] { String.format("Template with name: %s is not " + "registered for tenant: %s.", templateName, tenantDomain) });
}
}
return spTemplate;
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method updateApplicationTemplate.
@Override
public void updateApplicationTemplate(String oldTemplateName, SpTemplate spTemplate, String tenantDomain) throws IdentityApplicationManagementException {
try {
validateSPTemplateExists(oldTemplateName, spTemplate, tenantDomain);
ServiceProvider serviceProvider = unmarshalSPTemplate(spTemplate.getContent());
validateUnsupportedTemplateConfigs(serviceProvider);
applicationValidatorManager.validateSPConfigurations(serviceProvider, tenantDomain, CarbonContext.getThreadLocalCarbonContext().getUsername());
Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
for (ApplicationMgtListener listener : listeners) {
if (listener.isEnable()) {
listener.doPreUpdateApplicationTemplate(serviceProvider, tenantDomain);
}
}
doUpdateApplicationTemplate(oldTemplateName, spTemplate, tenantDomain);
} catch (IdentityApplicationManagementValidationException e) {
log.error("Validation error when updating the application template: " + oldTemplateName + " in:" + tenantDomain);
logValidationErrorMessages(e);
throw new IdentityApplicationManagementClientException(e.getValidationMsg());
} catch (IdentityApplicationManagementException e) {
String errorMsg = String.format("Error in updating the application template: %s in tenant: %s", oldTemplateName, tenantDomain);
throw new IdentityApplicationManagementException(errorMsg, e);
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getDiscoverableApplicationBasicInfoByResourceId.
@Override
public ApplicationBasicInfo getDiscoverableApplicationBasicInfoByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Getting application basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain + " if discoverable.");
}
ApplicationBasicInfo applicationBasicInfo = null;
boolean isDiscoverable = false;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, LOAD_APP_BY_TENANT_AND_UUID)) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setString(ApplicationTableColumns.UUID, resourceId);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
applicationBasicInfo = buildApplicationBasicInfo(resultSet);
isDiscoverable = getBooleanValue(resultSet.getString(ApplicationTableColumns.IS_DISCOVERABLE));
}
}
}
} catch (SQLException e) {
throw new IdentityApplicationManagementServerException("Error while getting discoverable application " + "basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, e);
}
if (applicationBasicInfo != null && !isDiscoverable) {
throw new IdentityApplicationManagementClientException(APPLICATION_NOT_DISCOVERABLE.getCode(), "Requested application resource " + resourceId + " is not discoverable.");
}
return applicationBasicInfo;
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method addApplication.
public String addApplication(ServiceProvider application, String tenantDomain) throws IdentityApplicationManagementException {
Connection connection = IdentityDatabaseUtil.getDBConnection(true);
try {
// Create basic application.
ApplicationCreateResult result = persistBasicApplicationInformation(connection, application, tenantDomain);
int applicationId = result.getApplicationId();
String resourceId = result.getApplicationResourceId();
if (log.isDebugEnabled()) {
log.debug("Application with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain + " has been created with appId: " + applicationId + " and resourceId: " + resourceId);
}
// Before calling update we set the appId and resourceId to the application.
application.setApplicationID(applicationId);
application.setApplicationResourceId(resourceId);
addApplicationConfigurations(connection, application, tenantDomain);
IdentityDatabaseUtil.commitTransaction(connection);
return resourceId;
} catch (SQLException | UserStoreException | IdentityApplicationManagementException e) {
log.error("Error while creating the application with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain + ". Rolling back created application information.");
IdentityDatabaseUtil.rollbackTransaction(connection);
if (isApplicationConflict(e)) {
throw new IdentityApplicationManagementClientException(APPLICATION_ALREADY_EXISTS.getCode(), "Application already exists with name: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain);
}
throw new IdentityApplicationManagementException("Error while creating an application: " + application.getApplicationName() + " in tenantDomain: " + tenantDomain, e);
} finally {
IdentityDatabaseUtil.closeConnection(connection);
}
}
Aggregations