Search in sources :

Example 1 with NegotiationMechanismFactory

use of org.jboss.security.negotiation.NegotiationMechanismFactory in project wildfly by wildfly.

the class ServletContainerAdd method installRuntimeServices.

public void installRuntimeServices(OperationContext context, ModelNode model, String name) throws OperationFailedException {
    final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS), 2);
    final SessionCookieConfig config = SessionCookieDefinition.INSTANCE.getConfig(context, fullModel.get(SessionCookieDefinition.INSTANCE.getPathElement().getKeyValuePair()));
    final CrawlerSessionManagerConfig crawlerSessionManagerConfig = CrawlerSessionManagementDefinition.INSTANCE.getConfig(context, fullModel.get(CrawlerSessionManagementDefinition.INSTANCE.getPathElement().getKeyValuePair()));
    final boolean persistentSessions = PersistentSessionsDefinition.isEnabled(context, fullModel.get(PersistentSessionsDefinition.INSTANCE.getPathElement().getKeyValuePair()));
    final boolean allowNonStandardWrappers = ServletContainerDefinition.ALLOW_NON_STANDARD_WRAPPERS.resolveModelAttribute(context, model).asBoolean();
    final boolean proactiveAuth = ServletContainerDefinition.PROACTIVE_AUTHENTICATION.resolveModelAttribute(context, model).asBoolean();
    final String bufferCache = ServletContainerDefinition.DEFAULT_BUFFER_CACHE.resolveModelAttribute(context, model).asString();
    final boolean disableFileWatchService = ServletContainerDefinition.DISABLE_FILE_WATCH_SERVICE.resolveModelAttribute(context, model).asBoolean();
    JSPConfig jspConfig = JspDefinition.INSTANCE.getConfig(context, fullModel.get(JspDefinition.INSTANCE.getPathElement().getKeyValuePair()));
    final String stackTracesString = ServletContainerDefinition.STACK_TRACE_ON_ERROR.resolveModelAttribute(context, model).asString();
    final ModelNode defaultEncodingValue = ServletContainerDefinition.DEFAULT_ENCODING.resolveModelAttribute(context, model);
    final String defaultEncoding = defaultEncodingValue.isDefined() ? defaultEncodingValue.asString() : null;
    final boolean useListenerEncoding = ServletContainerDefinition.USE_LISTENER_ENCODING.resolveModelAttribute(context, model).asBoolean();
    final boolean ignoreFlush = ServletContainerDefinition.IGNORE_FLUSH.resolveModelAttribute(context, model).asBoolean();
    final boolean eagerFilterInit = ServletContainerDefinition.EAGER_FILTER_INIT.resolveModelAttribute(context, model).asBoolean();
    final boolean disableCachingForSecuredPages = ServletContainerDefinition.DISABLE_CACHING_FOR_SECURED_PAGES.resolveModelAttribute(context, model).asBoolean();
    final int sessionIdLength = ServletContainerDefinition.SESSION_ID_LENGTH.resolveModelAttribute(context, model).asInt();
    Boolean directoryListingEnabled = null;
    if (model.hasDefined(Constants.DIRECTORY_LISTING)) {
        directoryListingEnabled = ServletContainerDefinition.DIRECTORY_LISTING.resolveModelAttribute(context, model).asBoolean();
    }
    Integer maxSessions = null;
    if (model.hasDefined(Constants.MAX_SESSIONS)) {
        maxSessions = ServletContainerDefinition.MAX_SESSIONS.resolveModelAttribute(context, model).asInt();
    }
    final int sessionTimeout = ServletContainerDefinition.DEFAULT_SESSION_TIMEOUT.resolveModelAttribute(context, model).asInt();
    WebsocketsDefinition.WebSocketInfo webSocketInfo = WebsocketsDefinition.INSTANCE.getConfig(context, fullModel.get(WebsocketsDefinition.INSTANCE.getPathElement().getKeyValuePair()));
    final Map<String, String> mimeMappings = new HashMap<>();
    if (fullModel.hasDefined(Constants.MIME_MAPPING)) {
        for (final Property mapping : fullModel.get(Constants.MIME_MAPPING).asPropertyList()) {
            mimeMappings.put(mapping.getName(), MimeMappingDefinition.VALUE.resolveModelAttribute(context, mapping.getValue()).asString());
        }
    }
    List<String> welcomeFiles = new ArrayList<>();
    if (fullModel.hasDefined(Constants.WELCOME_FILE)) {
        for (final Property welcome : fullModel.get(Constants.WELCOME_FILE).asPropertyList()) {
            welcomeFiles.add(welcome.getName());
        }
    }
    // WFLY-2553 Adding default WildFly specific mechanisms here - subsequently we could enhance the servlet-container
    // config to override / add mechanisms.
    Map<String, AuthenticationMechanismFactory> authenticationMechanisms = new HashMap<>();
    authenticationMechanisms.put("SPNEGO", new NegotiationMechanismFactory());
    authenticationMechanisms.put(HttpServletRequest.DIGEST_AUTH, DigestAuthenticationMechanismFactory.FACTORY);
    final ServletContainerService container = new ServletContainerService(allowNonStandardWrappers, ServletStackTraces.valueOf(stackTracesString.toUpperCase().replace('-', '_')), config, jspConfig, defaultEncoding, useListenerEncoding, ignoreFlush, eagerFilterInit, sessionTimeout, disableCachingForSecuredPages, webSocketInfo != null, webSocketInfo != null && webSocketInfo.isDispatchToWorker(), webSocketInfo != null && webSocketInfo.isPerMessageDeflate(), webSocketInfo == null ? -1 : webSocketInfo.getDeflaterLevel(), mimeMappings, welcomeFiles, directoryListingEnabled, proactiveAuth, sessionIdLength, authenticationMechanisms, maxSessions, crawlerSessionManagerConfig, disableFileWatchService);
    final ServiceTarget target = context.getServiceTarget();
    final ServiceBuilder<ServletContainerService> builder = target.addService(UndertowService.SERVLET_CONTAINER.append(name), container);
    if (bufferCache != null) {
        builder.addDependency(BufferCacheService.SERVICE_NAME.append(bufferCache), DirectBufferCache.class, container.getBufferCacheInjectedValue());
    }
    if (persistentSessions) {
        builder.addDependency(AbstractPersistentSessionManager.SERVICE_NAME, SessionPersistenceManager.class, container.getSessionPersistenceManagerInjectedValue());
    }
    if (webSocketInfo != null) {
        builder.addDependency(IOServices.WORKER.append(webSocketInfo.getWorker()), XnioWorker.class, container.getWebsocketsWorker());
        builder.addDependency(IOServices.BUFFER_POOL.append(webSocketInfo.getBufferPool()), Pool.class, (InjectedValue) container.getWebsocketsBufferPool());
    }
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
Also used : NegotiationMechanismFactory(org.jboss.security.negotiation.NegotiationMechanismFactory) HashMap(java.util.HashMap) ServiceTarget(org.jboss.msc.service.ServiceTarget) ArrayList(java.util.ArrayList) CrawlerSessionManagerConfig(io.undertow.servlet.api.CrawlerSessionManagerConfig) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) AuthenticationMechanismFactory(io.undertow.security.api.AuthenticationMechanismFactory) DigestAuthenticationMechanismFactory(org.wildfly.extension.undertow.security.digest.DigestAuthenticationMechanismFactory)

Aggregations

AuthenticationMechanismFactory (io.undertow.security.api.AuthenticationMechanismFactory)1 CrawlerSessionManagerConfig (io.undertow.servlet.api.CrawlerSessionManagerConfig)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ModelNode (org.jboss.dmr.ModelNode)1 Property (org.jboss.dmr.Property)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 NegotiationMechanismFactory (org.jboss.security.negotiation.NegotiationMechanismFactory)1 DigestAuthenticationMechanismFactory (org.wildfly.extension.undertow.security.digest.DigestAuthenticationMechanismFactory)1