Search in sources :

Example 11 with AuthConfigProvider

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

the class AuthenticatorBase method authenticate.

@Override
public boolean authenticate(Request request, HttpServletResponse httpResponse) throws IOException {
    AuthConfigProvider jaspicProvider = getJaspicProvider();
    if (jaspicProvider == null) {
        return doAuthenticate(request, httpResponse);
    } else {
        Response response = request.getResponse();
        JaspicState jaspicState = getJaspicState(jaspicProvider, request, response, true);
        if (jaspicState == null) {
            return false;
        }
        boolean result = authenticateJaspic(request, response, jaspicState, true);
        secureResponseJspic(request, response, jaspicState);
        return result;
    }
}
Also used : Response(org.apache.catalina.connector.Response) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider)

Example 12 with AuthConfigProvider

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

the class AuthConfigFactoryImpl method createAuthConfigProvider.

private AuthConfigProvider createAuthConfigProvider(String className, @SuppressWarnings("rawtypes") Map properties) throws SecurityException {
    Class<?> clazz = null;
    AuthConfigProvider provider = null;
    try {
        clazz = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
    } catch (ClassNotFoundException e) {
    // Ignore so the re-try below can proceed
    }
    try {
        if (clazz == null) {
            clazz = Class.forName(className);
        }
        Constructor<?> constructor = clazz.getConstructor(Map.class, AuthConfigFactory.class);
        provider = (AuthConfigProvider) constructor.newInstance(properties, null);
    } catch (ReflectiveOperationException | IllegalArgumentException e) {
        throw new SecurityException(e);
    }
    return provider;
}
Also used : AuthConfigProvider(jakarta.security.auth.message.config.AuthConfigProvider)

Example 13 with AuthConfigProvider

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

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

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