Search in sources :

Example 96 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 testGetResidentIDPMetadata.

@Test
public void testGetResidentIDPMetadata() throws Exception {
    addResidentIdp();
    Assert.assertNull(identityProviderManagementService.getResidentIDPMetadata());
    when(mockMetadataConverter.canHandle((FederatedAuthenticatorConfig) anyObject())).thenReturn(TRUE);
    when(mockMetadataConverter.getMetadataString((FederatedAuthenticatorConfig) anyObject())).thenReturn("saml2sso");
    IdentityProvider newIdp = new IdentityProvider();
    newIdp.setIdentityProviderName("LOCAL");
    FederatedAuthenticatorConfig facNew = new FederatedAuthenticatorConfig();
    facNew.setDisplayName("SAML2SSO");
    facNew.setName("saml2sso");
    facNew.setEnabled(true);
    newIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { facNew });
    identityProviderManagementService.updateResidentIdP((IdentityProvider) newIdp);
    Assert.assertNotNull(identityProviderManagementService.getResidentIDPMetadata());
    Assert.assertEquals(identityProviderManagementService.getResidentIDPMetadata(), "saml2sso");
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Test(org.testng.annotations.Test)

Example 97 with IdentityProvider

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

the class IdPManagementDAOTest method testUpdateIdP.

@Test(dataProvider = "updateIdPData")
public void testUpdateIdP(Object oldIdp, Object newIdp, int tenantId) throws Exception {
    mockStatic(IdentityDatabaseUtil.class);
    mockStatic(IdentityUtil.class);
    try (Connection connection = getConnection(DB_NAME)) {
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection);
        when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
        when(IdentityUtil.getProperty(RESET_PROVISIONING_ENTITIES_ON_CONFIG_UPDATE)).thenReturn("false");
        when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSourceMap.get(DB_NAME));
        addTestIdps();
        idPManagementDAO.updateIdP((IdentityProvider) newIdp, ((IdentityProvider) oldIdp), tenantId);
        String newIdpName = ((IdentityProvider) newIdp).getIdentityProviderName();
        IdentityProvider idpResult = idPManagementDAO.getIdPByName(connection, newIdpName, tenantId, TENANT_DOMAIN);
        assertEquals(idpResult.getIdentityProviderName(), newIdpName);
    }
}
Also used : Connection(java.sql.Connection) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 98 with IdentityProvider

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

the class IdPManagementDAOTest method testGetIdPByAuthenticatorPropertyWithoutAuthenticatorData.

@Test(dataProvider = "getIdPByAuthenticatorPropertyValueWithoutAuthenticatorData")
public void testGetIdPByAuthenticatorPropertyWithoutAuthenticatorData(int tenantId, String idpName, String property, String value, boolean isExist) 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();
        IdentityProvider idpResult = idPManagementDAO.getIdPByAuthenticatorPropertyValue(connection, property, value, tenantId, TENANT_DOMAIN);
        if (isExist) {
            assertEquals(idpResult.getIdentityProviderName(), idpName);
        } else {
            assertNull(idpResult);
        }
    }
}
Also used : Connection(java.sql.Connection) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 99 with IdentityProvider

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

the class IdPManagementDAOTest method testGetIdPsSearch.

@Test(dataProvider = "getIdPsSearchData")
public void testGetIdPsSearch(int tenantId, String tenantDomain, String filter, 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();
        List<IdentityProvider> idps1 = idPManagementDAO.getIdPsSearch(connection, tenantId, tenantDomain, filter);
        assertEquals(idps1.size(), resultCount);
        List<IdentityProvider> idps2 = idPManagementDAO.getIdPsSearch(null, tenantId, tenantDomain, filter);
        assertEquals(idps2.size(), resultCount);
    }
}
Also used : Connection(java.sql.Connection) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 100 with IdentityProvider

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

the class IdPManagementDAOTest method updateIdPData.

@DataProvider
public Object[][] updateIdPData() {
    // 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("");
    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);
    federatedAuthenticatorConfig.setProperties(new Property[] { property1 });
    idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
    ProvisioningConnectorConfig provisioningConnectorConfig = new ProvisioningConnectorConfig();
    provisioningConnectorConfig.setName("ProvisiningConfig1");
    provisioningConnectorConfig.setProvisioningProperties(new Property[] { property1 });
    idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig });
    // 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");
    // 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 property1New = new Property();
    property1New.setName("Property1New");
    property1New.setValue("value1New");
    property1New.setConfidential(false);
    Property property2New = new Property();
    property2New.setName("Property2New");
    property2New.setValue("value2New");
    property2New.setConfidential(false);
    newFederatedAuthenticatorConfig.setProperties(new Property[] { property1New, property2New });
    idp1New.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { newFederatedAuthenticatorConfig });
    ProvisioningConnectorConfig newProvisioningConnectorConfig1 = new ProvisioningConnectorConfig();
    newProvisioningConnectorConfig1.setName("ProvisiningConfig1");
    newProvisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1New });
    ProvisioningConnectorConfig newProvisioningConnectorConfig2 = new ProvisioningConnectorConfig();
    newProvisioningConnectorConfig2.setName("ProvisiningConfig2");
    newProvisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2New });
    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[][] { // Update PermissionsAndRoleConfig,FederatedAuthenticatorConfig,ProvisioningConnectorConfig,ClaimConfig.
    { idp1, idp1New, SAMPLE_TENANT_ID }, // Update name, LocalClaimDialect, ClaimConfig.
    { idp2, idp2New, SAMPLE_TENANT_ID }, // Update name.
    { idp3, idp3New, SAMPLE_TENANT_ID2 } };
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) 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) DataProvider(org.testng.annotations.DataProvider)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)190 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