Search in sources :

Example 36 with ServiceProvider

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

the class ApplicationDAOImpl method loadApplicationPermissions.

private void loadApplicationPermissions(String serviceProviderName, ServiceProvider serviceProvider) throws IdentityApplicationManagementException {
    try {
        ApplicationMgtUtil.startTenantFlow(serviceProvider.getOwner().getTenantDomain());
        List<ApplicationPermission> permissionList = ApplicationMgtUtil.loadPermissions(serviceProviderName);
        if (permissionList != null) {
            PermissionsAndRoleConfig permissionAndRoleConfig;
            if (serviceProvider.getPermissionAndRoleConfig() == null) {
                permissionAndRoleConfig = new PermissionsAndRoleConfig();
            } else {
                permissionAndRoleConfig = serviceProvider.getPermissionAndRoleConfig();
            }
            permissionAndRoleConfig.setPermissions(permissionList.toArray(new ApplicationPermission[0]));
            serviceProvider.setPermissionAndRoleConfig(permissionAndRoleConfig);
        }
    } finally {
        ApplicationMgtUtil.endTenantFlow();
    }
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) ApplicationPermission(org.wso2.carbon.identity.application.common.model.ApplicationPermission)

Example 37 with ServiceProvider

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

the class ApplicationDAOImpl method createApplication.

/**
 * Stores basic application information and meta-data such as the application name, creator and
 * tenant.
 *
 * @param application
 * @throws IdentityApplicationManagementException
 */
@Override
public int createApplication(ServiceProvider application, String tenantDomain) throws IdentityApplicationManagementException {
    Connection connection = IdentityDatabaseUtil.getDBConnection(true);
    try {
        ApplicationCreateResult result = persistBasicApplicationInformation(connection, application, tenantDomain);
        IdentityDatabaseUtil.commitTransaction(connection);
        return result.getApplicationId();
    } catch (SQLException e) {
        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 Application", e);
    } finally {
        IdentityApplicationManagementUtil.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)

Example 38 with ServiceProvider

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

the class ApplicationMgtUtil method getApplicationFromSpFileStream.

/**
 * Get Service provider name from XML configuration file
 *
 * @param spFileStream
 * @param tenantDomain
 * @return ServiceProvider
 * @throws IdentityApplicationManagementException
 */
public static ServiceProvider getApplicationFromSpFileStream(SpFileStream spFileStream, String tenantDomain) throws IdentityApplicationManagementException {
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ServiceProvider.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        return (ServiceProvider) unmarshaller.unmarshal(spFileStream.getFileStream());
    } catch (JAXBException e) {
        throw new IdentityApplicationManagementException(String.format("Error in reading Service Provider " + "configuration file %s uploaded by tenant: %s", spFileStream.getFileName(), tenantDomain), e);
    }
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) JAXBException(javax.xml.bind.JAXBException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 39 with ServiceProvider

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

the class ApplicationMgtUtil method isValidApplicationOwner.

/**
 * To check whether the application owner is valid by validating user existence and permissions.
 *
 * @param serviceProvider service provider
 * @return true if the application owner is valid.
 * @throws IdentityApplicationManagementException when an error occurs while validating the user.
 */
public static boolean isValidApplicationOwner(ServiceProvider serviceProvider) throws IdentityApplicationManagementException {
    try {
        String userName;
        String userNameWithDomain;
        if (serviceProvider.getOwner() != null) {
            userName = serviceProvider.getOwner().getUserName();
            if (StringUtils.isEmpty(userName) || CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(userName)) {
                return false;
            }
            String userStoreDomain = serviceProvider.getOwner().getUserStoreDomain();
            userNameWithDomain = IdentityUtil.addDomainToName(userName, userStoreDomain);
            org.wso2.carbon.user.api.UserRealm realm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
            if (realm == null || StringUtils.isEmpty(userNameWithDomain)) {
                return false;
            }
            boolean isUserExist = realm.getUserStoreManager().isExistingUser(userNameWithDomain);
            if (!isUserExist) {
                if (log.isDebugEnabled()) {
                    log.debug("Owner does not exist for application: " + serviceProvider.getApplicationName() + ". Hence making the tenant admin the owner of the application.");
                }
                // Since the SP owner does not exist, set the tenant admin user as the owner.
                User owner = new User();
                owner.setUserName(realm.getRealmConfiguration().getAdminUserName());
                owner.setUserStoreDomain(realm.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME));
                owner.setTenantDomain(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
                serviceProvider.setOwner(owner);
            }
        } else {
            return false;
        }
    } catch (UserStoreException e) {
        throw new IdentityApplicationManagementException("User validation failed for owner update in the " + "application: " + serviceProvider.getApplicationName(), e);
    }
    return true;
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 40 with ServiceProvider

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

the class CacheBackedApplicationDAO method getAllRequestedClaimsByServiceProvider.

public List<String> getAllRequestedClaimsByServiceProvider(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider applicationFromCache = getApplicationFromCache(serviceProviderName, tenantDomain);
    if (applicationFromCache != null) {
        List<String> requestedLocalClaims = new ArrayList<>();
        ClaimConfig claimConfig = applicationFromCache.getClaimConfig();
        ClaimMapping[] claimMappings = claimConfig.getClaimMappings();
        for (ClaimMapping claimMapping : claimMappings) {
            if (claimMapping.isRequested()) {
                requestedLocalClaims.add(claimMapping.getLocalClaim().getClaimUri());
            }
        }
        return requestedLocalClaims;
    }
    return appDAO.getAllRequestedClaimsByServiceProvider(serviceProviderName, tenantDomain);
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ArrayList(java.util.ArrayList)

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