blob: ed17765f19ee99d642957310e0e9fa2d64a49676 [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="de"><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>SessionValidator.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 Turbine</a> &gt; <a href="index.source.html" class="el_package">org.apache.turbine.modules.actions.sessionvalidator</a> &gt; <span class="el_source">SessionValidator.java</span></div><h1>SessionValidator.java</h1><pre class="source lang-java linenums">package org.apache.turbine.modules.actions.sessionvalidator;
import org.apache.turbine.TurbineConstants;
import org.apache.turbine.annotation.TurbineConfiguration;
import org.apache.turbine.annotation.TurbineService;
/*
* 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.
*/
import org.apache.turbine.modules.Action;
import org.apache.turbine.services.security.SecurityService;
import org.apache.turbine.util.RunData;
/**
* The SessionValidator attempts to retrieve the User object from the
* Servlet API session that is associated with the request. If the
* data cannot be retrieved, it is handled here. If the user has not
* been marked as being logged into the system, the user is rejected
* and the screen is set to the screen.homepage value in
* TurbineResources.properties.
*
* &lt;p&gt;
* Other systems generally have a database table which stores this
* information, but we take advantage of the Servlet API here to save
* a hit to the database for each and every connection that a user
* makes.
* &lt;/p&gt;
*
* &lt;p&gt;
* This action is special in that it should only be executed by the
* Turbine servlet.
* &lt;/p&gt;
*
* @author &lt;a href=&quot;mailto:mbryson@mont.mindspring.com&quot;&gt;Dave Bryson&lt;/a&gt;
* @version $Id$
*/
<span class="fc" id="L53">public abstract class SessionValidator implements Action</span>
{
@TurbineService
protected SecurityService security;
@TurbineConfiguration( TurbineConstants.TEMPLATE_HOMEPAGE )
protected String templateHomepage;
@TurbineConfiguration( TurbineConstants.SCREEN_HOMEPAGE )
protected String screenHomepage;
@TurbineConfiguration( TurbineConstants.TEMPLATE_INVALID_STATE )
protected String templateInvalidState;
@TurbineConfiguration( TurbineConstants.SCREEN_INVALID_STATE )
protected String screenInvalidState;
// the session_access_counter can be placed as a hidden field in
// forms. This can be used to prevent a user from using the
// browsers back button and submitting stale data.
/**
*
* @param data RunData object
* @param screenOnly {@link DefaultSessionValidator}
*/
protected void handleFormCounterToken( RunData data, boolean screenOnly )
{
<span class="nc bnc" id="L81" title="All 2 branches missed."> if (data.getParameters().containsKey(&quot;_session_access_counter&quot;))</span>
{
<span class="nc bnc" id="L83" title="All 2 branches missed."> if (screenOnly) {</span>
// See comments in screens.error.InvalidState.
<span class="nc" id="L85"> if (data.getParameters().getInt(&quot;_session_access_counter&quot;)</span>
<span class="nc" id="L86"> &lt; (((Integer) data.getUser().getTemp(</span>
<span class="nc bnc" id="L87" title="All 2 branches missed."> &quot;_session_access_counter&quot;)).intValue() - 1))</span>
{
<span class="nc" id="L89"> data.getUser().setTemp(&quot;prev_screen&quot;, data.getScreen());</span>
<span class="nc" id="L90"> data.getUser().setTemp(&quot;prev_parameters&quot;, data.getParameters());</span>
<span class="nc" id="L91"> data.setScreen(screenInvalidState);</span>
<span class="nc" id="L92"> data.setAction(&quot;&quot;);</span>
}
} else {
<span class="nc bnc" id="L95" title="All 2 branches missed."> if (!security.isAnonymousUser(data.getUser()))</span>
{
// See comments in screens.error.InvalidState.
<span class="nc" id="L98"> if (data.getParameters().getInt(&quot;_session_access_counter&quot;)</span>
<span class="nc" id="L99"> &lt; (((Integer) data.getUser().getTemp(</span>
<span class="nc bnc" id="L100" title="All 2 branches missed."> &quot;_session_access_counter&quot;)).intValue() - 1))</span>
{
<span class="nc bnc" id="L102" title="All 2 branches missed."> if (data.getTemplateInfo().getScreenTemplate() != null)</span>
{
<span class="nc" id="L104"> data.getUser().setTemp(&quot;prev_template&quot;,</span>
<span class="nc" id="L105"> data.getTemplateInfo().getScreenTemplate()</span>
<span class="nc" id="L106"> .replace('/', ','));</span>
<span class="nc" id="L107"> data.getTemplateInfo().setScreenTemplate(templateInvalidState);</span>
}
else
{
<span class="nc" id="L111"> data.getUser().setTemp(&quot;prev_screen&quot;,</span>
<span class="nc" id="L112"> data.getScreen().replace('/', ','));</span>
<span class="nc" id="L113"> data.setScreen(screenInvalidState);</span>
}
<span class="nc" id="L115"> data.getUser().setTemp(&quot;prev_parameters&quot;, data.getParameters());</span>
<span class="nc" id="L116"> data.setAction(&quot;&quot;);</span>
}
}
}
}
<span class="nc" id="L122"> }</span>
// empty
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html>