Search in sources :

Example 1 with CasEmbeddedApacheTomcatBasicAuthenticationProperties

use of org.apereo.cas.configuration.model.core.web.tomcat.CasEmbeddedApacheTomcatBasicAuthenticationProperties in project cas by apereo.

the class CasEmbeddedContainerTomcatConfiguration method configureBasicAuthn.

private void configureBasicAuthn(final TomcatEmbeddedServletContainerFactory tomcat) {
    final CasEmbeddedApacheTomcatBasicAuthenticationProperties basic = casProperties.getServer().getBasicAuthn();
    if (basic.isEnabled()) {
        tomcat.addContextCustomizers(ctx -> {
            final LoginConfig config = new LoginConfig();
            config.setAuthMethod("BASIC");
            ctx.setLoginConfig(config);
            basic.getSecurityRoles().forEach(ctx::addSecurityRole);
            basic.getAuthRoles().forEach(r -> {
                final SecurityConstraint constraint = new SecurityConstraint();
                constraint.addAuthRole(r);
                final SecurityCollection collection = new SecurityCollection();
                basic.getPatterns().forEach(collection::addPattern);
                constraint.addCollection(collection);
                ctx.addConstraint(constraint);
            });
        });
        tomcat.addContextValves(new BasicAuthenticator());
    }
}
Also used : BasicAuthenticator(org.apache.catalina.authenticator.BasicAuthenticator) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) CasEmbeddedApacheTomcatBasicAuthenticationProperties(org.apereo.cas.configuration.model.core.web.tomcat.CasEmbeddedApacheTomcatBasicAuthenticationProperties) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Aggregations

BasicAuthenticator (org.apache.catalina.authenticator.BasicAuthenticator)1 LoginConfig (org.apache.tomcat.util.descriptor.web.LoginConfig)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 CasEmbeddedApacheTomcatBasicAuthenticationProperties (org.apereo.cas.configuration.model.core.web.tomcat.CasEmbeddedApacheTomcatBasicAuthenticationProperties)1