Search in sources :

Example 6 with AuthConfigProvider

use of javax.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(javax.security.auth.message.config.AuthConfigProvider) ArrayList(java.util.ArrayList) AuthConfigFactory(javax.security.auth.message.config.AuthConfigFactory)

Example 7 with AuthConfigProvider

use of javax.security.auth.message.config.AuthConfigProvider in project jetty.project by eclipse.

the class JaspiAuthenticatorFactory method getAuthenticator.

/* ------------------------------------------------------------ */
public Authenticator getAuthenticator(Server server, ServletContext context, AuthConfiguration configuration, IdentityService identityService, LoginService loginService) {
    Authenticator authenticator = null;
    try {
        AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
        RegistrationListener listener = new RegistrationListener() {

            public void notify(String layer, String appContext) {
            }
        };
        Subject serviceSubject = findServiceSubject(server);
        String serverName = findServerName(server, serviceSubject);
        String contextPath = context.getContextPath();
        if (contextPath == null || contextPath.length() == 0)
            contextPath = "/";
        String appContext = serverName + " " + context.getContextPath();
        AuthConfigProvider authConfigProvider = authConfigFactory.getConfigProvider(MESSAGE_LAYER, appContext, listener);
        if (authConfigProvider != null) {
            ServletCallbackHandler servletCallbackHandler = new ServletCallbackHandler(loginService);
            ServerAuthConfig serverAuthConfig = authConfigProvider.getServerAuthConfig(MESSAGE_LAYER, appContext, servletCallbackHandler);
            if (serverAuthConfig != null) {
                Map map = new HashMap();
                for (String key : configuration.getInitParameterNames()) map.put(key, configuration.getInitParameter(key));
                authenticator = new JaspiAuthenticator(serverAuthConfig, map, servletCallbackHandler, serviceSubject, true, identityService);
            }
        }
    } catch (AuthException e) {
        LOG.warn(e);
    }
    return authenticator;
}
Also used : RegistrationListener(javax.security.auth.message.config.RegistrationListener) AuthConfigProvider(javax.security.auth.message.config.AuthConfigProvider) HashMap(java.util.HashMap) AuthConfigFactory(javax.security.auth.message.config.AuthConfigFactory) AuthException(javax.security.auth.message.AuthException) HashMap(java.util.HashMap) Map(java.util.Map) Authenticator(org.eclipse.jetty.security.Authenticator) Subject(javax.security.auth.Subject) ServerAuthConfig(javax.security.auth.message.config.ServerAuthConfig)

Example 8 with AuthConfigProvider

use of javax.security.auth.message.config.AuthConfigProvider in project wildfly by wildfly.

the class JASPICSecurityContext method login.

/**
     * <p>
     * JASPIC 1.1 specification: if there is an {@code AuthConfigProvider} for the {@code HttpServlet} layer and
     * application context, then @{@code login} must throw a {@code ServletException} which may convey that the
     * exception was caused by an incompatibility between the {@code login} method and the configured authentication
     * mechanism. If there is no such provider, then the container must proceed with the regular {@code login} processing.
     * </p>
     *
     * @param username The username
     * @param password The password
     * @return <code>true</code> if the login succeeded, false otherwise
     * @throws SecurityException if login is called when JASPIC is enabled for application context and layer.
     */
@Override
public boolean login(final String username, final String password) {
    // if there is an AuthConfigProvider for the HttpServlet layer and appContext, this method must throw an exception.
    String appContext = this.buildAppContext();
    AuthConfigProvider provider = AuthConfigFactory.getFactory().getConfigProvider(layer, appContext, null);
    if (provider != null) {
        ServletException se = new ServletException("login is not supported by the JASPIC mechanism");
        throw new SecurityException(se);
    }
    return super.login(username, password);
}
Also used : ServletException(javax.servlet.ServletException) AuthConfigProvider(javax.security.auth.message.config.AuthConfigProvider)

Example 9 with AuthConfigProvider

use of javax.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 : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.catalina.connector.Response) AuthConfigProvider(javax.security.auth.message.config.AuthConfigProvider)

Example 10 with AuthConfigProvider

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

the class TestAuthConfigFactoryImpl method doTestResistration.

private void doTestResistration(String layer, String appContext, String expectedRegId) {
    AuthConfigFactory factory = new AuthConfigFactoryImpl();
    AuthConfigProvider acp1 = new SimpleAuthConfigProvider(null, null);
    SimpleRegistrationListener listener = new SimpleRegistrationListener(layer, appContext);
    String regId = factory.registerConfigProvider(acp1, layer, appContext, null);
    Assert.assertEquals(expectedRegId, regId);
    factory.getConfigProvider(layer, appContext, listener);
    factory.removeRegistration(regId);
    Assert.assertTrue(listener.wasCorrectlyCalled());
    listener.reset();
    factory.registerConfigProvider(acp1, layer, appContext, null);
    factory.getConfigProvider(layer, appContext, listener);
    // Replace it
    AuthConfigProvider acp2 = new SimpleAuthConfigProvider(null, null);
    factory.registerConfigProvider(acp2, layer, appContext, null);
    Assert.assertTrue(listener.wasCorrectlyCalled());
}
Also used : AuthConfigProvider(javax.security.auth.message.config.AuthConfigProvider) AuthConfigFactory(javax.security.auth.message.config.AuthConfigFactory)

Aggregations

AuthConfigProvider (javax.security.auth.message.config.AuthConfigProvider)10 AuthConfigFactory (javax.security.auth.message.config.AuthConfigFactory)5 Principal (java.security.Principal)2 Subject (javax.security.auth.Subject)2 AuthException (javax.security.auth.message.AuthException)2 ServerAuthConfig (javax.security.auth.message.config.ServerAuthConfig)2 TomcatPrincipal (org.apache.catalina.TomcatPrincipal)2 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MessageInfo (javax.security.auth.message.MessageInfo)1 RegistrationListener (javax.security.auth.message.config.RegistrationListener)1 ServerAuthContext (javax.security.auth.message.config.ServerAuthContext)1 ServletException (javax.servlet.ServletException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Realm (org.apache.catalina.Realm)1 Session (org.apache.catalina.Session)1