Search in sources :

Example 1 with X509Profile

use of org.pac4j.http.profile.X509Profile in project pac4j by pac4j.

the class X509ClientTests method testOk.

@Test
public void testOk() throws CertificateException {
    final var context = MockWebContext.create();
    final var certificateData = Base64.getDecoder().decode(CERTIFICATE);
    final var cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(certificateData));
    final var certs = new X509Certificate[1];
    certs[0] = cert;
    context.setRequestAttribute(X509CredentialsExtractor.CERTIFICATE_REQUEST_ATTRIBUTE, certs);
    final var credentials = (X509Credentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (X509Profile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals("jerome", profile.getId());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) X509Profile(org.pac4j.http.profile.X509Profile) ByteArrayInputStream(java.io.ByteArrayInputStream) X509Certificate(java.security.cert.X509Certificate) X509Credentials(org.pac4j.http.credentials.X509Credentials) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 X509Certificate (java.security.cert.X509Certificate)1 Test (org.junit.Test)1 MockSessionStore (org.pac4j.core.context.session.MockSessionStore)1 X509Credentials (org.pac4j.http.credentials.X509Credentials)1 X509Profile (org.pac4j.http.profile.X509Profile)1