Search in sources :

Example 46 with ProcessedClaim

use of org.apache.cxf.sts.claims.ProcessedClaim 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);
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) LdapClaimsHandler(org.apache.cxf.sts.claims.LdapClaimsHandler) URI(java.net.URI) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters) CustomTokenPrincipal(org.apache.wss4j.common.principal.CustomTokenPrincipal) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ByteArrayInputStream(java.io.ByteArrayInputStream) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim)

Aggregations

ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)46 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)35 ArrayList (java.util.ArrayList)15 Claim (org.apache.cxf.rt.security.claims.Claim)12 Test (org.junit.Test)12 URI (java.net.URI)11 ClaimsParameters (org.apache.cxf.sts.claims.ClaimsParameters)9 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)8 ClaimsManager (org.apache.cxf.sts.claims.ClaimsManager)6 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)6 Principal (java.security.Principal)5 LdapClaimsHandler (org.apache.cxf.sts.claims.LdapClaimsHandler)5 List (java.util.List)4 X500Principal (javax.security.auth.x500.X500Principal)3 Connection (org.forgerock.opendj.ldap.Connection)3 BindResult (org.forgerock.opendj.ldap.responses.BindResult)3 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)3 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)3 GuestPrincipal (ddf.security.principal.GuestPrincipal)2 AttributeBean (org.apache.wss4j.common.saml.bean.AttributeBean)2