use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.
the class JexlClaimsMapperTest method testUpdateIssuer.
@Test
public void testUpdateIssuer() throws IOException {
ProcessedClaimCollection result = jcm.mapClaims("A", createClaimCollection(), "B", createProperties());
assertNotNull(result);
assertEquals("STS-B", result.get(0).getOriginalIssuer());
assertEquals("NewIssuer", result.get(0).getIssuer());
assertEquals("STS-A", result.get(1).getOriginalIssuer());
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.
the class JexlClaimsMapperTest method testStaticClaim.
@Test
public void testStaticClaim() throws IOException {
ProcessedClaimCollection result = jcm.mapClaims("A", createClaimCollection(), "B", createProperties());
assertNotNull(result);
ProcessedClaim staticClaim = findClaim(result, "http://schemas.microsoft.com/identity/claims/identityprovider");
assertNotNull(staticClaim);
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.
the class CustomAttributeProvider method getStatement.
/**
* Get an AttributeStatementBean using the given parameters.
*/
public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
List<AttributeBean> attributeList = new ArrayList<>();
TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
String tokenType = tokenRequirements.getTokenType();
// Handle Claims
ProcessedClaimCollection retrievedClaims = ClaimsUtils.processClaims(providerParameters);
AttributeStatementBean attrBean = new AttributeStatementBean();
Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
if (!claimIterator.hasNext()) {
// If no Claims have been processed then create a default attribute
AttributeBean attributeBean = createDefaultAttribute(tokenType);
attributeList.add(attributeBean);
}
while (claimIterator.hasNext()) {
ProcessedClaim claim = claimIterator.next();
AttributeBean attributeBean = createAttributeFromClaim(claim, tokenType);
attributeList.add(attributeBean);
}
ReceivedToken onBehalfOf = tokenRequirements.getOnBehalfOf();
ReceivedToken actAs = tokenRequirements.getActAs();
try {
if (onBehalfOf != null) {
AttributeBean parameterBean = handleAdditionalParameters(false, onBehalfOf.getToken(), tokenType);
if (!parameterBean.getAttributeValues().isEmpty()) {
attributeList.add(parameterBean);
}
}
if (actAs != null) {
AttributeBean parameterBean = handleAdditionalParameters(true, actAs.getToken(), tokenType);
if (!parameterBean.getAttributeValues().isEmpty()) {
attributeList.add(parameterBean);
}
}
} catch (WSSecurityException ex) {
throw new STSException(ex.getMessage(), ex);
}
attrBean.setSamlAttributes(attributeList);
return attrBean;
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection in project cxf by apache.
the class CustomUserClaimsHandler method retrieveClaimValues.
public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {
if (claims != null && !claims.isEmpty()) {
ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
for (Claim requestClaim : claims) {
ProcessedClaim claim = new ProcessedClaim();
claim.setClaimType(requestClaim.getClaimType());
if (ClaimTypes.FIRSTNAME.equals(requestClaim.getClaimType())) {
if (parameters.getPrincipal().getName().equalsIgnoreCase("alice")) {
claim.addValue("aliceClaim");
} else if (parameters.getPrincipal().getName().equalsIgnoreCase("bob")) {
claim.addValue("bobClaim");
}
}
claimCollection.add(claim);
}
return claimCollection;
}
return null;
}
use of org.apache.cxf.sts.claims.ProcessedClaimCollection 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(URI.create("Claim-A")));
RealmSupportClaimsHandler realmBHandler = new RealmSupportClaimsHandler();
realmBHandler.setRealm("B");
realmBHandler.setSupportedClaimTypes(Collections.singletonList(URI.create("Claim-B")));
RealmSupportClaimsHandler realmCHandler = new RealmSupportClaimsHandler();
realmCHandler.setRealm("A");
realmCHandler.setSupportedRealms(Collections.singletonList("A"));
realmCHandler.setSupportedClaimTypes(Collections.singletonList(URI.create("Claim-C")));
List<ClaimsHandler> claimHandlers = new ArrayList<>();
claimHandlers.add(realmAHandler);
claimHandlers.add(realmBHandler);
claimHandlers.add(realmCHandler);
claimsManager.setClaimHandlers(Collections.unmodifiableList(claimHandlers));
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
}
Aggregations