Search in sources :

Example 11 with GenericPrincipal

use of org.apache.catalina.realm.GenericPrincipal in project tomcat by apache.

the class DeltaRequest method setPrincipal.

/**
     * Only support principals from type {@link GenericPrincipal GenericPrincipal}
     * @param p Session principal
     * @see GenericPrincipal
     */
public void setPrincipal(Principal p) {
    int action = (p == null) ? ACTION_REMOVE : ACTION_SET;
    GenericPrincipal gp = null;
    if (p != null) {
        if (p instanceof GenericPrincipal) {
            gp = (GenericPrincipal) p;
            if (log.isDebugEnabled())
                log.debug(sm.getString("deltaRequest.showPrincipal", p.getName(), getSessionId()));
        } else
            log.error(sm.getString("deltaRequest.wrongPrincipalClass", p.getClass().getName()));
    }
    addAction(TYPE_PRINCIPAL, action, NAME_PRINCIPAL, gp);
}
Also used : GenericPrincipal(org.apache.catalina.realm.GenericPrincipal)

Example 12 with GenericPrincipal

use of org.apache.catalina.realm.GenericPrincipal 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 13 with GenericPrincipal

use of org.apache.catalina.realm.GenericPrincipal 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

GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)13 Principal (java.security.Principal)4 CdiEventRealm (org.apache.tomee.catalina.realm.CdiEventRealm)4 Test (org.junit.Test)4 Subject (javax.security.auth.Subject)2 X509Certificate (java.security.cert.X509Certificate)1 Map (java.util.Map)1 Callback (javax.security.auth.callback.Callback)1 AuthException (javax.security.auth.message.AuthException)1 AuthStatus (javax.security.auth.message.AuthStatus)1 CallerPrincipalCallback (javax.security.auth.message.callback.CallerPrincipalCallback)1 GroupPrincipalCallback (javax.security.auth.message.callback.GroupPrincipalCallback)1 TomcatPrincipal (org.apache.catalina.TomcatPrincipal)1 SerializablePrincipal (org.apache.catalina.ha.session.SerializablePrincipal)1 CallerPrincipal (org.apache.openejb.spi.CallerPrincipal)1