| <?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> > <a href="index.source.html" class="el_package">org.apache.turbine.modules.actions.sessionvalidator</a> > <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 |
| * "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. |
| */ |
| |
| 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. |
| * |
| * <p> |
| * 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. |
| * </p> |
| * |
| * <p> |
| * This action is special in that it should only be executed by the |
| * Turbine servlet. |
| * </p> |
| * |
| * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> |
| * @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("_session_access_counter"))</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("_session_access_counter")</span> |
| <span class="nc" id="L86"> < (((Integer) data.getUser().getTemp(</span> |
| <span class="nc bnc" id="L87" title="All 2 branches missed."> "_session_access_counter")).intValue() - 1))</span> |
| { |
| <span class="nc" id="L89"> data.getUser().setTemp("prev_screen", data.getScreen());</span> |
| <span class="nc" id="L90"> data.getUser().setTemp("prev_parameters", data.getParameters());</span> |
| <span class="nc" id="L91"> data.setScreen(screenInvalidState);</span> |
| <span class="nc" id="L92"> data.setAction("");</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("_session_access_counter")</span> |
| <span class="nc" id="L99"> < (((Integer) data.getUser().getTemp(</span> |
| <span class="nc bnc" id="L100" title="All 2 branches missed."> "_session_access_counter")).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("prev_template",</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("prev_screen",</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("prev_parameters", data.getParameters());</span> |
| <span class="nc" id="L116"> data.setAction("");</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> |