Search in sources :

Example 6 with IdentityProviderProperty

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

the class IdPManagementDAO method addIdPWithResourceId.

/**
 * Add IDP.
 *
 * @param identityProvider  Identity provider information.
 * @param tenantId          Tenant ID.
 * @return Resource ID of created IDP.
 * @throws IdentityProviderManagementException
 */
public String addIdPWithResourceId(IdentityProvider identityProvider, int tenantId) throws IdentityProviderManagementException {
    Connection dbConnection = IdentityDatabaseUtil.getDBConnection(true);
    PreparedStatement prepStmt = null;
    try {
        if (identityProvider.isPrimary()) {
            // this is going to be the primary. Switch off any other primary set up in the
            // system.
            switchOffPrimary(dbConnection, tenantId);
        }
        // SP_TENANT_ID, SP_IDP_NAME, SP_IDP_PRIMARY, SP_IDP_HOME_REALM_ID, SP_IDP_CERTIFICATE,
        // SP_IDP_TOKEN_EP_ALIAS,
        // SP_IDP_INBOUND_PROVISIONING_ENABLED,SP_IDP_INBOUND_PROVISIONING_USER_STORE_ID,
        // SP_IDP_USER_CLAIM_URI,SP_IDP_ROLE_CLAIM_URI,SP_IDP_DEFAULT_AUTHENTICATOR_NAME,
        // SP_IDP_DEFAULT_PRO_CONNECTOR_NAME
        String sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, identityProvider.getIdentityProviderName());
        if (identityProvider.isPrimary()) {
            prepStmt.setString(3, IdPManagementConstants.IS_TRUE_VALUE);
        } else {
            prepStmt.setString(3, IdPManagementConstants.IS_FALSE_VALUE);
        }
        prepStmt.setString(4, identityProvider.getHomeRealmId());
        if (ArrayUtils.isNotEmpty(identityProvider.getCertificateInfoArray())) {
            try {
                // Check whether certificate decoding and certificate generation fails or not.
                IdentityApplicationManagementUtil.getCertDataArray(identityProvider.getCertificateInfoArray());
            } catch (CertificateException ex) {
                throw new IdentityProviderManagementClientException("Malformed Public Certificate file has been " + "provided.", ex);
            }
        }
        JSONArray certificateInfoJsonArray = new JSONArray(identityProvider.getCertificateInfoArray());
        setBlobValue(certificateInfoJsonArray.toString(), prepStmt, 5);
        prepStmt.setString(6, identityProvider.getAlias());
        if (identityProvider.getJustInTimeProvisioningConfig() != null) {
            // provisioned locally.
            if (identityProvider.getJustInTimeProvisioningConfig().isProvisioningEnabled()) {
                prepStmt.setString(7, IdPManagementConstants.IS_TRUE_VALUE);
            } else {
                prepStmt.setString(7, IdPManagementConstants.IS_FALSE_VALUE);
            }
            // user will be provisioned to the configured user store.
            prepStmt.setString(8, identityProvider.getJustInTimeProvisioningConfig().getProvisioningUserStore());
        } else {
            prepStmt.setString(7, IdPManagementConstants.IS_FALSE_VALUE);
            prepStmt.setString(8, null);
        }
        if (identityProvider.getClaimConfig() != null) {
            // this is how we find the subject name from the authentication response.
            // this claim URI is in identity provider's own dialect.
            prepStmt.setString(9, identityProvider.getClaimConfig().getUserClaimURI());
            // this is how we find the role name from the authentication response.
            // this claim URI is in identity provider's own dialect.
            prepStmt.setString(10, identityProvider.getClaimConfig().getRoleClaimURI());
        } else {
            prepStmt.setString(9, null);
            prepStmt.setString(10, null);
        }
        if (identityProvider.getDefaultAuthenticatorConfig() != null) {
            prepStmt.setString(11, identityProvider.getDefaultAuthenticatorConfig().getName());
        } else {
            prepStmt.setString(11, null);
        }
        if (identityProvider.getDefaultProvisioningConnectorConfig() != null) {
            prepStmt.setString(12, identityProvider.getDefaultProvisioningConnectorConfig().getName());
        } else {
            prepStmt.setString(12, null);
        }
        prepStmt.setString(13, identityProvider.getIdentityProviderDescription());
        if (identityProvider.isFederationHub()) {
            prepStmt.setString(14, IdPManagementConstants.IS_TRUE_VALUE);
        } else {
            prepStmt.setString(14, IdPManagementConstants.IS_FALSE_VALUE);
        }
        if (identityProvider.getClaimConfig() != null && identityProvider.getClaimConfig().isLocalClaimDialect()) {
            prepStmt.setString(15, IdPManagementConstants.IS_TRUE_VALUE);
        } else {
            prepStmt.setString(15, IdPManagementConstants.IS_FALSE_VALUE);
        }
        prepStmt.setString(16, identityProvider.getProvisioningRole());
        // enabled by default
        prepStmt.setString(17, IdPManagementConstants.IS_TRUE_VALUE);
        prepStmt.setString(18, identityProvider.getDisplayName());
        prepStmt.setString(19, identityProvider.getImageUrl());
        String resourceId = UUID.randomUUID().toString();
        prepStmt.setString(20, resourceId);
        prepStmt.executeUpdate();
        prepStmt.clearParameters();
        // get newly added Identity provider.
        IdentityProvider createdIDP = getIDPbyResourceId(dbConnection, resourceId, tenantId, IdentityTenantUtil.getTenantDomain(tenantId));
        // get the id of the just added identity provider.
        int idPId = Integer.parseInt(createdIDP.getId());
        if (idPId <= 0) {
            String msg = "Error adding Identity Provider for tenant " + tenantId;
            throw new IdentityProviderManagementException(msg);
        }
        // add provisioning connectors.
        if (identityProvider.getProvisioningConnectorConfigs() != null && identityProvider.getProvisioningConnectorConfigs().length > 0) {
            addProvisioningConnectorConfigs(identityProvider.getProvisioningConnectorConfigs(), dbConnection, idPId, tenantId);
        }
        // add federated authenticators.
        addFederatedAuthenticatorConfigs(identityProvider.getFederatedAuthenticatorConfigs(), dbConnection, idPId, tenantId);
        // add role configuration.
        if (identityProvider.getPermissionAndRoleConfig() != null) {
            if (identityProvider.getPermissionAndRoleConfig().getIdpRoles() != null && identityProvider.getPermissionAndRoleConfig().getIdpRoles().length > 0) {
                // add roles.
                addIdPRoles(dbConnection, idPId, tenantId, identityProvider.getPermissionAndRoleConfig().getIdpRoles());
                if (identityProvider.getPermissionAndRoleConfig().getRoleMappings() != null && identityProvider.getPermissionAndRoleConfig().getRoleMappings().length > 0) {
                    // add role mappings.
                    addIdPRoleMappings(dbConnection, idPId, tenantId, identityProvider.getPermissionAndRoleConfig().getRoleMappings());
                }
            }
        }
        // add claim configuration.
        if (identityProvider.getClaimConfig() != null && identityProvider.getClaimConfig().getClaimMappings() != null && identityProvider.getClaimConfig().getClaimMappings().length > 0) {
            if (identityProvider.getClaimConfig().isLocalClaimDialect()) {
                // identity provider is using local claim dialect - we do not need to add
                // claims.
                addDefaultClaimValuesForLocalIdP(dbConnection, idPId, tenantId, identityProvider.getClaimConfig().getClaimMappings());
            } else {
                addIdPClaims(dbConnection, idPId, tenantId, identityProvider.getClaimConfig().getIdpClaims());
                addIdPClaimMappings(dbConnection, idPId, tenantId, identityProvider.getClaimConfig().getClaimMappings());
            }
        }
        IdentityProviderProperty[] idpProperties = identityProvider.getIdpProperties();
        if (IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(identityProvider.getIdentityProviderName())) {
            idpProperties = filterConnectorProperties(idpProperties, IdentityTenantUtil.getTenantDomain(tenantId)).toArray(new IdentityProviderProperty[0]);
        }
        List<IdentityProviderProperty> identityProviderProperties = getCombinedProperties(identityProvider.getJustInTimeProvisioningConfig(), idpProperties);
        identityProviderProperties.add(buildTemplateIdProperty(identityProvider));
        addIdentityProviderProperties(dbConnection, idPId, identityProviderProperties, tenantId);
        IdentityDatabaseUtil.commitTransaction(dbConnection);
        return resourceId;
    } catch (IOException e) {
        throw new IdentityProviderManagementException("An error occurred while processing content stream.", e);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new IdentityProviderManagementException("Error occurred while adding Identity Provider for tenant " + tenantId, e);
    } catch (ConnectorException e) {
        throw new IdentityProviderManagementException("An error occurred while filtering IDP properties.", e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) JSONArray(org.json.JSONArray) PreparedStatement(java.sql.PreparedStatement) CertificateException(java.security.cert.CertificateException) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IOException(java.io.IOException) IdentityProviderManagementClientException(org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ConnectorException(org.wso2.carbon.identity.core.ConnectorException) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 7 with IdentityProviderProperty

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

the class IdPManagementDAO method getIdPs.

/**
 * @param dbConnection
 * @param tenantId
 * @param tenantDomain
 * @return
 * @throws IdentityProviderManagementException
 */
public List<IdentityProvider> getIdPs(Connection dbConnection, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    boolean dbConnInitialized = true;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<IdentityProvider> idps = new ArrayList<IdentityProvider>();
    if (dbConnection == null) {
        dbConnection = IdentityDatabaseUtil.getDBConnection(false);
    } else {
        dbConnInitialized = false;
    }
    try {
        String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDPS_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setInt(2, MultitenantConstants.SUPER_TENANT_ID);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            String identityProviderName = rs.getString(1);
            if (!IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(identityProviderName)) {
                IdentityProvider identityProvider = new IdentityProvider();
                identityProvider.setIdentityProviderName(identityProviderName);
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_PRIMARY"))) {
                    identityProvider.setPrimary(true);
                } else {
                    identityProvider.setPrimary(false);
                }
                identityProvider.setHomeRealmId(rs.getString("HOME_REALM_ID"));
                identityProvider.setIdentityProviderDescription(rs.getString("DESCRIPTION"));
                // IS_FEDERATION_HUB_IDP
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_FEDERATION_HUB"))) {
                    identityProvider.setFederationHub(false);
                }
                // IS_LOCAL_CLAIM_DIALECT
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_LOCAL_CLAIM_DIALECT"))) {
                    if (identityProvider.getClaimConfig() == null) {
                        identityProvider.setClaimConfig(new ClaimConfig());
                    }
                    identityProvider.getClaimConfig().setLocalClaimDialect(true);
                }
                // IS_ENABLE
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_ENABLED"))) {
                    identityProvider.setEnable(true);
                } else {
                    identityProvider.setEnable(false);
                }
                identityProvider.setDisplayName(rs.getString("DISPLAY_NAME"));
                identityProvider.setId(rs.getString("ID"));
                List<IdentityProviderProperty> propertyList = getIdentityPropertiesByIdpId(dbConnection, Integer.parseInt(identityProvider.getId()));
                identityProvider.setIdpProperties(propertyList.toArray(new IdentityProviderProperty[0]));
                identityProvider.setImageUrl(rs.getString("IMAGE_URL"));
                identityProvider.setResourceId(rs.getString("UUID"));
                idps.add(identityProvider);
            }
        }
        return idps;
    } catch (SQLException e) {
        throw new IdentityProviderManagementException("Error occurred while retrieving registered Identity " + "Provider Entity IDs " + "for tenant " + tenantDomain, e);
    } finally {
        if (dbConnInitialized) {
            IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        } else {
            IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
        }
    }
}
Also used : ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 8 with IdentityProviderProperty

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

