use of org.apache.cxf.sts.claims.LdapClaimsHandler in project cxf by apache.
the class LDAPClaimsTest method testRetrieveClaims.
@org.junit.Test
public void testRetrieveClaims() throws Exception {
LdapClaimsHandler claimsHandler = (LdapClaimsHandler) appContext.getBean("testClaimsHandler");
ClaimsManager claimsManager = new ClaimsManager();
claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
String user = props.getProperty("claimUser");
Assert.assertNotNull(user, "Property 'claimUser' not configured");
ClaimCollection requestedClaims = createRequestClaimCollection();
List<URI> expectedClaims = new ArrayList<>();
expectedClaims.add(ClaimTypes.FIRSTNAME);
expectedClaims.add(ClaimTypes.LASTNAME);
expectedClaims.add(ClaimTypes.EMAILADDRESS);
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());
for (ProcessedClaim c : retrievedClaims) {
if (expectedClaims.contains(c.getClaimType())) {
expectedClaims.remove(c.getClaimType());
} else {
Assert.assertTrue("Claim '" + c.getClaimType() + "' not requested", false);
}
}
}
use of org.apache.cxf.sts.claims.LdapClaimsHandler 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);
}
Aggregations