Search in sources :

Example 6 with AuthConfigProvider

use of jakarta.security.auth.message.config.AuthConfigProvider in project tomcat by apache.

the class TestAuthConfigFactoryImpl method doTestRegistrationInsert.

private void doTestRegistrationInsert(String newLayer, String newAppContext, String expectedListenerLayer, String expectedListenerAppContext) {
    // Set up
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp1, "L_1", "AC_1", null);
    AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp2, null, "AC_2", null);
    AuthConfigProvider acp3 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp3, "L_2", null, null);
    AuthConfigProvider acp4 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp4, null, null, null);
    SimpleRegistrationListener listener1 = new SimpleRegistrationListener("L_1", "AC_1");
    factory.getConfigProvider("L_1", "AC_1", listener1);
    SimpleRegistrationListener listener2 = new SimpleRegistrationListener("L_3", "AC_2");
    factory.getConfigProvider("L_3", "AC_2", listener2);
    SimpleRegistrationListener listener3 = new SimpleRegistrationListener("L_2", "AC_3");
    factory.getConfigProvider("L_2", "AC_3", listener3);
    SimpleRegistrationListener listener4 = new SimpleRegistrationListener("L_4", "AC_4");
    factory.getConfigProvider("L_4", "AC_4", listener4);
    List<SimpleRegistrationListener> listeners = new ArrayList<>();
    listeners.add(listener1);
    listeners.add(listener2);
    listeners.add(listener3);
    listeners.add(listener4);
    // Register a new provider that will impact some existing registrations
    AuthConfigProvider acpNew = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acpNew, newLayer, newAppContext, null);
    // Check to see if the expected listener fired.
    for (SimpleRegistrationListener listener : listeners) {
        if (listener.wasCalled()) {
            Assert.assertEquals(listener.layer, expectedListenerLayer);
            Assert.assertEquals(listener.appContext, expectedListenerAppContext);
            Assert.assertTrue(listener.wasCorrectlyCalled());
        } else {
            Assert.assertFalse((listener.layer.equals(expectedListenerLayer) && listener.appContext.equals(expectedListenerAppContext)));
        }
    }
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) ArrayList(java.util.ArrayList) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory)

Example 7 with AuthConfigProvider

use of jakarta.security.auth.message.config.AuthConfigProvider in project tomcat by apache.

the class TestAuthConfigFactoryImpl method testAllRegistrationIds.

@Test
public void testAllRegistrationIds() {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null);
    String registrationId1 = factory.registerConfigProvider(acp1, "L_1", "AC_1", null);
    AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null);
    String registrationId2 = factory.registerConfigProvider(acp2, "L_2", "AC_2", null);
    String[] registrationIds = factory.getRegistrationIDs(null);
    Assert.assertTrue(registrationIds.length == 2);
    Set<String> ids = new HashSet<>(Arrays.asList(registrationIds));
    Assert.assertTrue(ids.contains(registrationId1));
    Assert.assertTrue(ids.contains(registrationId2));
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with AuthConfigProvider

use of jakarta.security.auth.message.config.AuthConfigProvider in project tomcat by apache.

the class TestAuthConfigFactoryImpl method testDetachListenerNonexistingRegistration.

@Test
public void testDetachListenerNonexistingRegistration() {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null);
    String registrationId = factory.registerConfigProvider(acp1, "L_1", "AC_1", null);
    SimpleRegistrationListener listener1 = new SimpleRegistrationListener("L_1", "AC_1");
    factory.getConfigProvider("L_1", "AC_1", listener1);
    factory.removeRegistration(registrationId);
    String[] registrationIds = factory.detachListener(listener1, "L_1", "AC_1");
    Assert.assertTrue(registrationIds.length == 0);
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory) Test(org.junit.Test)

Example 9 with AuthConfigProvider

use of jakarta.security.auth.message.config.AuthConfigProvider in project tomcat by apache.

the class TestAuthConfigFactoryImpl method doTestSearchOrder.

private void doTestSearchOrder(String layer, String appContext, int expected) {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp1, null, null, "1");
    AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp2, null, "AC_1", "2");
    AuthConfigProvider acp3 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp3, "L_1", null, "3");
    AuthConfigProvider acp4 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp4, "L_2", "AC_2", "4");
    AuthConfigProvider searchResult = factory.getConfigProvider(layer, appContext, null);
    int searchIndex;
    if (searchResult == acp1) {
        searchIndex = 1;
    } else if (searchResult == acp2) {
        searchIndex = 2;
    } else if (searchResult == acp3) {
        searchIndex = 3;
    } else if (searchResult == acp4) {
        searchIndex = 4;
    } else {
        searchIndex = -1;
    }
    Assert.assertEquals(expected, searchIndex);
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory)

Example 10 with AuthConfigProvider

use of jakarta.security.auth.message.config.AuthConfigProvider in project tomcat by apache.

the class TestAuthConfigFactoryImpl method testRegistrationNullListener.

@Test
public void testRegistrationNullListener() {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null);
    String registrationId = factory.registerConfigProvider(acp1, "L_1", "AC_1", null);
    factory.getConfigProvider("L_1", "AC_1", null);
    boolean result = factory.removeRegistration(registrationId);
    Assert.assertTrue(result);
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory) Test(org.junit.Test)

Aggregations

AuthConfigProvider (jakarta.security.auth.message.config.AuthConfigProvider)14 AuthConfigFactory (jakarta.security.auth.message.config.AuthConfigFactory)9 Test (org.junit.Test)4 Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 TomcatPrincipal (org.apache.catalina.TomcatPrincipal)2 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)2 AuthException (jakarta.security.auth.message.AuthException)1 MessageInfo (jakarta.security.auth.message.MessageInfo)1 ServerAuthConfig (jakarta.security.auth.message.config.ServerAuthConfig)1 ServerAuthContext (jakarta.security.auth.message.config.ServerAuthContext)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 ArrayList (java.util.ArrayList)1 Subject (javax.security.auth.Subject)1 Realm (org.apache.catalina.Realm)1 Session (org.apache.catalina.Session)1 MessageInfoImpl (org.apache.catalina.authenticator.jaspic.MessageInfoImpl)1 Response (org.apache.catalina.connector.Response)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1