Search in sources :

Example 16 with LocalRole

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

the class ApplicationDAOImpl method getRoleMappingOfApplication.

/**
 * Reads the claim mappings for a given appID
 *
 * @param applicationId
 * @param connection
 * @return
 * @throws IdentityApplicationManagementException
 */
private List<RoleMapping> getRoleMappingOfApplication(int applicationId, Connection connection, int tenantID) throws IdentityApplicationManagementException {
    ArrayList<RoleMapping> roleMappingList = new ArrayList<RoleMapping>();
    if (log.isDebugEnabled()) {
        log.debug("Reading Role Mapping of Application " + applicationId);
    }
    PreparedStatement getClientInfo = null;
    ResultSet resultSet = null;
    try {
        getClientInfo = connection.prepareStatement(LOAD_ROLE_MAPPING_BY_APP_ID);
        // IDP_ROLE, SP_ROLE
        getClientInfo.setInt(1, applicationId);
        getClientInfo.setInt(2, tenantID);
        resultSet = getClientInfo.executeQuery();
        while (resultSet.next()) {
            RoleMapping roleMapping = new RoleMapping();
            LocalRole localRole = new LocalRole();
            localRole.setLocalRoleName(resultSet.getString(1));
            roleMapping.setLocalRole(localRole);
            roleMapping.setRemoteRole(resultSet.getString(2));
            roleMappingList.add(roleMapping);
            if (log.isDebugEnabled()) {
                log.debug("Local Role: " + roleMapping.getLocalRole().getLocalRoleName() + " SPRole: " + roleMapping.getRemoteRole());
            }
        }
    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error while retrieving all application");
    } finally {
        IdentityApplicationManagementUtil.closeStatement(getClientInfo);
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
    }
    return roleMappingList;
}
Also used : SQLException(java.sql.SQLException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping)

Example 17 with LocalRole

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

the class IdPManagementUIUtil method buildRoleConfiguration.

/**
 * @param fedIdp
 * @param paramMap
 * @param idpRoles
 * @param currentRoleMapping
 * @throws IdentityApplicationManagementException
 */
private static void buildRoleConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap, List<String> idpRoles, RoleMapping[] currentRoleMapping) throws IdentityApplicationManagementException {
    PermissionsAndRoleConfig roleConfiguration = new PermissionsAndRoleConfig();
    roleConfiguration.setIdpRoles(idpRoles.toArray(new String[idpRoles.size()]));
    Set<RoleMapping> roleMappingList = new HashSet<RoleMapping>();
    String idpProvisioningRole = paramMap.get("idpProvisioningRole");
    fedIdp.setProvisioningRole(idpProvisioningRole);
    int attributesCount = 0;
    if (paramMap.get("rolemappingrow_name_count") != null) {
        attributesCount = Integer.parseInt(paramMap.get("rolemappingrow_name_count"));
    }
    for (int i = 0; i < attributesCount; i++) {
        String idPRoleName = paramMap.get("rolerowname_" + i);
        String localRoleString = paramMap.get("localrowname_" + i);
        if (idPRoleName != null && localRoleString != null) {
            String[] splitLocalRole = localRoleString.split("/");
            String userStoreId = null;
            String localRoleName = null;
            LocalRole localRole = null;
            if (splitLocalRole != null && splitLocalRole.length == 2) {
                userStoreId = splitLocalRole[0];
                localRoleName = splitLocalRole[1];
                localRole = new LocalRole();
                localRole.setUserStoreId(userStoreId);
                localRole.setLocalRoleName(localRoleName);
            } else {
                localRoleName = localRoleString;
                localRole = new LocalRole();
                localRole.setLocalRoleName(localRoleName);
            }
            RoleMapping roleMapping = new RoleMapping();
            roleMapping.setLocalRole(localRole);
            roleMapping.setRemoteRole(idPRoleName);
            roleMappingList.add(roleMapping);
        }
    }
    roleConfiguration.setRoleMappings(roleMappingList.toArray(new RoleMapping[roleMappingList.size()]));
    fedIdp.setPermissionAndRoleConfig(roleConfiguration);
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.PermissionsAndRoleConfig) LocalRole(org.wso2.carbon.identity.application.common.model.idp.xsd.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.idp.xsd.RoleMapping) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 18 with LocalRole

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