the class IdentityProviderManagementServiceTest method addTestIdps.

private void addTestIdps() throws IdentityProviderManagementException {
    // Initialize Test Identity Provider 1.
    IdentityProvider idp1 = new IdentityProvider();
    idp1.setIdentityProviderName("testIdP1");
    idp1.setIdentityProviderDescription("Test Idp 1");
    idp1.setHomeRealmId("1");
    idp1.setEnable(true);
    idp1.setPrimary(true);
    idp1.setFederationHub(true);
    idp1.setCertificate("");
    RoleMapping roleMapping1 = new RoleMapping();
    roleMapping1.setRemoteRole("Role1");
    roleMapping1.setLocalRole(new LocalRole("1", "LocalRole1"));
    RoleMapping roleMapping2 = new RoleMapping();
    roleMapping2.setRemoteRole("Role2");
    roleMapping2.setLocalRole(new LocalRole("2", "LocalRole2"));
    PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
    permissionsAndRoleConfig.setIdpRoles(new String[] { "Role1", "Role2" });
    permissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { roleMapping1, roleMapping2 });
    idp1.setPermissionAndRoleConfig(permissionsAndRoleConfig);
    FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    federatedAuthenticatorConfig.setDisplayName("DisplayName1");
    federatedAuthenticatorConfig.setName("Name");
    federatedAuthenticatorConfig.setEnabled(true);
    Property property1 = new Property();
    property1.setName("Property1");
    property1.setValue("value1");
    property1.setConfidential(true);
    Property property2 = new Property();
    property2.setName("Property2");
    property2.setValue("value2");
    property2.setConfidential(false);
    federatedAuthenticatorConfig.setProperties(new Property[] { property1, property2 });
    idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
    ProvisioningConnectorConfig provisioningConnectorConfig1 = new ProvisioningConnectorConfig();
    provisioningConnectorConfig1.setName("ProvisiningConfig1");
    provisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1 });
    ProvisioningConnectorConfig provisioningConnectorConfig2 = new ProvisioningConnectorConfig();
    provisioningConnectorConfig2.setName("ProvisiningConfig2");
    provisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2 });
    provisioningConnectorConfig2.setEnabled(true);
    provisioningConnectorConfig2.setBlocking(true);
    idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig1, provisioningConnectorConfig2 });
    IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
    identityProviderProperty.setDisplayName("idpDisplayName");
    identityProviderProperty.setName("idpPropertyName");
    identityProviderProperty.setValue("idpPropertyValue");
    idp1.setIdpProperties(new IdentityProviderProperty[] { identityProviderProperty });
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setLocalClaimDialect(false);
    claimConfig.setRoleClaimURI("Country");
    claimConfig.setUserClaimURI("Country");
    ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimId(0);
    remoteClaim.setClaimUri("Country");
    claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    claimConfig.setIdpClaims(new Claim[] { remoteClaim });
    idp1.setClaimConfig(claimConfig);
    // Initialize Test Identity Provider 2.
    IdentityProvider idp2 = new IdentityProvider();
    idp2.setIdentityProviderName("testIdP2");
    idp2.setHomeRealmId("2");
    ClaimConfig claimConfig2 = new ClaimConfig();
    claimConfig2.setLocalClaimDialect(true);
    claimConfig2.setRoleClaimURI("http://wso2.org/claims/role");
    claimConfig2.setUserClaimURI("http://wso2.org/claims/fullname");
    ClaimMapping claimMapping2 = new ClaimMapping();
    Claim localClaim2 = new Claim();
    localClaim2.setClaimId(0);
    localClaim2.setClaimUri("http://wso2.org/claims/fullname");
    claimMapping2.setLocalClaim(localClaim2);
    claimConfig2.setClaimMappings(new ClaimMapping[] { claimMapping2 });
    idp2.setClaimConfig(claimConfig2);
    // Initialize Test Identity Provider 3.
    IdentityProvider idp3 = new IdentityProvider();
    idp3.setIdentityProviderName("testIdP3");
    idp3.setHomeRealmId("3");
    // IDP with PermissionsAndRoleConfig, FederatedAuthenticatorConfigs, ProvisioningConnectorConfigs, ClaimConfigs.
    identityProviderManagementService.addIdP(idp1);
    // IDP with Local Cliam Dialect ClaimConfigs.
    identityProviderManagementService.addIdP(idp2);
    // IDP with Only name.
    identityProviderManagementService.addIdP(idp3);
}
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) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) 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) 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)

