blob: 03d21d609b029ed345536bb78ee464b49b89013e [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>AbstractFilter.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Web</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.web.servlet</a> &gt; <span class="el_source">AbstractFilter.java</span></div><h1>AbstractFilter.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); 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
* &quot;AS IS&quot; 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.
*/
package org.apache.shiro.web.servlet;
import org.apache.shiro.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
/**
* Base abstract Filter simplifying Filter initialization and {@link #getInitParam(String) access} to init parameters.
* Subclass initialization logic should be performed by overriding the {@link #onFilterConfigSet()} template method.
* FilterChain execution logic (the
* {@link #doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)} method
* is left to subclasses.
*
* @since 1.0
*/
<span class="fc" id="L38">public abstract class AbstractFilter extends ServletContextSupport implements Filter {</span>
<span class="fc" id="L40"> private static transient final Logger log = LoggerFactory.getLogger(AbstractFilter.class);</span>
/**
* FilterConfig provided by the Servlet container at start-up.
*/
protected FilterConfig filterConfig;
/**
* Returns the servlet container specified {@code FilterConfig} instance provided at
* {@link #init(javax.servlet.FilterConfig) startup}.
*
* @return the servlet container specified {@code FilterConfig} instance provided at start-up.
*/
public FilterConfig getFilterConfig() {
<span class="fc" id="L54"> return filterConfig;</span>
}
/**
* Sets the FilterConfig &lt;em&gt;and&lt;/em&gt; the {@code ServletContext} as attributes of this class for use by
* subclasses. That is:
* &lt;pre&gt;
* this.filterConfig = filterConfig;
* setServletContext(filterConfig.getServletContext());&lt;/pre&gt;
*
* @param filterConfig the FilterConfig instance provided by the Servlet container at start-up.
*/
public void setFilterConfig(FilterConfig filterConfig) {
<span class="fc" id="L67"> this.filterConfig = filterConfig;</span>
<span class="fc" id="L68"> setServletContext(filterConfig.getServletContext());</span>
<span class="fc" id="L69"> }</span>
/**
* Returns the value for the named {@code init-param}, or {@code null} if there was no {@code init-param}
* specified by that name.
*
* @param paramName the name of the {@code init-param}
* @return the value for the named {@code init-param}, or {@code null} if there was no {@code init-param}
* specified by that name.
*/
protected String getInitParam(String paramName) {
<span class="fc" id="L80"> FilterConfig config = getFilterConfig();</span>
<span class="pc bpc" id="L81" title="1 of 2 branches missed."> if (config != null) {</span>
<span class="fc" id="L82"> return StringUtils.clean(config.getInitParameter(paramName));</span>
}
<span class="nc" id="L84"> return null;</span>
}
/**
* Sets the filter's {@link #setFilterConfig filterConfig} and then immediately calls
* {@link #onFilterConfigSet() onFilterConfigSet()} to trigger any processing a subclass might wish to perform.
*
* @param filterConfig the servlet container supplied FilterConfig instance.
* @throws javax.servlet.ServletException if {@link #onFilterConfigSet() onFilterConfigSet()} throws an Exception.
*/
public final void init(FilterConfig filterConfig) throws ServletException {
<span class="fc" id="L95"> setFilterConfig(filterConfig);</span>
try {
<span class="fc" id="L97"> onFilterConfigSet();</span>
<span class="fc" id="L98"> } catch (Exception e) {</span>
<span class="pc bpc" id="L99" title="1 of 2 branches missed."> if (e instanceof ServletException) {</span>
<span class="nc" id="L100"> throw (ServletException) e;</span>
} else {
<span class="pc bpc" id="L102" title="1 of 2 branches missed."> if (log.isErrorEnabled()) {</span>
<span class="fc" id="L103"> log.error(&quot;Unable to start Filter: [&quot; + e.getMessage() + &quot;].&quot;, e);</span>
}
<span class="fc" id="L105"> throw new ServletException(e);</span>
}
<span class="fc" id="L107"> }</span>
<span class="fc" id="L108"> }</span>
/**
* Template method to be overridden by subclasses to perform initialization logic at start-up. The
* {@code ServletContext} and {@code FilterConfig} will be accessible
* (and non-{@code null}) at the time this method is invoked via the
* {@link #getServletContext() getServletContext()} and {@link #getFilterConfig() getFilterConfig()}
* methods respectively.
* &lt;p/&gt;
* {@code init-param} values may be conveniently obtained via the {@link #getInitParam(String)} method.
*
* @throws Exception if the subclass has an error upon initialization.
*/
protected void onFilterConfigSet() throws Exception {
<span class="fc" id="L122"> }</span>
/**
* Default no-op implementation that can be overridden by subclasses for custom cleanup behavior.
*/
public void destroy() {
<span class="nc" id="L128"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>