Search in sources :

Example 31 with ServiceProvider

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;
}
Also used : ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 32 with ServiceProvider

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);
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 33 with ServiceProvider

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.");
    }
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) User(org.wso2.carbon.identity.application.common.model.User) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with ServiceProvider

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);
    }
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) Connection(java.sql.Connection) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 35 with ServiceProvider

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);
    }
}
Also used : IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) Connection(java.sql.Connection) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19