Example 9 with IdentityProviderProperty

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

the class IdentityProviderManagementServiceTest method updateResidentIdPData.

@DataProvider
public Object[][] updateResidentIdPData() {
    // Initialize New Resident Identity Provider 1.
    IdentityProvider idp1New = new IdentityProvider();
    idp1New.setIdentityProviderName("LOCAL");
    IdentityProviderProperty idpProperty1 = new IdentityProviderProperty();
    idpProperty1.setName(IdentityApplicationConstants.SESSION_IDLE_TIME_OUT);
    idpProperty1.setValue("100");
    IdentityProviderProperty idpProperty2 = new IdentityProviderProperty();
    idpProperty2.setName(IdentityApplicationConstants.REMEMBER_ME_TIME_OUT);
    idpProperty2.setValue("10000");
    IdentityProviderProperty idpProperty3 = new IdentityProviderProperty();
    idpProperty3.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD);
    idpProperty3.setValue("10000");
    IdentityProviderProperty idpProperty4 = new IdentityProviderProperty();
    idpProperty4.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED);
    idpProperty4.setValue("true");
    idp1New.setIdpProperties(new IdentityProviderProperty[] { idpProperty1, idpProperty2, idpProperty3, idpProperty4 });
    // Initialize New Resident Identity Provider 2.
    IdentityProvider idp2New = new IdentityProvider();
    idp2New.setIdentityProviderName("LOCAL");
    FederatedAuthenticatorConfig facNew = new FederatedAuthenticatorConfig();
    facNew.setDisplayName("DisplayName1New");
    facNew.setName("Name");
    facNew.setEnabled(true);
    idp2New.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { facNew });
    // Initialize New Resident Identity Provider 3.
    IdentityProvider idp3New = new IdentityProvider();
    idp3New.setIdentityProviderName("LOCAL");
    return new Object[][] { // New Resident IDP with new IDP Properties.
    { idp1New }, // New Resident IDP with new FederatedAuthenticatorConfigs.
    { idp2New }, // New Resident IDP with no object properties (only contains the name).
    { idp3New } };
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Matchers.anyObject(org.mockito.Matchers.anyObject) DataProvider(org.testng.annotations.DataProvider)

