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());
}
}
Aggregations