Search in sources :

Example 1 with CdiEventRealm

use of org.apache.tomee.catalina.realm.CdiEventRealm in project tomee by apache.

the class CdiEventRealmTest method ssl.

@Test
public void ssl() {
    X509Certificate cert = mock(X509Certificate.class);
    GenericPrincipal expected = new GenericPrincipal("john", "doe", Arrays.asList("test"));
    when(cert.getSubjectDN()).thenReturn(expected);
    final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate(new X509Certificate[] { cert }));
    assertEquals(expected, gp);
    assertEquals("john", gp.getName());
    assertEquals("doe", gp.getPassword());
    assertEquals(1, gp.getRoles().length);
    assertEquals("test", gp.getRoles()[0]);
}
Also used : CdiEventRealm(org.apache.tomee.catalina.realm.CdiEventRealm) GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 2 with CdiEventRealm

use of org.apache.tomee.catalina.realm.CdiEventRealm in project tomee by apache.

the class CdiEventRealmTest method gss.

@Test
public void gss() {
    final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate(mock(GSSContext.class), false));
    assertEquals("gss", gp.getName());
    assertEquals("", gp.getPassword());
    assertEquals(1, gp.getRoles().length);
    assertEquals("dummy", gp.getRoles()[0]);
}
Also used : CdiEventRealm(org.apache.tomee.catalina.realm.CdiEventRealm) GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) Test(org.junit.Test)

Example 3 with CdiEventRealm

use of org.apache.tomee.catalina.realm.CdiEventRealm in project tomee by apache.

the class CdiEventRealmTest method digest.

@Test
public void digest() {
    final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate("ryan", "md5", "nonce", "nc", "cnonce", "qop", "realm", "md5a2"));
    final String[] actual = gp.getRoles();
    final String[] expected = new String[] { "ryan", "md5", "nonce", "nc", "cnonce", "qop", "realm", "md5a2" };
    Arrays.sort(actual);
    Arrays.sort(expected);
    assertArrayEquals(actual, expected);
}
Also used : CdiEventRealm(org.apache.tomee.catalina.realm.CdiEventRealm) GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) Test(org.junit.Test)

Example 4 with CdiEventRealm

use of org.apache.tomee.catalina.realm.CdiEventRealm in project tomee by apache.

the class CdiEventRealmTest method find.

@Test
public void find() {
    final SecurityConstraint[] securityConstraints = new CdiEventRealm().findSecurityConstraints(mock(Request.class), mock(Context.class));
    assertEquals(1, securityConstraints.length);
    final SecurityConstraint c = securityConstraints[0];
    assertEquals("CONFIDENTIAL", c.getUserConstraint());
    assertEquals(2, c.findAuthRoles().length);
    assertEquals(1, c.findCollections().length);
    SecurityCollection sc = c.findCollections()[0];
    assertTrue(sc.findPattern("/*"));
}
Also used : GSSContext(org.ietf.jgss.GSSContext) Context(org.apache.catalina.Context) CdiEventRealm(org.apache.tomee.catalina.realm.CdiEventRealm) Request(org.apache.catalina.connector.Request) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection) Test(org.junit.Test)

Example 5 with CdiEventRealm

use of org.apache.tomee.catalina.realm.CdiEventRealm in project tomee by apache.

the class CdiEventRealmTest method userPassword.

@Test
public void userPassword() {
    final GenericPrincipal gp = getGenericPrincipal(new CdiEventRealm().authenticate("john", "secret"));
    assertEquals("john", gp.getName());
    assertEquals("", gp.getPassword());
    assertEquals(1, gp.getRoles().length);
    assertEquals("admin", gp.getRoles()[0]);
}
Also used : CdiEventRealm(org.apache.tomee.catalina.realm.CdiEventRealm) GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) Test(org.junit.Test)

Aggregations

CdiEventRealm (org.apache.tomee.catalina.realm.CdiEventRealm)5 Test (org.junit.Test)5 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)4 X509Certificate (java.security.cert.X509Certificate)1 Context (org.apache.catalina.Context)1 Request (org.apache.catalina.connector.Request)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 GSSContext (org.ietf.jgss.GSSContext)1