Search in sources :

Example 1 with ServerAuthModule

use of jakarta.security.auth.message.module.ServerAuthModule in project tomcat by apache.

the class SimpleServerAuthContext method validateRequest.

// JASPIC API uses raw types
@SuppressWarnings("unchecked")
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
    for (int moduleIndex = 0; moduleIndex < modules.size(); moduleIndex++) {
        ServerAuthModule module = modules.get(moduleIndex);
        AuthStatus result = module.validateRequest(messageInfo, clientSubject, serviceSubject);
        if (result != AuthStatus.SEND_FAILURE) {
            messageInfo.getMap().put("moduleIndex", Integer.valueOf(moduleIndex));
            return result;
        }
    }
    return AuthStatus.SEND_FAILURE;
}
Also used : AuthStatus(jakarta.security.auth.message.AuthStatus) ServerAuthModule(jakarta.security.auth.message.module.ServerAuthModule)

Example 2 with ServerAuthModule

use of jakarta.security.auth.message.module.ServerAuthModule in project tomcat by apache.

the class SimpleServerAuthConfig method getAuthContext.

// JASPIC API uses raw types
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public ServerAuthContext getAuthContext(String authContextID, Subject serviceSubject, Map properties) throws AuthException {
    ServerAuthContext serverAuthContext = this.serverAuthContext;
    if (serverAuthContext == null) {
        synchronized (this) {
            if (this.serverAuthContext == null) {
                Map<String, String> mergedProperties = new HashMap<>();
                if (this.properties != null) {
                    mergedProperties.putAll(this.properties);
                }
                if (properties != null) {
                    mergedProperties.putAll(properties);
                }
                List<ServerAuthModule> modules = new ArrayList<>();
                int moduleIndex = 1;
                String key = SERVER_AUTH_MODULE_KEY_PREFIX + moduleIndex;
                String moduleClassName = mergedProperties.get(key);
                while (moduleClassName != null) {
                    try {
                        Class<?> clazz = Class.forName(moduleClassName);
                        ServerAuthModule module = (ServerAuthModule) clazz.getConstructor().newInstance();
                        module.initialize(null, null, handler, mergedProperties);
                        modules.add(module);
                    } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) {
                        AuthException ae = new AuthException();
                        ae.initCause(e);
                        throw ae;
                    }
                    // Look for the next module
                    moduleIndex++;
                    key = SERVER_AUTH_MODULE_KEY_PREFIX + moduleIndex;
                    moduleClassName = mergedProperties.get(key);
                }
                if (modules.size() == 0) {
                    throw new AuthException(sm.getString("simpleServerAuthConfig.noModules"));
                }
                this.serverAuthContext = createServerAuthContext(modules);
            }
            serverAuthContext = this.serverAuthContext;
        }
    }
    return serverAuthContext;
}
Also used : HashMap(java.util.HashMap) ServerAuthModule(jakarta.security.auth.message.module.ServerAuthModule) ArrayList(java.util.ArrayList) AuthException(jakarta.security.auth.message.AuthException) ServerAuthContext(jakarta.security.auth.message.config.ServerAuthContext)

Aggregations

ServerAuthModule (jakarta.security.auth.message.module.ServerAuthModule)2 AuthException (jakarta.security.auth.message.AuthException)1 AuthStatus (jakarta.security.auth.message.AuthStatus)1 ServerAuthContext (jakarta.security.auth.message.config.ServerAuthContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1