the class DefaultOIDCClaimsCallbackHandlerTest method testHandleCustomClaimsWithOAuthTokenReqMsgCtxtWithSpRoleMappings.

@Test
public void testHandleCustomClaimsWithOAuthTokenReqMsgCtxtWithSpRoleMappings() throws Exception {
    JWTClaimsSet.Builder jwtClaimsSetBuilder = new JWTClaimsSet.Builder();
    OAuthTokenReqMessageContext requestMsgCtx = getTokenReqMessageContextForLocalUser();
    ServiceProvider serviceProvider = getSpWithDefaultRequestedClaimsMappings();
    // Add a SP role mapping
    RoleMapping[] roleMappings = new RoleMapping[] { new RoleMapping(new LocalRole(USER_STORE_DOMAIN, ROLE2), SP_ROLE_2) };
    serviceProvider.getPermissionAndRoleConfig().setRoleMappings(roleMappings);
    mockApplicationManagementService(serviceProvider);
    UserRealm userRealm = getUserRealmWithUserClaims(USER_CLAIMS_MAP);
    mockUserRealm(requestMsgCtx.getAuthorizedUser().toString(), userRealm);
    mockClaimHandler();
    // Define OIDC Scope property
    Properties oidcProperties = new Properties();
    String[] oidcScopeClaims = new String[] { ROLE, USERNAME };
    oidcProperties.setProperty(OIDC_SCOPE, StringUtils.join(oidcScopeClaims, ","));
    JWTClaimsSet jwtClaimsSet = getJwtClaimSet(jwtClaimsSetBuilder, requestMsgCtx);
    assertNotNull(jwtClaimsSet);
    assertNotNull(jwtClaimsSet.getClaim(EMAIL));
    assertNotNull(jwtClaimsSet.getClaim(USERNAME));
    assertEquals(jwtClaimsSet.getClaim(USERNAME), USER_NAME);
    assertNotNull(jwtClaimsSet.getClaim(ROLE));
    JSONArray jsonArray = (JSONArray) jwtClaimsSet.getClaim(ROLE);
    String[] expectedRoles = new String[] { ROLE1, SP_ROLE_2, ROLE3 };
    for (String role : expectedRoles) {
        assertTrue(jsonArray.contains(role));
    }
}
Also used : AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) OAuthTokenReqMessageContext(org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext) JSONArray(net.minidev.json.JSONArray) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) UserRealm(org.wso2.carbon.user.core.UserRealm) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) SAML2BearerGrantHandlerTest(org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantHandlerTest) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with LocalRole

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

the class ClaimUtilTest method setup.

