Search in sources :

Example 11 with RoleMapping

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

the class IdPManagementDAOTest method addIdPData.

@DataProvider
public Object[][] addIdPData() {
    // Initialize Test Identity Provider 1.
    IdentityProvider idp1 = new IdentityProvider();
    idp1.setIdentityProviderName("testIdP1");
    idp1.setEnable(true);
    idp1.setPrimary(true);
    idp1.setFederationHub(true);
    idp1.setCertificate("");
    RoleMapping roleMapping1 = new RoleMapping(new LocalRole("1", "LocalRole1"), "Role1");
    RoleMapping roleMapping2 = new RoleMapping(new LocalRole("2", "LocalRole2"), "Role2");
    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(false);
    Property property2 = new Property();
    property2.setName("Property2");
    property2.setValue("value2");
    property2.setConfidential(true);
    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 });
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setLocalClaimDialect(false);
    claimConfig.setRoleClaimURI("Country");
    claimConfig.setUserClaimURI("Country");
    ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
    claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimId(0);
    remoteClaim.setClaimUri("Country");
    claimConfig.setIdpClaims(new Claim[] { remoteClaim });
    idp1.setClaimConfig(claimConfig);
    // Initialize Test Identity Provider 2.
    IdentityProvider idp2 = new IdentityProvider();
    idp2.setIdentityProviderName("testIdP2");
    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");
    return new Object[][] { // IDP with PermissionsAndRoleConfig,FederatedAuthenticatorConfigs,ProvisioningConnectorConfigs,Claims.
    { idp1, SAMPLE_TENANT_ID }, // IDP with Local Cliam Dialect ClaimConfigs.
    { idp2, SAMPLE_TENANT_ID }, // IDP with Only name.
    { 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) 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) DataProvider(org.testng.annotations.DataProvider)

Example 12 with RoleMapping

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

the class OutboundProvisioningManager method getMappedGroups.

/**
 * Get mapped idp roles for given role list
 *
 * @param groupList
 * @param idPRoleMapping
 * @return
 */
private List<String> getMappedGroups(List<String> groupList, RoleMapping[] idPRoleMapping) {
    if (CollectionUtils.isEmpty(groupList)) {
        return new ArrayList<>();
    }
    Map<String, String> mappedRoles = new HashMap<>();
    for (RoleMapping mapping : idPRoleMapping) {
        mappedRoles.put(mapping.getLocalRole().getLocalRoleName(), mapping.getRemoteRole());
    }
    List<String> mappedUserGroups = new ArrayList<>();
    for (Iterator<String> iterator = groupList.iterator(); iterator.hasNext(); ) {
        String userGroup = iterator.next();
        String mappedGroup = null;
        if ((mappedGroup = mappedRoles.get(userGroup)) != null) {
            mappedUserGroups.add(mappedGroup);
        }
    }
    return mappedUserGroups;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping)

Example 13 with RoleMapping

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

the class ApplicationDAOImpl method updatePermissionAndRoleConfiguration.

/**
 * @param applicationID
 * @param permissionsAndRoleConfiguration
 * @param connection
 * @throws SQLException
 */
