use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method buildSkipLogoutConsentProperty.
private ServiceProviderProperty buildSkipLogoutConsentProperty(ServiceProvider sp) {
ServiceProviderProperty skipLogoutConsentProperty = new ServiceProviderProperty();
skipLogoutConsentProperty.setName(SKIP_LOGOUT_CONSENT);
skipLogoutConsentProperty.setDisplayName(SKIP_LOGOUT_CONSENT_DISPLAY_NAME);
skipLogoutConsentProperty.setValue(String.valueOf(sp.getLocalAndOutBoundAuthenticationConfig().isSkipLogoutConsent()));
return skipLogoutConsentProperty;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getApplication.
@Override
public ServiceProvider getApplication(String applicationName, String tenantDomain) throws IdentityApplicationManagementException {
int applicationId = getApplicationIdByName(applicationName, tenantDomain);
if (isApplicationNotFound(applicationId) && LOCAL_SP.equals(applicationName)) {
// Looking for the resident sp. Create the resident sp for the tenant.
if (log.isDebugEnabled()) {
log.debug("The application: " + applicationName + " trying to retrieve is not available, which is" + " identified as the Local Service Provider. Therefore, creating the application: " + applicationName);
}
ServiceProvider localServiceProvider = new ServiceProvider();
localServiceProvider.setApplicationName(applicationName);
localServiceProvider.setDescription("Local Service Provider");
applicationId = createServiceProvider(tenantDomain, localServiceProvider);
}
return getApplication(applicationId);
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method updateBasicApplicationData.
/**
* @param serviceProvider
* @param connection
* @throws SQLException
* @throws UserStoreException
* @throws IdentityApplicationManagementException
*/
private void updateBasicApplicationData(ServiceProvider serviceProvider, Connection connection) throws SQLException, UserStoreException, IdentityApplicationManagementException {
int applicationId = serviceProvider.getApplicationID();
String applicationName = serviceProvider.getApplicationName();
String description = serviceProvider.getDescription();
boolean isSaasApp = serviceProvider.isSaasApp();
boolean isDiscoverable = serviceProvider.isDiscoverable();
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
String storedAppName = null;
if (applicationName == null) {
// check for required attributes.
throw new IdentityApplicationManagementException("Application Name is required.");
}
if (log.isDebugEnabled()) {
log.debug("Updating Application with id: " + applicationId);
}
// reads back the Application Name. This is to check if the Application
// has been renamed
storedAppName = getApplicationName(applicationId, connection);
if (log.isDebugEnabled()) {
log.debug("Stored application name for id: " + applicationId + " is " + storedAppName);
}
boolean validateRoles = ApplicationMgtUtil.validateRoles();
// only if the application has been renamed TODO: move to OSGi layer
if (!StringUtils.equals(applicationName, storedAppName) && validateRoles) {
String applicationNameforRole = IdentityUtil.addDomainToName(applicationName, ApplicationConstants.APPLICATION_DOMAIN);
String storedAppNameforRole = IdentityUtil.addDomainToName(storedAppName, ApplicationConstants.APPLICATION_DOMAIN);
// rename the role
ApplicationMgtUtil.renameRole(storedAppNameforRole, applicationNameforRole);
if (log.isDebugEnabled()) {
log.debug("Renaming application role from " + storedAppName + " to " + applicationName);
}
Map<String, String> applicationPermissions = readApplicationPermissions(storedAppName);
for (Map.Entry<String, String> entry : applicationPermissions.entrySet()) {
updatePermissionPath(entry.getKey(), entry.getValue().replace(storedAppName.toLowerCase(), applicationName.toLowerCase()));
}
}
boolean isValidUserForOwnerUpdate = ApplicationMgtUtil.isValidApplicationOwner(serviceProvider);
String sql;
if (isValidUserForOwnerUpdate) {
sql = UPDATE_BASIC_APPINFO_WITH_OWNER_UPDATE;
} else {
sql = UPDATE_BASIC_APPINFO;
}
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, sql)) {
statement.setString(ApplicationTableColumns.APP_NAME, applicationName);
statement.setString(ApplicationTableColumns.DESCRIPTION, description);
statement.setString(ApplicationTableColumns.IS_SAAS_APP, isSaasApp ? "1" : "0");
statement.setString(ApplicationTableColumns.IS_DISCOVERABLE, isDiscoverable ? "1" : "0");
statement.setString(ApplicationTableColumns.IMAGE_URL, serviceProvider.getImageUrl());
statement.setString(ApplicationTableColumns.ACCESS_URL, serviceProvider.getAccessUrl());
if (isValidUserForOwnerUpdate) {
User owner = serviceProvider.getOwner();
statement.setString(ApplicationTableColumns.USERNAME, owner.getUserName());
statement.setString(ApplicationTableColumns.USER_STORE, owner.getUserStoreDomain());
}
statement.setInt(ApplicationTableColumns.TENANT_ID, tenantID);
statement.setInt(ApplicationTableColumns.ID, applicationId);
statement.executeUpdate();
}
if (log.isDebugEnabled()) {
String tenantDomain = IdentityTenantUtil.getTenantDomain(tenantID);
log.debug("Application with name: " + applicationName + " , id: " + applicationId + " in tenantDomain: " + tenantDomain + " updated successfully.");
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method updateApplication.
@Override
public void updateApplication(ServiceProvider serviceProvider, String tenantDomain) throws IdentityApplicationManagementException {
int applicationId = serviceProvider.getApplicationID();
Connection connection = IdentityDatabaseUtil.getDBConnection(true);
try {
deleteApplicationConfigurations(connection, serviceProvider, applicationId);
addApplicationConfigurations(connection, serviceProvider, tenantDomain);
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException | UserStoreException | IdentityApplicationManagementException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw new IdentityApplicationManagementException("Failed to update application id: " + applicationId, e);
} finally {
IdentityApplicationManagementUtil.closeConnection(connection);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider 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