org.eurekaclinical.common.config.AbstractServletModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eurekaclinical-common Show documentation
Show all versions of eurekaclinical-common Show documentation
A library of classes shared across the Eureka! Clinical platform.
package org.eurekaclinical.common.config;
/*-
* #%L
* Eureka! Clinical Common
* %%
* Copyright (C) 2016 Emory University
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.Map;
import org.jasig.cas.client.authentication.AuthenticationFilter;
import org.jasig.cas.client.util.AssertionThreadLocalFilter;
import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Singleton;
import com.google.inject.servlet.ServletModule;
import org.eurekaclinical.standardapis.props.CasEurekaClinicalProperties;
import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter;
/**
* Extend to setup Eureka web applications. This abstract class sets up Guice
* and binds the authentication and authorization filters that every Eureka web
* application should have.
*
* @author hrathod
*/
public abstract class AbstractServletModule extends ServletModule {
private static final Logger LOGGER = LoggerFactory
.getLogger(AbstractServletModule.class);
private final String protectedPath;
private final ServletModuleSupport servletModuleSupport;
protected AbstractServletModule(CasEurekaClinicalProperties inProperties,
String inContainerPath, String inProtectedPath) {
if (inProtectedPath == null) {
throw new IllegalArgumentException("inProtectedPath cannot be null");
}
this.servletModuleSupport = new ServletModuleSupport(
this.getServletContext().getContextPath(), inProperties);
this.protectedPath = inProtectedPath;
}
protected void printParams(Map inParams) {
for (Map.Entry entry : inParams.entrySet()) {
LOGGER.debug(entry.getKey() + " -> " + entry.getValue());
}
}
private void setupCasSingleSignOutFilter() {
bind(SingleSignOutFilter.class).in(Singleton.class);
filter("/*").through(SingleSignOutFilter.class);
}
private void setupCasValidationFilter() {
bind(Cas20ProxyReceivingTicketValidationFilter.class).in(
Singleton.class);
Map params = getCasValidationFilterInitParams();
filter(this.servletModuleSupport.getCasProxyCallbackPath(), this.protectedPath).through(
Cas20ProxyReceivingTicketValidationFilter.class, params);
}
private void setupCasAuthenticationFilter() {
bind(AuthenticationFilter.class).in(Singleton.class);
Map params
= this.servletModuleSupport.getCasAuthenticationFilterInitParams();
filter(this.protectedPath).through(AuthenticationFilter.class, params);
}
private void setupCasServletRequestWrapperFilter() {
bind(HttpServletRequestWrapperFilter.class).in(Singleton.class);
Map params
= this.servletModuleSupport.getServletRequestWrapperFilterInitParams();
filter("/*").through(HttpServletRequestWrapperFilter.class, params);
}
private void setupCasThreadLocalAssertionFilter() {
bind(AssertionThreadLocalFilter.class).in(Singleton.class);
filter("/*").through(AssertionThreadLocalFilter.class);
}
protected String getCasProxyCallbackPath() {
return this.servletModuleSupport.getCasProxyCallbackPath();
}
protected String getCasProxyCallbackUrl() {
return this.servletModuleSupport.getCasProxyCallbackUrl();
}
protected abstract Map getCasValidationFilterInitParams();
protected abstract void setupServlets();
/**
* Override to setup additional filters. The default implementation does
* nothing.
*/
protected void setupFilters() {
}
@Override
protected final void configureServlets() {
super.configureServlets();
/*
* CAS filters must go before other filters.
*/
this.setupCasFilters();
this.setupFilters();
this.setupServlets();
}
/*
* Sets up CAS filters. The filter order is specified in
* https://wiki.jasig.org/display/CASC/Configuring+Single+Sign+Out
* and
* https://wiki.jasig.org/display/CASC/CAS+Client+for+Java+3.1
*/
private void setupCasFilters() {
this.setupCasSingleSignOutFilter();
this.setupCasAuthenticationFilter();
this.setupCasValidationFilter();
this.setupCasServletRequestWrapperFilter();
this.setupCasThreadLocalAssertionFilter();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy