Search in sources :

Example 86 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider 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 87 with IdentityProvider

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

the class IdPManagementDAO method getIdPByRealmId.

/**
 * @param realmId
 * @param tenantId
 * @param tenantDomain
 * @return
 * @throws IdentityProviderManagementException
 * @throws SQLException
 */
public IdentityProvider getIdPByRealmId(String realmId, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String idPName = null;
    try {
        String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_NAME_BY_REALM_ID_SQL;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setInt(2, MultitenantConstants.SUPER_TENANT_ID);
        prepStmt.setString(3, realmId);
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            idPName = rs.getString("NAME");
        }
        return getIdPByName(dbConnection, idPName, tenantId, tenantDomain);
    } catch (SQLException e) {
        throw new IdentityProviderManagementException("Error while retreiving Identity Provider by realm " + realmId, e);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 88 with IdentityProvider

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

the class IdPManagementDAO method doAppointPrimary.

private void doAppointPrimary(Connection conn, int tenantId, String tenantDomain) throws SQLException, IdentityProviderManagementException {
    List<IdentityProvider> tenantIdPs = getIdPs(conn, tenantId, tenantDomain);
    if (!tenantIdPs.isEmpty()) {
        PreparedStatement prepStmt = null;
        try {
            String sqlStmt = IdPManagementConstants.SQLQueries.SWITCH_IDP_PRIMARY_ON_DELETE_SQL;
            prepStmt = conn.prepareStatement(sqlStmt);
            prepStmt.setString(1, IdPManagementConstants.IS_TRUE_VALUE);
            prepStmt.setInt(2, tenantId);
            prepStmt.setString(3, tenantIdPs.get(0).getIdentityProviderName());
            prepStmt.setString(4, IdPManagementConstants.IS_FALSE_VALUE);
            prepStmt.executeUpdate();
        } finally {
            IdentityDatabaseUtil.closeStatement(prepStmt);
        }
    } else {
        String msg = "No Identity Providers registered for tenant " + tenantDomain;
        log.warn(msg);
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) PreparedStatement(java.sql.PreparedStatement)

Example 89 with IdentityProvider

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

the class IdentityProviderManagementServiceTest method addSharedIdp.

private void addSharedIdp() throws SQLException, IdentityProviderManagementException {
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        String sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_SQL;
        PreparedStatement prepStmt = connection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, SUPER_TENANT_ID);
        prepStmt.setString(2, "SHARED_IDP");
        prepStmt.setString(3, IdPManagementConstants.IS_TRUE_VALUE);
        prepStmt.setString(4, "");
        prepStmt.setBinaryStream(5, new ByteArrayInputStream(new byte[0]), 0);
        prepStmt.setString(6, "");
        prepStmt.setString(7, IdPManagementConstants.IS_FALSE_VALUE);
        prepStmt.setString(8, null);
        prepStmt.setString(9, null);
        prepStmt.setString(10, null);
        prepStmt.setString(11, null);
        prepStmt.setString(12, null);
        prepStmt.setString(13, "SHARED_IDP");
        prepStmt.setString(14, IdPManagementConstants.IS_FALSE_VALUE);
        prepStmt.setString(15, IdPManagementConstants.IS_FALSE_VALUE);
        prepStmt.setString(16, "Role");
        prepStmt.setString(17, IdPManagementConstants.IS_TRUE_VALUE);
        prepStmt.setString(18, "");
        prepStmt.setString(19, "");
        prepStmt.setString(20, "0000");
        prepStmt.executeUpdate();
        prepStmt.clearParameters();
    }
    IdentityProvider sharedIdp = identityProviderManagementService.getIdPByName("SHARED_IDP");
    Assert.assertNotNull(sharedIdp);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Matchers.anyString(org.mockito.Matchers.anyString)

Example 90 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider 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)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)191 Test (org.testng.annotations.Test)103 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)65 ArrayList (java.util.ArrayList)64 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)54 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)53 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)47 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)47 API (org.wso2.carbon.apimgt.core.models.API)43 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)37 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)35 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)34 Property (org.wso2.carbon.identity.application.common.model.Property)29 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig)29 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)27 Connection (java.sql.Connection)25 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)22 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)22 HashMap (java.util.HashMap)20 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)20