use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class LDAPClaimsTest method testRetrieveBinaryClaims.
@org.junit.Test
public void testRetrieveBinaryClaims() throws Exception {
LdapClaimsHandler claimsHandler = (LdapClaimsHandler) appContext.getBean("testClaimsHandler");
ClaimsManager claimsManager = new ClaimsManager();
claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
String user = props.getProperty("binaryClaimUser");
Assert.assertNotNull(user, "Property 'binaryClaimUser' not configured");
ClaimCollection requestedClaims = createRequestClaimCollection();
// Ask for the (binary) cert as well
Claim claim = new Claim();
claim.setClaimType(URI.create("http://custom/x509"));
claim.setOptional(true);
requestedClaims.add(claim);
List<URI> expectedClaims = new ArrayList<>();
expectedClaims.add(ClaimTypes.FIRSTNAME);
expectedClaims.add(ClaimTypes.LASTNAME);
expectedClaims.add(ClaimTypes.EMAILADDRESS);
expectedClaims.add(URI.create("http://custom/x509"));
ClaimsParameters params = new ClaimsParameters();
params.setPrincipal(new CustomTokenPrincipal(user));
ProcessedClaimCollection retrievedClaims = claimsManager.retrieveClaimValues(requestedClaims, params);
Assert.assertTrue("Retrieved number of claims [" + retrievedClaims.size() + "] doesn't match with expected [" + expectedClaims.size() + "]", retrievedClaims.size() == expectedClaims.size());
boolean foundCert = false;
for (ProcessedClaim c : retrievedClaims) {
if (URI.create("http://custom/x509").equals(c.getClaimType())) {
foundCert = true;
Assert.assertTrue(c.getValues().get(0) instanceof byte[]);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream((byte[]) c.getValues().get(0));
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);
Assert.assertTrue(cert != null);
}
}
Assert.assertTrue(foundCert);
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project cxf by apache.
the class LDAPClaimsTest method createRequestClaimCollection.
private ClaimCollection createRequestClaimCollection() {
ClaimCollection claims = new ClaimCollection();
Claim claim = new Claim();
claim.setClaimType(ClaimTypes.FIRSTNAME);
claim.setOptional(true);
claims.add(claim);
claim = new Claim();
claim.setClaimType(ClaimTypes.LASTNAME);
claim.setOptional(true);
claims.add(claim);
claim = new Claim();
claim.setClaimType(ClaimTypes.EMAILADDRESS);
claim.setOptional(true);
claims.add(claim);
return claims;
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project alliance by codice.
the class VideographerClaimsHandlerTest method testEmailClaim.
@SuppressWarnings("unchecked")
@Test
public void testEmailClaim() throws URISyntaxException {
claimsHandler = new VideographerClaimsHandler();
claimsHandler.setAttributes(Collections.singletonList(CLAIM_URI_2 + "=" + CLAIM_VALUE_2A + "|" + CLAIM_VALUE_2B + "|" + CLAIM_VALUE_2C));
requestClaims = new ClaimCollection();
Claim requestClaim = new Claim();
URI emailURI = new URI(CLAIM_URI_2);
requestClaim.setClaimType(emailURI);
requestClaims.add(requestClaim);
claimsParameters = new ClaimsParameters();
claimsParameters.setPrincipal(new VideographerPrincipal(IP_ADDR));
claimsCollection = claimsHandler.retrieveClaimValues(requestClaims, claimsParameters);
assertThat(claimsCollection, containsInAnyOrder(getEmailClaim(emailURI), getIpClaim()));
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project alliance by codice.
the class VideographerClaimsHandlerTest method createClaims.
private void createClaims() throws URISyntaxException {
requestClaims = new ClaimCollection();
Claim requestClaim = new Claim();
URI nameURI = new URI(CLAIM_URI_1);
requestClaim.setClaimType(nameURI);
requestClaims.add(requestClaim);
requestClaim = new Claim();
URI emailURI = new URI(CLAIM_URI_2);
requestClaim.setClaimType(emailURI);
requestClaims.add(requestClaim);
requestClaim = new Claim();
URI fooURI = new URI("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/foobar");
requestClaim.setClaimType(fooURI);
requestClaim.setOptional(true);
requestClaims.add(requestClaim);
}
use of org.apache.cxf.rt.security.claims.ClaimCollection in project cas by apereo.
the class WrappingSecurityTokenServiceClaimsHandlerTests method verifyClaimNoClaims.
@Test
public void verifyClaimNoClaims() {
val claims = new ClaimCollection();
val parameters = new ClaimsParameters();
parameters.setRealm("CAS");
parameters.setPrincipal(mock(Principal.class));
val handler = new WrappingSecurityTokenServiceClaimsHandler("CAS", "https://apereo.org/cas");
assertTrue(handler.retrieveClaimValues(claims, parameters).isEmpty());
}
Aggregations