Example 10 with IdentityProviderProperty

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

the class IdPManagementDAOTest method addTestIdps.

private void addTestIdps() throws IdentityProviderManagementException {
    // Initialize Test Identity Provider 1.
    IdentityProvider idp1 = new IdentityProvider();
    idp1.setIdentityProviderName("testIdP1");
    idp1.setHomeRealmId("1");
    idp1.setEnable(true);
    idp1.setPrimary(true);
    idp1.setFederationHub(true);
    idp1.setCertificate("");
    RoleMapping roleMapping1 = new RoleMapping();
    roleMapping1.setRemoteRole("Role1");
    roleMapping1.setLocalRole(new LocalRole("1", "LocalRole1"));
    RoleMapping roleMapping2 = new RoleMapping();
    roleMapping2.setRemoteRole("Role2");
    roleMapping2.setLocalRole(new LocalRole("2", "LocalRole2"));
    PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
    permissionsAndRoleConfig.setIdpRoles(new String[] { "Role1", "Role2" });
    permissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { roleMapping1, roleMapping2 });
    idp1.setPermissionAndRoleConfig(permissionsAndRoleConfig);
    FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    federatedAuthenticatorConfig.setDisplayName("DisplayName1");
    federatedAuthenticatorConfig.setName("Name");
    federatedAuthenticatorConfig.setEnabled(true);
    Property property1 = new Property();
    property1.setName("Property1");
    property1.setValue("value1");
    property1.setConfidential(true);
    Property property2 = new Property();
    property2.setName("Property2");
    property2.setValue("value2");
    property2.setConfidential(false);
    federatedAuthenticatorConfig.setProperties(new Property[] { property1, property2 });
    idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
    ProvisioningConnectorConfig provisioningConnectorConfig1 = new ProvisioningConnectorConfig();
    provisioningConnectorConfig1.setName("ProvisiningConfig1");
    provisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1 });
    ProvisioningConnectorConfig provisioningConnectorConfig2 = new ProvisioningConnectorConfig();
    provisioningConnectorConfig2.setName("ProvisiningConfig2");
    provisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2 });
    provisioningConnectorConfig2.setEnabled(true);
    provisioningConnectorConfig2.setBlocking(true);
    idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig1, provisioningConnectorConfig2 });
    IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
    identityProviderProperty.setDisplayName("idpDisplayName");
    identityProviderProperty.setName("idpPropertyName");
    identityProviderProperty.setValue("idpPropertyValue");
    idp1.setIdpProperties(new IdentityProviderProperty[] { identityProviderProperty });
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setLocalClaimDialect(false);
    claimConfig.setRoleClaimURI("Country");
    claimConfig.setUserClaimURI("Country");
    ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimId(0);
    remoteClaim.setClaimUri("Country");
    claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    claimConfig.setIdpClaims(new Claim[] { remoteClaim });
    idp1.setClaimConfig(claimConfig);
    // Initialize Test Identity Provider 2.
    IdentityProvider idp2 = new IdentityProvider();
    idp2.setIdentityProviderName("testIdP2");
    idp2.setHomeRealmId("2");
    ClaimConfig claimConfig2 = new ClaimConfig();
    claimConfig2.setLocalClaimDialect(true);
    claimConfig2.setRoleClaimURI("http://wso2.org/claims/role");
    claimConfig2.setUserClaimURI("http://wso2.org/claims/fullname");
    ClaimMapping claimMapping2 = new ClaimMapping();
    Claim localClaim2 = new Claim();
    localClaim2.setClaimId(0);
    localClaim2.setClaimUri("http://wso2.org/claims/fullname");
    claimMapping2.setLocalClaim(localClaim2);
    claimConfig2.setClaimMappings(new ClaimMapping[] { claimMapping2 });
    idp2.setClaimConfig(claimConfig2);
    // Initialize Test Identity Provider 3.
    IdentityProvider idp3 = new IdentityProvider();
    idp3.setIdentityProviderName("testIdP3");
    idp3.setHomeRealmId("3");
    // IDP with PermissionsAndRoleConfig, FederatedAuthenticatorConfigs, ProvisioningConnectorConfigs, ClaimConfigs.
    idPManagementDAO.addIdP(idp1, SAMPLE_TENANT_ID);
    // IDP with Local Cliam Dialect ClaimConfigs.
    idPManagementDAO.addIdP(idp2, SAMPLE_TENANT_ID);
    // IDP with Only name.
    idPManagementDAO.addIdP(idp3, SAMPLE_TENANT_ID2);
}
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) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) 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) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) Property(org.wso2.carbon.identity.application.common.model.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim)

Aggregations

IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)43 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)30 ArrayList (java.util.ArrayList)20 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)14 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)9 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)8 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)8 ResultSet (java.sql.ResultSet)7 HashMap (java.util.HashMap)7 Property (org.wso2.carbon.identity.application.common.model.Property)7 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)7 Test (org.testng.annotations.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)5 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)5 IOException (java.io.IOException)4 List (java.util.List)4 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)4