Search in sources :

Example 16 with PermissionsAndRoleConfig

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

the class ApplicationDAOImpl method getApplication.

@Override
public ServiceProvider getApplication(int applicationId) throws IdentityApplicationManagementException {
    Connection connection = IdentityDatabaseUtil.getDBConnection(false);
    try {
        // Load basic application data
        ServiceProvider serviceProvider = getBasicApplicationData(applicationId, connection);
        if (serviceProvider == null) {
            return null;
        }
        int tenantID = IdentityTenantUtil.getTenantId(serviceProvider.getOwner().getTenantDomain());
        List<ServiceProviderProperty> propertyList = getServicePropertiesBySpId(connection, applicationId);
        serviceProvider.setJwksUri(getJwksUri(propertyList));
        serviceProvider.setTemplateId(getTemplateId(propertyList));
        serviceProvider.setInboundAuthenticationConfig(getInboundAuthenticationConfig(applicationId, connection, tenantID));
        serviceProvider.setLocalAndOutBoundAuthenticationConfig(getLocalAndOutboundAuthenticationConfig(applicationId, connection, tenantID, propertyList));
        serviceProvider.setInboundProvisioningConfig(getInboundProvisioningConfiguration(applicationId, connection, tenantID));
        serviceProvider.setOutboundProvisioningConfig(getOutboundProvisioningConfiguration(applicationId, connection, tenantID));
        // Load Claim Mapping
        serviceProvider.setClaimConfig(getClaimConfiguration(applicationId, connection, tenantID));
        // Load Role Mappings
        List<RoleMapping> roleMappings = getRoleMappingOfApplication(applicationId, connection, tenantID);
        PermissionsAndRoleConfig permissionAndRoleConfig = new PermissionsAndRoleConfig();
        permissionAndRoleConfig.setRoleMappings(roleMappings.toArray(new RoleMapping[0]));
        serviceProvider.setPermissionAndRoleConfig(permissionAndRoleConfig);
        RequestPathAuthenticatorConfig[] requestPathAuthenticators = getRequestPathAuthenticators(applicationId, connection, tenantID);
        serviceProvider.setRequestPathAuthenticatorConfigs(requestPathAuthenticators);
        serviceProvider.setSpProperties(propertyList.toArray(new ServiceProviderProperty[0]));
        serviceProvider.setCertificateContent(getCertificateContent(propertyList, connection));
        // Will be supported with 'Advance Consent Management Feature'.
        /*
            ConsentConfig consentConfig = serviceProvider.getConsentConfig();
            if (isNull(consentConfig)) {
                consentConfig = new ConsentConfig();
            }
            consentConfig.setConsentPurposeConfigs(getConsentPurposeConfigs(connection, applicationId, tenantID));
            serviceProvider.setConsentConfig(consentConfig);
            */
        String serviceProviderName = serviceProvider.getApplicationName();
        loadApplicationPermissions(serviceProviderName, serviceProvider);
        return serviceProvider;
    } catch (SQLException | CertificateRetrievingException e) {
        throw new IdentityApplicationManagementException("Failed to get service provider with 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) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) CertificateRetrievingException(org.wso2.carbon.identity.core.CertificateRetrievingException) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.ServiceProviderProperty)

Example 17 with PermissionsAndRoleConfig

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

the class ApplicationBean method update.

/**
 * @param request
 */
public void update(HttpServletRequest request) {
    // update basic info.
    serviceProvider.setApplicationName(request.getParameter("spName"));
    serviceProvider.setDescription(request.getParameter("sp-description"));
    serviceProvider.setCertificateContent(request.getParameter("sp-certificate"));
    String jwks = request.getParameter("jwksUri");
    serviceProvider.setJwksUri(jwks);
    if (Boolean.parseBoolean(request.getParameter("deletePublicCert"))) {
        serviceProvider.setCertificateContent("");
    }
    String isSasApp = request.getParameter("isSaasApp");
    serviceProvider.setSaasApp((isSasApp != null && "on".equals(isSasApp)) ? true : false);
    String isDiscoverableApp = request.getParameter("isDiscoverableApp");
    serviceProvider.setDiscoverable("on".equals(isDiscoverableApp));
    String accessUrl = request.getParameter("accessURL");
    serviceProvider.setAccessUrl(accessUrl);
    String imageUrl = request.getParameter("imageURL");
    serviceProvider.setImageUrl(imageUrl);
    String logoutReturnUrl = request.getParameter(LOGOUT_RETURN_URL);
    if (StringUtils.isNotBlank(logoutReturnUrl)) {
        boolean logoutReturnUrlDefined = false;
        if (serviceProvider.getSpProperties() != null) {
            for (ServiceProviderProperty property : serviceProvider.getSpProperties()) {
                if (property.getName() != null && LOGOUT_RETURN_URL.equals(property.getName())) {
                    property.setValue(logoutReturnUrl);
                    logoutReturnUrlDefined = true;
                    break;
                }
            }
        }
        if (!logoutReturnUrlDefined) {
            ServiceProviderProperty property = new ServiceProviderProperty();
            property.setName(LOGOUT_RETURN_URL);
            property.setDisplayName("Logout Return URL");
            property.setValue(logoutReturnUrl);
            serviceProvider.addSpProperties(property);
        }
    }
    if (serviceProvider.getLocalAndOutBoundAuthenticationConfig() == null) {
        // create fresh one.
        serviceProvider.setLocalAndOutBoundAuthenticationConfig(new LocalAndOutboundAuthenticationConfig());
    }
    // authentication type : default, local, federated or advanced.
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationType(request.getParameter("auth_type"));
    // update inbound provisioning data.
    String provisioningUserStore = request.getParameter("scim-inbound-userstore");
    InboundProvisioningConfig inBoundProConfig = new InboundProvisioningConfig();
    inBoundProConfig.setProvisioningUserStore(provisioningUserStore);
    inBoundProConfig.setDumbMode(Boolean.parseBoolean(request.getParameter(DUMB)));
    serviceProvider.setInboundProvisioningConfig(inBoundProConfig);
    // update outbound provisioning data.
    String[] provisioningProviders = request.getParameterValues("provisioning_idp");
    if (provisioningProviders != null && provisioningProviders.length > 0) {
        List<IdentityProvider> provisioningIdps = new ArrayList<IdentityProvider>();
        for (String proProvider : provisioningProviders) {
            String connector = request.getParameter("provisioning_con_idp_" + proProvider);
            String jitEnabled = request.getParameter("provisioning_jit_" + proProvider);
            String blocking = request.getParameter("blocking_prov_" + proProvider);
            String ruleEnabled = request.getParameter("rules_enabled_" + proProvider);
            if (connector != null) {
                IdentityProvider proIdp = new IdentityProvider();
                proIdp.setIdentityProviderName(proProvider);
                JustInTimeProvisioningConfig jitpro = new JustInTimeProvisioningConfig();
                if ("on".equals(jitEnabled)) {
                    jitpro.setProvisioningEnabled(true);
                }
                proIdp.setJustInTimeProvisioningConfig(jitpro);
                ProvisioningConnectorConfig proCon = new ProvisioningConnectorConfig();
                if ("on".equals(ruleEnabled)) {
                    proCon.setRulesEnabled(true);
                } else {
                    proCon.setRulesEnabled(false);
                }
                if ("on".equals(blocking)) {
                    proCon.setBlocking(true);
                } else {
                    proCon.setBlocking(false);
                }
                proCon.setName(connector);
                proIdp.setDefaultProvisioningConnectorConfig(proCon);
                provisioningIdps.add(proIdp);
            }
        }
        if (CollectionUtils.isNotEmpty(provisioningIdps)) {
            OutboundProvisioningConfig outboundProConfig = new OutboundProvisioningConfig();
            outboundProConfig.setProvisioningIdentityProviders(provisioningIdps.toArray(new IdentityProvider[provisioningIdps.size()]));
            serviceProvider.setOutboundProvisioningConfig(outboundProConfig);
        }
    } else {
        serviceProvider.setOutboundProvisioningConfig(new OutboundProvisioningConfig());
    }
    // get all request-path authenticators.
    String[] requestPathAuthenticators = request.getParameterValues("req_path_auth");
    if (requestPathAuthenticators != null && requestPathAuthenticators.length > 0) {
        List<RequestPathAuthenticatorConfig> reqAuthList = new ArrayList<RequestPathAuthenticatorConfig>();
        for (String name : requestPathAuthenticators) {
            if (name != null) {
                RequestPathAuthenticatorConfig reqAuth = new RequestPathAuthenticatorConfig();
                reqAuth.setName(name);
                reqAuth.setDisplayName(request.getParameter("req_path_auth_" + name));
                reqAuthList.add(reqAuth);
            }
        }
        if (CollectionUtils.isNotEmpty(reqAuthList)) {
            serviceProvider.setRequestPathAuthenticatorConfigs(reqAuthList.toArray(new RequestPathAuthenticatorConfig[reqAuthList.size()]));
        } else {
            serviceProvider.setRequestPathAuthenticatorConfigs(null);
        }
    } else {
        serviceProvider.setRequestPathAuthenticatorConfigs(null);
    }
    List<InboundAuthenticationRequestConfig> authRequestList = new ArrayList<InboundAuthenticationRequestConfig>();
    if (samlIssuer != null) {
        InboundAuthenticationRequestConfig samlAuthenticationRequest = new InboundAuthenticationRequestConfig();
        samlAuthenticationRequest.setInboundAuthKey(samlIssuer);
        samlAuthenticationRequest.setInboundAuthType("samlsso");
        if (attrConsumServiceIndex != null && !attrConsumServiceIndex.isEmpty()) {
            Property property = new Property();
            property.setName("attrConsumServiceIndex");
            property.setValue(attrConsumServiceIndex);
            Property[] properties = { property };
            samlAuthenticationRequest.setProperties(properties);
        }
        authRequestList.add(samlAuthenticationRequest);
    }
    if (kerberosServiceName != null) {
        InboundAuthenticationRequestConfig kerberosAuthenticationRequest = new InboundAuthenticationRequestConfig();
        kerberosAuthenticationRequest.setInboundAuthKey(kerberosServiceName);
        kerberosAuthenticationRequest.setInboundAuthType("kerberos");
        authRequestList.add(kerberosAuthenticationRequest);
    }
    if (oauthAppName != null) {
        InboundAuthenticationRequestConfig opicAuthenticationRequest = new InboundAuthenticationRequestConfig();
        opicAuthenticationRequest.setInboundAuthKey(oauthAppName);
        opicAuthenticationRequest.setInboundAuthType("oauth2");
        if (oauthConsumerSecret != null && !oauthConsumerSecret.isEmpty()) {
            Property property = new Property();
            property.setName("oauthConsumerSecret");
            property.setValue(oauthConsumerSecret);
            Property[] properties = { property };
            opicAuthenticationRequest.setProperties(properties);
        }
        authRequestList.add(opicAuthenticationRequest);
    }
    if (CollectionUtils.isNotEmpty(wstrustEp)) {
        wstrustEp.forEach(entry -> {
            InboundAuthenticationRequestConfig opicAuthenticationRequest = new InboundAuthenticationRequestConfig();
            opicAuthenticationRequest.setInboundAuthKey(entry);
            opicAuthenticationRequest.setInboundAuthType("wstrust");
            authRequestList.add(opicAuthenticationRequest);
        });
    }
    String passiveSTSRealm = request.getParameter("passiveSTSRealm");
    String passiveSTSWReply = request.getParameter("passiveSTSWReply");
    if (StringUtils.isNotBlank(passiveSTSRealm)) {
        InboundAuthenticationRequestConfig opicAuthenticationRequest = new InboundAuthenticationRequestConfig();
        opicAuthenticationRequest.setInboundAuthKey(passiveSTSRealm);
        opicAuthenticationRequest.setInboundAuthType("passivests");
        if (passiveSTSWReply != null && !passiveSTSWReply.isEmpty()) {
            Property property = new Property();
            property.setName("passiveSTSWReply");
            property.setValue(passiveSTSWReply);
            Property[] properties = { property };
            opicAuthenticationRequest.setProperties(properties);
        }
        authRequestList.add(opicAuthenticationRequest);
    }
    String openidRealm = request.getParameter("openidRealm");
    if (StringUtils.isNotBlank(openidRealm)) {
        InboundAuthenticationRequestConfig opicAuthenticationRequest = new InboundAuthenticationRequestConfig();
        opicAuthenticationRequest.setInboundAuthKey(openidRealm);
        opicAuthenticationRequest.setInboundAuthType("openid");
        authRequestList.add(opicAuthenticationRequest);
    }
    if (!CollectionUtils.isEmpty(inboundAuthenticationRequestConfigs)) {
        for (InboundAuthenticationRequestConfig customAuthConfig : inboundAuthenticationRequestConfigs) {
            String type = customAuthConfig.getInboundAuthType();
            Property[] properties = customAuthConfig.getProperties();
            if (!ArrayUtils.isEmpty(properties)) {
                for (Property prop : properties) {
                    String propVal = request.getParameter("custom_auth_prop_name_" + type + "_" + prop.getName());
                    prop.setValue(propVal);
                }
            }
            authRequestList.add(customAuthConfig);
        }
    }
    if (serviceProvider.getInboundAuthenticationConfig() == null) {
        serviceProvider.setInboundAuthenticationConfig(new InboundAuthenticationConfig());
    }
    if (CollectionUtils.isNotEmpty(authRequestList)) {
        serviceProvider.getInboundAuthenticationConfig().setInboundAuthenticationRequestConfigs(authRequestList.toArray(new InboundAuthenticationRequestConfig[authRequestList.size()]));
    }
    // update local and out-bound authentication.
    if (AUTH_TYPE_DEFAULT.equalsIgnoreCase(serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationType())) {
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(null);
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(null);
    } else if (AUTH_TYPE_LOCAL.equalsIgnoreCase(serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationType())) {
        AuthenticationStep authStep = new AuthenticationStep();
        LocalAuthenticatorConfig localAuthenticator = new LocalAuthenticatorConfig();
        localAuthenticator.setName(request.getParameter("local_authenticator"));
        if (localAuthenticator.getName() != null && localAuthenticatorConfigs != null) {
            for (LocalAuthenticatorConfig config : localAuthenticatorConfigs) {
                if (config.getName().equals(localAuthenticator.getName())) {
                    localAuthenticator.setDisplayName(config.getDisplayName());
                    break;
                }
            }
        }
        authStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localAuthenticator });
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(new AuthenticationStep[] { authStep });
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(null);
    } else if (AUTH_TYPE_FEDERATED.equalsIgnoreCase(serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationType())) {
        AuthenticationStep authStep = new AuthenticationStep();
        IdentityProvider idp = new IdentityProvider();
        idp.setIdentityProviderName(request.getParameter("fed_idp"));
        authStep.setFederatedIdentityProviders(new IdentityProvider[] { idp });
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationSteps(new AuthenticationStep[] { authStep });
        serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAuthenticationScriptConfig(null);
    } else if (AUTH_TYPE_FLOW.equalsIgnoreCase(serviceProvider.getLocalAndOutBoundAuthenticationConfig().getAuthenticationType())) {
    // already updated.
    }
    String alwaysSendAuthListOfIdPs = request.getParameter("always_send_auth_list_of_idps");
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setAlwaysSendBackAuthenticatedListOfIdPs(alwaysSendAuthListOfIdPs != null && "on".equals(alwaysSendAuthListOfIdPs) ? true : false);
    String useTenantDomainInLocalSubjectIdentifier = request.getParameter("use_tenant_domain_in_local_subject_identifier");
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setUseTenantDomainInLocalSubjectIdentifier(useTenantDomainInLocalSubjectIdentifier != null && "on".equals(useTenantDomainInLocalSubjectIdentifier) ? true : false);
    String useUserstoreDomainInLocalSubjectIdentifier = request.getParameter("use_userstore_domain_in_local_subject_identifier");
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setUseUserstoreDomainInLocalSubjectIdentifier(useUserstoreDomainInLocalSubjectIdentifier != null && "on".equals(useUserstoreDomainInLocalSubjectIdentifier) ? true : false);
    String useUserstoreDomainInRoles = request.getParameter("use_userstore_domain_in_roles");
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setUseUserstoreDomainInRoles(useUserstoreDomainInRoles != null && "on".equals(useUserstoreDomainInRoles) ? true : false);
    boolean skipConsent = Boolean.parseBoolean(request.getParameter(IdentityConstants.SKIP_CONSENT));
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setSkipConsent(skipConsent);
    boolean skipLogoutConsent = Boolean.parseBoolean(request.getParameter(IdentityConstants.SKIP_LOGOUT_CONSENT));
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setSkipLogoutConsent(skipLogoutConsent);
    String enableAuthorization = request.getParameter("enable_authorization");
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setEnableAuthorization(enableAuthorization != null && "on".equals(enableAuthorization));
    String subjectClaimUri = request.getParameter("subject_claim_uri");
    serviceProvider.getLocalAndOutBoundAuthenticationConfig().setSubjectClaimUri((subjectClaimUri != null && !subjectClaimUri.isEmpty()) ? subjectClaimUri : null);
    // update application permissions.
    PermissionsAndRoleConfig permAndRoleConfig = new PermissionsAndRoleConfig();
    String[] permissions = request.getParameterValues("app_permission");
    List<ApplicationPermission> appPermList = new ArrayList<ApplicationPermission>();
    if (permissions != null && permissions.length > 0) {
        for (String permission : permissions) {
            if (permission != null && !permission.trim().isEmpty()) {
                ApplicationPermission appPermission = new ApplicationPermission();
                appPermission.setValue(permission);
                appPermList.add(appPermission);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(appPermList)) {
        permAndRoleConfig.setPermissions(appPermList.toArray(new ApplicationPermission[appPermList.size()]));
    }
    // update role mapping.
    int roleMappingCount = Integer.parseInt(request.getParameter("number_of_rolemappings"));
    List<RoleMapping> roleMappingList = new ArrayList<RoleMapping>();
    for (int i = 0; i < roleMappingCount; i++) {
        RoleMapping mapping = new RoleMapping();
        LocalRole localRole = new LocalRole();
        localRole.setLocalRoleName(request.getParameter("idpRole_" + i));
        mapping.setLocalRole(localRole);
        mapping.setRemoteRole(request.getParameter("spRole_" + i));
        if (mapping.getLocalRole() != null && mapping.getRemoteRole() != null) {
            roleMappingList.add(mapping);
        }
    }
    permAndRoleConfig.setRoleMappings(roleMappingList.toArray(new RoleMapping[roleMappingList.size()]));
    serviceProvider.setPermissionAndRoleConfig(permAndRoleConfig);
    if (serviceProvider.getClaimConfig() == null) {
        serviceProvider.setClaimConfig(new ClaimConfig());
    }
    if (request.getParameter("claim_dialect") != null && "custom".equals(request.getParameter("claim_dialect"))) {
        serviceProvider.getClaimConfig().setLocalClaimDialect(false);
    } else {
        serviceProvider.getClaimConfig().setLocalClaimDialect(true);
    }
    // update claim configuration.
    int claimCount = Integer.parseInt(request.getParameter("number_of_claim_mappings"));
    List<ClaimMapping> claimMappingList = new ArrayList<ClaimMapping>();
    for (int i = 0; i < claimCount; i++) {
        ClaimMapping mapping = new ClaimMapping();
        Claim localClaim = new Claim();
        localClaim.setClaimUri(request.getParameter("idpClaim_" + i));
        Claim spClaim = new Claim();
        spClaim.setClaimUri(request.getParameter("spClaim_" + i));
        String requested = request.getParameter("spClaim_req_" + i);
        if (requested != null && "on".equals(requested)) {
            mapping.setRequested(true);
        } else {
            mapping.setRequested(false);
        }
        String mandatory = request.getParameter("spClaim_mand_" + i);
        if (mandatory != null && "on".equals(mandatory)) {
            mapping.setMandatory(true);
        } else {
            mapping.setMandatory(false);
        }
        mapping.setLocalClaim(localClaim);
        mapping.setRemoteClaim(spClaim);
        if (isLocalClaimsSelected() || mapping.getRemoteClaim().getClaimUri() == null || mapping.getRemoteClaim().getClaimUri().isEmpty()) {
            mapping.getRemoteClaim().setClaimUri(mapping.getLocalClaim().getClaimUri());
        }
        if (mapping.getLocalClaim().getClaimUri() != null && mapping.getRemoteClaim().getClaimUri() != null) {
            claimMappingList.add(mapping);
        }
    }
    String spClaimDialectParam = request.getParameter(ApplicationMgtUIConstants.Params.SP_CLAIM_DIALECT);
    String[] spClaimDialects = null;
    if (StringUtils.isNotBlank(spClaimDialectParam)) {
        spClaimDialects = spClaimDialectParam.split(",");
    }
    serviceProvider.getClaimConfig().setSpClaimDialects(spClaimDialects);
    serviceProvider.getClaimConfig().setClaimMappings(claimMappingList.toArray(new ClaimMapping[claimMappingList.size()]));
    serviceProvider.getClaimConfig().setRoleClaimURI(request.getParameter("roleClaim"));
    String alwaysSendMappedLocalSubjectId = request.getParameter("always_send_local_subject_id");
    serviceProvider.getClaimConfig().setAlwaysSendMappedLocalSubjectId(alwaysSendMappedLocalSubjectId != null && "on".equals(alwaysSendMappedLocalSubjectId) ? true : false);
}
Also used : InboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundProvisioningConfig) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig) ArrayList(java.util.ArrayList) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig) OutboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.xsd.OutboundProvisioningConfig) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.xsd.PermissionsAndRoleConfig) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.RequestPathAuthenticatorConfig) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty) ServiceProviderProperty(org.wso2.carbon.identity.application.common.model.xsd.ServiceProviderProperty) Property(org.wso2.carbon.identity.application.common.model.xsd.Property) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.xsd.ProvisioningConnectorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.xsd.IdentityProvider) RoleMapping(org.wso2.carbon.identity.application.common.model.xsd.RoleMapping) ApplicationPermission(org.wso2.carbon.identity.application.common.model.xsd.ApplicationPermission) ClaimMapping(org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.xsd.ClaimConfig) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.xsd.JustInTimeProvisioningConfig) LocalRole(org.wso2.carbon.identity.application.common.model.xsd.LocalRole) Claim(org.wso2.carbon.identity.application.common.model.xsd.Claim)