private void updatePermissionAndRoleConfiguration(int applicationID, PermissionsAndRoleConfig permissionsAndRoleConfiguration, Connection connection) throws SQLException {
    if (permissionsAndRoleConfiguration == null || permissionsAndRoleConfiguration.getRoleMappings() == null || ArrayUtils.isEmpty(permissionsAndRoleConfiguration.getRoleMappings())) {
        return;
    }
    RoleMapping[] roleMappings = permissionsAndRoleConfiguration.getRoleMappings();
    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    PreparedStatement storeRoleMapPrepStmt = null;
    try {
        storeRoleMapPrepStmt = connection.prepareStatement(STORE_ROLE_MAPPING);
        for (RoleMapping roleMapping : roleMappings) {
            // TENANT_ID, IDP_ROLE, SP_ROLE, APP_ID
            storeRoleMapPrepStmt.setInt(1, tenantID);
            storeRoleMapPrepStmt.setString(2, roleMapping.getLocalRole().getLocalRoleName());
            storeRoleMapPrepStmt.setString(3, roleMapping.getRemoteRole());
            storeRoleMapPrepStmt.setInt(4, applicationID);
            storeRoleMapPrepStmt.addBatch();
            if (log.isDebugEnabled()) {
                log.debug("Storing Claim Mapping. IDPRole: " + roleMapping.getLocalRole() + " SPRole: " + roleMapping.getRemoteRole());
            }
        }
        storeRoleMapPrepStmt.executeBatch();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(storeRoleMapPrepStmt);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping)

Example 14 with RoleMapping

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

the class ApplicationManagementServiceImplTest method addApplicationConfigurations.

private void addApplicationConfigurations(ServiceProvider serviceProvider) {
    serviceProvider.setDescription("Created for testing");
    serviceProvider.setSaasApp(TRUE);
    // Inbound Authentication Configurations.
    InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
    InboundAuthenticationRequestConfig authRequestConfig = new InboundAuthenticationRequestConfig();
    authRequestConfig.setInboundAuthKey("auth key");
    authRequestConfig.setInboundAuthType("oauth2");
    InboundAuthenticationRequestConfig[] authRequests = new InboundAuthenticationRequestConfig[] { authRequestConfig };
    inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(authRequests);
    serviceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
    // Inbound Provisioning Configurations.
    InboundProvisioningConfig provisioningConfig = new InboundProvisioningConfig();
    provisioningConfig.setProvisioningUserStore("UserStore");
    serviceProvider.setInboundProvisioningConfig(provisioningConfig);
    // OutBound Provisioning Configurations.
    IdentityProvider provisioningIdP = new IdentityProvider();
    provisioningIdP.setIdentityProviderName("Provisioning IdP");
    OutboundProvisioningConfig outboundProvisioningConfig = new OutboundProvisioningConfig();
    outboundProvisioningConfig.setProvisioningIdentityProviders(new IdentityProvider[] { provisioningIdP });
    ProvisioningConnectorConfig provisioningConnectorConfig = new ProvisioningConnectorConfig();
    provisioningConnectorConfig.setName("Provisioning connector");
    provisioningIdP.setDefaultProvisioningConnectorConfig(provisioningConnectorConfig);
    serviceProvider.setOutboundProvisioningConfig(outboundProvisioningConfig);
    // Local And OutBound Authentication Configuration.
    LocalAndOutboundAuthenticationConfig authenticationConfig = new LocalAndOutboundAuthenticationConfig();
    AuthenticationStep authenticationStep = new AuthenticationStep();
    IdentityProvider identityProvider = new IdentityProvider();
    identityProvider.setIdentityProviderName(IDP_NAME_1);
    FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    federatedAuthenticatorConfig.setName("Federated authenticator");
    identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
    authenticationStep.setFederatedIdentityProviders(new IdentityProvider[] { identityProvider });
    LocalAuthenticatorConfig localAuthenticatorConfig = new LocalAuthenticatorConfig();
    localAuthenticatorConfig.setName("Local authenticator");
    authenticationStep.setLocalAuthenticatorConfigs(new LocalAuthenticatorConfig[] { localAuthenticatorConfig });
    authenticationConfig.setAuthenticationSteps(new AuthenticationStep[] { authenticationStep });
    serviceProvider.setLocalAndOutBoundAuthenticationConfig(authenticationConfig);
    // Request Path Authenticator Configuration.
    RequestPathAuthenticatorConfig requestPathAuthenticatorConfig = new RequestPathAuthenticatorConfig();
    requestPathAuthenticatorConfig.setName("Request path authenticator");
    serviceProvider.setRequestPathAuthenticatorConfigs(new RequestPathAuthenticatorConfig[] { requestPathAuthenticatorConfig });
    // Claim Configurations.
    ClaimConfig claimConfig = new ClaimConfig();
    claimConfig.setRoleClaimURI("Role claim uri");
    claimConfig.setSpClaimDialects(new String[] { "SP claim dialect" });
    ClaimMapping claimMapping = new ClaimMapping();
    Claim localClaim = new Claim();
    localClaim.setClaimUri("Local claim uri");
    Claim remoteClaim = new Claim();
    remoteClaim.setClaimUri("Remote claim uri");
    claimMapping.setLocalClaim(localClaim);
    claimMapping.setRemoteClaim(remoteClaim);
    claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
    serviceProvider.setClaimConfig(claimConfig);
    // Permission Role Configurations.
    PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
    RoleMapping roleMapping = new RoleMapping();
    LocalRole localRole = new LocalRole("Local role");
    roleMapping.setLocalRole(localRole);
    roleMapping.setRemoteRole("Remote role");
    RoleMapping[] roleMappings = new RoleMapping[] { roleMapping };
    permissionsAndRoleConfig.setRoleMappings(roleMappings);
}
Also used : InboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.InboundProvisioningConfig) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) OutboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim)

Example 15 with RoleMapping

use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project identity-inbound-auth-oauth by wso2-extensions.

the class ClaimUtilTest method testGetServiceProviderMappedUserRoles.

@Test(dataProvider = "provideRoleMappingData")
public void testGetServiceProviderMappedUserRoles(List<String> locallyMappedUserRoles, Object roleMappingObject, String claimSeparator, String expected) throws Exception {
    RoleMapping[] roleMappings = (RoleMapping[]) roleMappingObject;
    when(mockedServiceProvider.getPermissionAndRoleConfig()).thenReturn(mockedPermissionAndRoleConfig);
    when(mockedPermissionAndRoleConfig.getRoleMappings()).thenReturn(roleMappings);
    String returned = ClaimUtil.getServiceProviderMappedUserRoles(mockedServiceProvider, locallyMappedUserRoles, claimSeparator);
    Assert.assertEquals(returned, expected, "Invalid returned value");
}
Also used : RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Aggregations

RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)29 ArrayList (java.util.ArrayList)15 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)15 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)14 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)12 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)9 Claim (org.wso2.carbon.identity.application.common.model.Claim)8 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)8 Property (org.wso2.carbon.identity.application.common.model.Property)7 HashMap (java.util.HashMap)6 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)6 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)6 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)5 PreparedStatement (java.sql.PreparedStatement)4 RoleAliasListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO)4 ResultSet (java.sql.ResultSet)3 HashSet (java.util.HashSet)3 JSONObject (org.json.simple.JSONObject)3 DataProvider (org.testng.annotations.DataProvider)3 Test (org.testng.annotations.Test)3