Search in sources :

Example 6 with AuthConfigFactory

use of jakarta.security.auth.message.config.AuthConfigFactory 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 7 with AuthConfigFactory

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

the class TestAuthConfigFactoryImpl method testRemovePersistentRegistration.

@Test
public void testRemovePersistentRegistration() {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    factory.registerConfigProvider(SimpleAuthConfigProvider.class.getName(), null, "L_1", "AC_1", null);
    String registrationId2 = factory.registerConfigProvider(SimpleAuthConfigProvider.class.getName(), null, "L_2", "AC_2", null);
    factory.removeRegistration(registrationId2);
    factory.refresh();
    String[] registrationIds = factory.getRegistrationIDs(null);
    for (String registrationId : registrationIds) {
        Assert.assertNotEquals(registrationId2, registrationId);
    }
}
Also used : AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory) Test(org.junit.Test)

Example 8 with AuthConfigFactory

use of jakarta.security.auth.message.config.AuthConfigFactory 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)

Example 9 with AuthConfigFactory

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

the class TestAuthConfigFactoryImpl method doTestNullClassName.

private void doTestNullClassName(boolean shouldOverrideExistingProvider, String layer, String appContext) {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    if (shouldOverrideExistingProvider) {
        factory.registerConfigProvider(SimpleAuthConfigProvider.class.getName(), null, layer, appContext, null);
    }
    String registrationId = factory.registerConfigProvider(null, null, layer, appContext, null);
    factory.refresh();
    String[] registrationIds = factory.getRegistrationIDs(null);
    Set<String> ids = new HashSet<>(Arrays.asList(registrationIds));
    Assert.assertTrue(ids.contains(registrationId));
    AuthConfigProvider provider = factory.getConfigProvider(layer, appContext, null);
    Assert.assertNull(provider);
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory) HashSet(java.util.HashSet)

Example 10 with AuthConfigFactory

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

the class TestAuthConfigFactoryImpl method testDetachListener.

@Test
public void testDetachListener() {
    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);
    String[] registrationIds = factory.detachListener(listener1, "L_1", "AC_1");
    Assert.assertTrue(registrationIds.length == 1);
    Assert.assertEquals(registrationId, registrationIds[0]);
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(jakarta.security.auth.message.config.AuthConfigFactory) Test(org.junit.Test)

Aggregations

AuthConfigFactory (jakarta.security.auth.message.config.AuthConfigFactory)10 AuthConfigProvider (jakarta.security.auth.message.config.AuthConfigProvider)9 Test (org.junit.Test)5 HashSet (java.util.HashSet)2 ArrayList (java.util.ArrayList)1