Example 18 with PermissionsAndRoleConfig

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

the class ApplicationManagementServiceImpl method doAddApplication.

private <T> T doAddApplication(ServiceProvider serviceProvider, String tenantDomain, String username, ApplicationPersistFunction<ServiceProvider, T> applicationPersistFunction) throws IdentityApplicationManagementException {
    try {
        startTenantFlow(tenantDomain, username);
        String applicationName = serviceProvider.getApplicationName();
        // First we need to create a role with the application name. Only the users in this role will be able to
        // edit/update the application.
        ApplicationMgtUtil.createAppRole(applicationName, username);
        try {
            PermissionsAndRoleConfig permissionAndRoleConfig = serviceProvider.getPermissionAndRoleConfig();
            ApplicationMgtUtil.storePermissions(applicationName, username, permissionAndRoleConfig);
        } catch (IdentityApplicationManagementException ex) {
            if (log.isDebugEnabled()) {
                log.debug("Creating application: " + applicationName + " in tenantDomain: " + tenantDomain + " failed. Rolling back by cleaning up partially created data.");
            }
            deleteApplicationRole(applicationName);
            throw ex;
        }
        try {
            return applicationPersistFunction.persistApplication(serviceProvider, tenantDomain);
        } catch (IdentityApplicationManagementException ex) {
            if (isRollbackRequired(ex)) {
                if (log.isDebugEnabled()) {
                    log.debug("Creating application: " + applicationName + " in tenantDomain: " + tenantDomain + " failed. Rolling back by cleaning up partially created data.");
                }
                deleteApplicationRole(applicationName);
                deleteApplicationPermission(applicationName);
            }
            throw ex;
        }
    } finally {
        endTenantFlow();
    }
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)

