use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class RealmSupportTest method testFilteredRealmAIdentityMapping.
@org.junit.Test
public void testFilteredRealmAIdentityMapping() throws Exception {
ClaimsManager claimsManager = new ClaimsManager();
claimsManager.setIdentityMapper(new CustomIdentityMapper());
RealmSupportClaimsHandler realmAHandler = new RealmSupportClaimsHandler();
realmAHandler.setRealm("A");
realmAHandler.setSupportedClaimTypes(Collections.singletonList("Claim-A"));
RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
realmBHandler.setRealm("B");
realmBHandler.setSupportedClaimTypes(Collections.singletonList("Claim-B"));
RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
realmCHandler.setRealm("A");
realmCHandler.setSupportedRealms(Collections.singletonList("A"));
realmCHandler.setSupportedClaimTypes(Collections.singletonList("Claim-C"));
claimsManager.setClaimHandlers(Arrays.asList(realmAHandler, realmBHandler, realmCHandler));
ClaimCollection requestedClaims = createClaimCollection();
ClaimsParameters parameters = new ClaimsParameters();
parameters.setRealm("A");
parameters.setPrincipal(new CustomTokenPrincipal("alice"));
ProcessedClaimCollection claims = claimsManager.retrieveClaimValues(requestedClaims, parameters);
Assert.assertEquals("Number of claims incorrect", 3, claims.size());
// Asserts in RealmSupportClaimsHandler must succeed
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class RealmSupportTest method testFilteredRealmBIdentityMapping.
@org.junit.Test
public void testFilteredRealmBIdentityMapping() throws Exception {
ClaimsManager claimsManager = new ClaimsManager();
claimsManager.setIdentityMapper(new CustomIdentityMapper());
RealmSupportClaimsHandler realmAHandler = new RealmSupportClaimsHandler();
realmAHandler.setRealm("A");
realmAHandler.setSupportedClaimTypes(Collections.singletonList("Claim-A"));
RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
realmBHandler.setRealm("B");
realmBHandler.setSupportedClaimTypes(Collections.singletonList("Claim-B"));
RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
realmCHandler.setRealm("A");
realmCHandler.setSupportedRealms(Collections.singletonList("A"));
realmCHandler.setSupportedClaimTypes(Collections.singletonList("Claim-C"));
claimsManager.setClaimHandlers(Arrays.asList(realmAHandler, realmBHandler, realmCHandler));
ClaimCollection requestedClaims = createClaimCollection();
ClaimsParameters parameters = new ClaimsParameters();
parameters.setRealm("B");
parameters.setPrincipal(new CustomTokenPrincipal("ALICE"));
ProcessedClaimCollection claims = claimsManager.retrieveClaimValues(requestedClaims, parameters);
Assert.assertEquals("Number of claims incorrect", 2, claims.size());
// Asserts in RealmSupportClaimsHandler must succeed
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class RealmSupportTest method testIdentityMappingRealmB2A.
@org.junit.Test
public void testIdentityMappingRealmB2A() throws Exception {
ClaimsManager claimsManager = new ClaimsManager();
claimsManager.setIdentityMapper(new CustomIdentityMapper());
RealmSupportClaimsHandler realmAHandler = new RealmSupportClaimsHandler();
realmAHandler.setRealm("A");
realmAHandler.setSupportedClaimTypes(Collections.singletonList("Claim-A"));
RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
realmBHandler.setRealm("B");
realmBHandler.setSupportedClaimTypes(Collections.singletonList("Claim-B"));
RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
realmCHandler.setRealm("B");
realmCHandler.setSupportedClaimTypes(Collections.singletonList("Claim-C"));
claimsManager.setClaimHandlers(Arrays.asList(realmAHandler, realmBHandler, realmCHandler));
ClaimCollection requestedClaims = createClaimCollection();
ClaimsParameters parameters = new ClaimsParameters();
parameters.setRealm("B");
parameters.setPrincipal(new CustomTokenPrincipal("ALICE"));
ProcessedClaimCollection claims = claimsManager.retrieveClaimValues(requestedClaims, parameters);
Assert.assertEquals("Number of claims incorrect", 3, claims.size());
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class ValidateTokenTransformationUnitTest method createSAMLAssertion.
/*
* Mock up an SAML assertion element
*/
private static Element createSAMLAssertion(String tokenType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler, Map<String, RealmProperties> realms) throws WSSecurityException {
SAMLTokenProvider samlTokenProvider = new SAMLTokenProvider();
samlTokenProvider.setRealmMap(realms);
samlTokenProvider.setAttributeStatementProviders(Collections.singletonList(new ClaimsAttributeStatementProvider()));
TokenProviderParameters providerParameters = createProviderParameters(tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler);
if (realms != null) {
providerParameters.setRealm("A");
}
// Set the ClaimsManager
ClaimsManager claimsManager = new ClaimsManager();
ClaimsHandler claimsHandler = new CustomClaimsHandler();
claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
providerParameters.setClaimsManager(claimsManager);
ClaimCollection requestedClaims = new ClaimCollection();
Claim requestClaim = new Claim();
requestClaim.setClaimType(ClaimTypes.LASTNAME);
requestClaim.setOptional(false);
requestedClaims.add(requestClaim);
providerParameters.setRequestedSecondaryClaims(requestedClaims);
TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
assertNotNull(providerResponse);
assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
return (Element) providerResponse.getToken();
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class JWTClaimsTest method testJWTStaticClaims.
/**
* Test the creation of a JWTToken with StaticClaimsHandler
*/
@org.junit.Test
public void testJWTStaticClaims() throws Exception {
TokenProvider tokenProvider = new JWTTokenProvider();
TokenProviderParameters providerParameters = createProviderParameters(JWTTokenProvider.JWT_TOKEN_TYPE, null);
ClaimsManager claimsManager = new ClaimsManager();
StaticClaimsHandler claimsHandler = new StaticClaimsHandler();
Map<String, String> staticClaimsMap = new HashMap<>();
staticClaimsMap.put(CLAIM_STATIC_COMPANY.toString(), CLAIM_STATIC_COMPANY_VALUE);
claimsHandler.setGlobalClaims(staticClaimsMap);
claimsManager.setClaimHandlers(Collections.singletonList((ClaimsHandler) claimsHandler));
providerParameters.setClaimsManager(claimsManager);
ClaimCollection claims = new ClaimCollection();
Claim claim = new Claim();
claim.setClaimType(CLAIM_STATIC_COMPANY);
claims.add(claim);
providerParameters.setRequestedPrimaryClaims(claims);
TokenProviderResponse providerResponse = tokenProvider.createToken(providerParameters);
assertNotNull(providerResponse);
assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
String token = (String) providerResponse.getToken();
assertNotNull(token);
JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token);
JwtToken jwt = jwtConsumer.getJwtToken();
assertEquals(jwt.getClaim(CLAIM_STATIC_COMPANY.toString()), CLAIM_STATIC_COMPANY_VALUE);
}
Aggregations