@BeforeClass
public void setup() {
    // Setting requested claims in SP
    requestedClaimMappings = new ClaimMapping[3];
    ClaimMapping claimMapping1 = new ClaimMapping();
    ClaimMapping claimMapping2 = new ClaimMapping();
    ClaimMapping claimMapping3 = new ClaimMapping();
    Claim claim1 = new Claim();
    Claim claim2 = new Claim();
    Claim claim3 = new Claim();
    claim1.setClaimUri(USERNAME_CLAIM_URI);
    claimMapping1.setLocalClaim(claim1);
    claimMapping1.setRemoteClaim(claim1);
    requestedClaimMappings[0] = claimMapping1;
    claim2.setClaimUri(ROLE_CLAIM_URI);
    claimMapping2.setLocalClaim(claim2);
    claimMapping2.setRemoteClaim(claim2);
    requestedClaimMappings[1] = claimMapping2;
    claim3.setClaimUri(EMAIL_CLAIM_URI);
    claimMapping3.setLocalClaim(claim3);
    claimMapping3.setRemoteClaim(claim3);
    claimMapping3.setRequested(true);
    requestedClaimMappings[2] = claimMapping3;
    // Setting returning claims from user store
    userClaimsMap = new HashMap<>();
    userClaimsMap.put(USERNAME_CLAIM_URI, AUTHORIZED_USER);
    userClaimsMap.put(EMAIL_CLAIM_URI, "test@wso2.com");
    userClaimsMap.put(ROLE_CLAIM_URI, "role1");
    userClaimsMapWithSubject = new HashedMap();
    userClaimsMap.put(USERNAME_CLAIM_URI, AUTHORIZED_USER);
    // Setting SP to local claim mapping
    spToLocalClaimMappings = new HashMap<>();
    spToLocalClaimMappings.put(USERNAME_CLAIM_URI, USERNAME_CLAIM_URI);
    spToLocalClaimMappings.put(ROLE_CLAIM_URI, ROLE_CLAIM_URI);
    spToLocalClaimMappings.put(EMAIL_CLAIM_URI, EMAIL_CLAIM_URI);
    // Setting SP role mappings
    roleMappings = new RoleMapping[2];
    LocalRole role1 = new LocalRole("PRIMARY", "role1");
    LocalRole role2 = new LocalRole("PRIMARY", "role2");
    RoleMapping mapping1 = new RoleMapping(role1, "remoteRole1");
    RoleMapping mapping2 = new RoleMapping(role2, "remoteRole2");
    roleMappings[0] = mapping1;
    roleMappings[1] = mapping2;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) HashedMap(org.apache.commons.collections.map.HashedMap) Claim(org.wso2.carbon.identity.application.common.model.Claim) BeforeClass(org.testng.annotations.BeforeClass)

Example 20 with LocalRole

use of org.wso2.carbon.identity.application.common.model.xsd.LocalRole in project product-is by wso2.

the class ApplicationManagementTestCase method testUpdateRoles.

@Test(alwaysRun = true, description = "2.1.2.10")
public void testUpdateRoles() {
    String applicationName = "TestServiceProvider";
    try {
        ServiceProvider serviceProvider = applicationManagementServiceClient.getApplication(applicationName);
        PermissionsAndRoleConfig permAndRoleConfig = new PermissionsAndRoleConfig();
        List<RoleMapping> roleMappingList = new ArrayList<RoleMapping>();
        RoleMapping mapping = new RoleMapping();
        LocalRole localRole = new LocalRole();
        localRole.setLocalRoleName(IDP_ROLE_1);
        mapping.setLocalRole(localRole);
        mapping.setRemoteRole("spRole_1");
        roleMappingList.add(mapping);
        permAndRoleConfig.setRoleMappings(roleMappingList.toArray(new RoleMapping[roleMappingList.size()]));
        serviceProvider.setPermissionAndRoleConfig(permAndRoleConfig);
        applicationManagementServiceClient.updateApplicationData(serviceProvider);
        ServiceProvider updatedServiceProvider = applicationManagementServiceClient.getApplication(applicationName);
        PermissionsAndRoleConfig updatedPermissionsAndRoleConfig = updatedServiceProvider.getPermissionAndRoleConfig();
        Assert.assertEquals(updatedPermissionsAndRoleConfig.getRoleMappings()[0].getLocalRole().getLocalRoleName(), IDP_ROLE_1, "Failed update local role");
        Assert.assertEquals(updatedPermissionsAndRoleConfig.getRoleMappings()[0].getRemoteRole(), "spRole_1", "Failed update remote role");
    } catch (Exception e) {
        Assert.fail("Error while trying to update Roles", e);
    }
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.xsd.PermissionsAndRoleConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) ArrayList(java.util.ArrayList) LocalRole(org.wso2.carbon.identity.application.common.model.xsd.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.xsd.RoleMapping) Test(org.testng.annotations.Test)

Aggregations

RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)17 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)15 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)10 Claim (org.wso2.carbon.identity.application.common.model.Claim)8 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)8 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)8 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)7 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)7 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)7 ArrayList (java.util.ArrayList)6 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 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 Test (org.testng.annotations.Test)2 LocalRole (org.wso2.carbon.identity.application.common.model.idp.xsd.LocalRole)2