Example 19 with PermissionsAndRoleConfig

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

the class IdPManagementDAOTest method testGetPermissionsAndRoleConfiguration.

@Test(dataProvider = "getPermissionsAndRoleConfigurationData")
public void testGetPermissionsAndRoleConfiguration(String idpName, int idpId, int tenantId, int resultCount) throws Exception {
    mockStatic(IdentityDatabaseUtil.class);
    try (Connection connection = getConnection(DB_NAME)) {
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection);
        when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
        when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSourceMap.get(DB_NAME));
        addTestIdps();
        PermissionsAndRoleConfig pac = idPManagementDAO.getPermissionsAndRoleConfiguration(connection, idpName, idpId, tenantId);
        assertEquals(pac.getIdpRoles().length, resultCount);
    }
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) Connection(java.sql.Connection) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with PermissionsAndRoleConfig

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

the class IdentityProviderManagementServiceTest method updateIdPData.

@DataProvider
public Object[][] updateIdPData() {
    // Initialize New Test Identity Provider 1.
    IdentityProvider idp1New = new IdentityProvider();
    idp1New.setIdentityProviderName("testIdP1New");
    idp1New.setEnable(true);
    idp1New.setPrimary(true);
    idp1New.setFederationHub(true);
    idp1New.setCertificate("");
    RoleMapping newRoleMapping1 = new RoleMapping();
    newRoleMapping1.setRemoteRole("Role1New");
    newRoleMapping1.setLocalRole(new LocalRole("1", "LocalRole1"));
    RoleMapping newRoleMapping2 = new RoleMapping();
    newRoleMapping2.setRemoteRole("Role2New");
    newRoleMapping2.setLocalRole(new LocalRole("2", "LocalRole2"));
    PermissionsAndRoleConfig newPermissionsAndRoleConfig = new PermissionsAndRoleConfig();
    newPermissionsAndRoleConfig.setIdpRoles(new String[] { "Role1New", "Role2New" });
    newPermissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { newRoleMapping1, newRoleMapping2 });
    idp1New.setPermissionAndRoleConfig(newPermissionsAndRoleConfig);
    FederatedAuthenticatorConfig newFederatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    newFederatedAuthenticatorConfig.setDisplayName("DisplayName1New");
    newFederatedAuthenticatorConfig.setName("Name");
    newFederatedAuthenticatorConfig.setEnabled(true);
    Property newProperty1 = new Property();
    newProperty1.setName("Property1New");
    newProperty1.setValue("value1New");
    newProperty1.setConfidential(false);
    Property newProperty2 = new Property();
    newProperty2.setName("Property2New");
    newProperty2.setValue("value2New");
    newProperty2.setConfidential(false);
    newFederatedAuthenticatorConfig.setProperties(new Property[] { newProperty1, newProperty2 });
    idp1New.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { newFederatedAuthenticatorConfig });
    ProvisioningConnectorConfig newProvisioningConnectorConfig1 = new ProvisioningConnectorConfig();
    newProvisioningConnectorConfig1.setName("ProvisiningConfig1");
    newProvisioningConnectorConfig1.setProvisioningProperties(new Property[] { newProperty1 });
    ProvisioningConnectorConfig newProvisioningConnectorConfig2 = new ProvisioningConnectorConfig();
    newProvisioningConnectorConfig2.setName("ProvisiningConfig2");
    newProvisioningConnectorConfig2.setProvisioningProperties(new Property[] { newProperty2 });
    newProvisioningConnectorConfig2.setEnabled(true);
    newProvisioningConnectorConfig2.setBlocking(true);
    idp1New.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { newProvisioningConnectorConfig1, newProvisioningConnectorConfig2 });
    ClaimConfig newClaimConfig = new ClaimConfig();
    newClaimConfig.setLocalClaimDialect(false);
    newClaimConfig.setRoleClaimURI("Country");
    newClaimConfig.setUserClaimURI("Country");
    ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimId(0);
    remoteClaim.setClaimUri("Country");
    newClaimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    newClaimConfig.setIdpClaims(new Claim[] { remoteClaim });
    idp1New.setClaimConfig(newClaimConfig);
    // Initialize New Test Identity Provider 2.
    IdentityProvider idp2New = new IdentityProvider();
    idp2New.setIdentityProviderName("testIdP2New");
    // Initialize New Test Identity Provider 3.
    IdentityProvider idp3New = new IdentityProvider();
    idp3New.setIdentityProviderName("testIdP3New");
    return new Object[][] { // IDP with PermissionsAndRoleConfig,FederatedAuthenticatorConfig,ProvisioningConnectorConfig,ClaimConf.
    { "testIdP1", idp1New }, // New IDP with Only name.
    { "testIdP2", idp2New }, // New IDP with Only name.
    { "testIdP3", idp3New } };
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) Matchers.anyObject(org.mockito.Matchers.anyObject) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) DataProvider(org.testng.annotations.DataProvider)

Aggregations

PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)20 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)16 ArrayList (java.util.ArrayList)10 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)10 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)9 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)9 Claim (org.wso2.carbon.identity.application.common.model.Claim)7 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)7 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)7 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)7 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)6 Property (org.wso2.carbon.identity.application.common.model.Property)6 DataProvider (org.testng.annotations.DataProvider)4 Test (org.testng.annotations.Test)4 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)4 HashSet (java.util.HashSet)3 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.xsd.PermissionsAndRoleConfig)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2