Java Code Examples for org.wso2.carbon.identity.application.common.model.ClaimMapping#build()

The following examples show how to use org.wso2.carbon.identity.application.common.model.ClaimMapping#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultClaimFilterTest.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilterRequestedClaimsFromSpConfigAndRequest() throws Exception {

    DefaultClaimFilter defaultClaimFilter = new DefaultClaimFilter();
    List<ClaimMapping> filteredClaims;

    filteredClaims = defaultClaimFilter.filterRequestedClaims(spClaimMappings,
            requestedClaimsInRequest);
    assertEquals(filteredClaims.size(), 0, "Error in filtering requested claims in sp config and " +
            "request.");

    ClaimMapping claimMapping = ClaimMapping.build(personIDLocalClaimUri, personIDRemoteClaimUri, null,
            true, true);
    spClaimMappings.add(claimMapping);

    filteredClaims = defaultClaimFilter.filterRequestedClaims(spClaimMappings,
            requestedClaimsInRequest);
    assertEquals(filteredClaims.size(), 1, "Error in filtering requested claims in sp config and " +
            "request.");
    assertEquals(filteredClaims.get(0).getLocalClaim().getClaimUri(), personIDLocalClaimUri,
            "Error in filtering requested claims in sp config and request.");
    assertEquals(filteredClaims.get(0).getRemoteClaim().getClaimUri(), personIDRemoteClaimUri,
            "Error in filtering requested claims in sp config and request.");
}
 
Example 2
Source File: JsAuthenticationContextTest.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteAddition() throws ScriptException {

    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    AuthenticationContext authenticationContext = new AuthenticationContext();
    setupAuthContextWithStepData(authenticationContext, authenticatedUser);

    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);

    scriptEngine.eval("context.steps[1].subject.remoteClaims['testClaim']='testValue'");

    ClaimMapping claimMapping = ClaimMapping.build("testClaim", "testClaim", "", false);
    String claimCreatedByJs = authenticatedUser.getUserAttributes().get(claimMapping);
    assertEquals(claimCreatedByJs, "testValue");
}
 
Example 3
Source File: UpdateClaimConfiguration.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private ClaimMapping buildRequestClaimMapping(RequestedClaimConfiguration requestedClaimConfiguration) {

        String claimUri = getClaimUri(requestedClaimConfiguration);
        ClaimMapping claimMapping = ClaimMapping.build(claimUri, claimUri, null, true);
        // Set whether claim is mandatory.
        setIfNotNull(requestedClaimConfiguration.getMandatory(), claimMapping::setMandatory);

        return claimMapping;
    }
 
Example 4
Source File: JsClaims.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a custom remote claim to the user.
 *
 * @param claimUri   Remote claim uri
 * @param claimValue Claim value
 */
private void setFederatedClaim(String claimUri, Object claimValue) {

    if (claimValue == null) {
        claimValue = StringUtils.EMPTY;
    }
    ClaimMapping newClaimMapping = ClaimMapping.build(claimUri, claimUri, null, false);
    authenticatedUser.getUserAttributes().put(newClaimMapping, String.valueOf(claimValue));
}
 
Example 5
Source File: DefaultStepBasedSequenceHandlerTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@DataProvider(name = "idpClaimMappingProvider")
public Object[][] getIdpClaimMappingsProvider() {
    return new Object[][]{
            {       // SP mapped role claim
                    new ClaimMapping[]{
                            ClaimMapping.build(FrameworkConstants.LOCAL_ROLE_CLAIM_URI, "IDP_ROLE_CLAIM", "", true)
                    },
                    "IDP_ROLE_CLAIM"
            },
            {       // Role claim not among SP mapped claims
                    new ClaimMapping[]{
                            ClaimMapping.build("LOCAL_CLAIM", "IDP_CLAIM", "", true)
                    },
                    null
            },
            {       // Role claim among claim mappings but remote claim is null
                    new ClaimMapping[]{
                            ClaimMapping.build(FrameworkConstants.LOCAL_ROLE_CLAIM_URI, null, null, true)
                    },
                    null
            },
            {      // No IDP mapped claims
                    new ClaimMapping[0], null
            },
            {
                    null, null
            }
    };
}
 
Example 6
Source File: DefaultClaimFilterTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setRequestedClaimsInRequest() throws Exception {

    ClaimMapping claimMapping = ClaimMapping.build(personIDLocalClaimUri, personIDRemoteClaimUri, null,
            true, true);
    requestedClaimsInRequest.add(claimMapping);
}
 
Example 7
Source File: DefaultClaimFilterTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setSpClaimMappings() throws Exception {

    ClaimMapping claimMapping = ClaimMapping.build(legalPersonIdLocalClaimUri, legalPersonIdRemoteClaimUri, null,
            true, true);
    spClaimMappings.add(claimMapping);
}
 
Example 8
Source File: JsAuthenticationContextTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testClaimAssignment() throws ScriptException {

    ClaimMapping claimMapping1 = ClaimMapping.build("", "", "", false);

    ClaimMapping claimMapping2 = ClaimMapping.build("Test.Remote.Claim.Url.2", "Test.Remote.Claim.Url.2", "",
        false);

    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.getUserAttributes().put(claimMapping1, "TestClaimVal1");
    authenticatedUser.getUserAttributes().put(claimMapping2, "TestClaimVal2");
    AuthenticationContext authenticationContext = new AuthenticationContext();
    setupAuthContextWithStepData(authenticationContext, authenticatedUser);

    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);

    Object result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.1']");
    assertNull(result);
    result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']");
    assertEquals(result, "TestClaimVal2");

    scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2'] = 'Modified2'");
    result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']");
    assertEquals(result, "Modified2");

}
 
Example 9
Source File: UpdateClaimConfiguration.java    From identity-api-server with Apache License 2.0 2 votes vote down vote up
private ClaimMapping buildClaimMapping(ClaimMappings mapping) {

        return ClaimMapping.build(mapping.getLocalClaim().getUri(), mapping.getApplicationClaim(), null, false);
    }