View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.view;
17  
18  import org.kuali.rice.krad.datadictionary.DictionaryBeanBase;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
22  
23  import java.io.Serializable;
24  
25  /**
26   * Holds configuration related to session handling of a view (and its related form)
27   *
28   * <p>
29   * The framework will keep track of the session for which a view is rendered in. When a request such as a
30   * post is made, the session id for the view will be compared against the current session. If different, or no
31   * session exists, a timeout will be assumed and the framework will take the action configured on this
32   * policy
33   * </p>
34   *
35   * <p>
36   * If none of the options are set here, the framework will allow a request after a timeout to go uninterrupted
37   * </p>
38   *
39   * <p>
40   * Notes carrying out the configured view session policy requires the filter
41   * {@link org.kuali.rice.krad.web.filter.UifSessionTimeoutFilter} to be configured first in the list of filters
42   * for the servlet
43   * </p>
44   *
45   * @author Kuali Rice Team (rice.collab@kuali.org)
46   */
47  @BeanTag(name = "sessionPolicy", parent = "Uif-ViewSessionPolicy")
48  public class ViewSessionPolicy extends UifDictionaryBeanBase implements Serializable {
49      private static final long serialVersionUID = -5187545712142535662L;
50  
51      private boolean redirectToHome;
52      private String redirectUrl;
53      private boolean renderTimeoutView;
54      private boolean enableTimeoutWarning;
55      private int timeoutWarningSeconds;
56  
57      public ViewSessionPolicy() {
58          super();
59  
60          timeoutWarningSeconds = 120;
61      }
62  
63      /**
64       * Indicates when a session timeout occurs the user should be redirect to the application home url
65       * (determined by the configuration parameter 'application.url')
66       *
67       * @return true if the user should be redirected to the home URL
68       */
69      @BeanTagAttribute
70      public boolean isRedirectToHome() {
71          return redirectToHome;
72      }
73  
74      /**
75       * Setter for indicating whether the user should be redirected to the home URL on session timeout
76       *
77       * @param redirectToHome
78       */
79      public void setRedirectToHome(boolean redirectToHome) {
80          this.redirectToHome = redirectToHome;
81      }
82  
83      /**
84       * URL the user should be redirected to when a session timeout occurs
85       *
86       * @return url to redirect user to
87       */
88      @BeanTagAttribute
89      public String getRedirectUrl() {
90          return redirectUrl;
91      }
92  
93      /**
94       * Setter for the URL to redirect the user to when a session timeout occurs
95       *
96       * @param redirectUrl
97       */
98      public void setRedirectUrl(String redirectUrl) {
99          this.redirectUrl = redirectUrl;
100     }
101 
102     /**
103      * Indicates the user should be shown the timeout message view when a session timeout occurs
104      *
105      * @return true if the timeout view should be shown on session timeout
106      */
107     @BeanTagAttribute
108     public boolean isRenderTimeoutView() {
109         return renderTimeoutView;
110     }
111 
112     /**
113      * Setter to indicate the timeout view should be shown on session timeout
114      *
115      * @param renderTimeoutView
116      */
117     public void setRenderTimeoutView(boolean renderTimeoutView) {
118         this.renderTimeoutView = renderTimeoutView;
119     }
120 
121     /**
122      * Enables the session timeout warning dialog and timeout dialog for the view
123      *
124      * <p>
125      * When enabled, a timer will be kept on the client to warning the user when their session is about
126      * to timeout, and if the timeout actually occurs. The amount of time before a timeout to warn is specified
127      * by {@link #getTimeoutWarningSeconds()}
128      * </p>
129      *
130      * <p>
131      * The dialogs shown for the warning and timeout are configured by the dialog groups with ids
132      * {@link org.kuali.rice.krad.uif.util.ComponentFactory#SESSION_TIMEOUT_WARNING_DIALOG} and
133      * {@link org.kuali.rice.krad.uif.util.ComponentFactory#SESSION_TIMEOUT_DIALOG}
134      * </p>
135      *
136      * @return true if the timeout warning dialog should be enabled
137      */
138     @BeanTagAttribute
139     public boolean isEnableTimeoutWarning() {
140         return enableTimeoutWarning;
141     }
142 
143     /**
144      * Setter for enabling the session timeout warning dialog
145      *
146      * @param enableTimeoutWarning
147      */
148     public void setEnableTimeoutWarning(boolean enableTimeoutWarning) {
149         this.enableTimeoutWarning = enableTimeoutWarning;
150     }
151 
152     /**
153      * When {@link #isEnableTimeoutWarning()} is true, the number of seconds before a timeout occurs to give a
154      * warning (default is 120 (2 minutes))
155      *
156      * @return number of seconds before timeout to give warning dialog
157      */
158     @BeanTagAttribute
159     public int getTimeoutWarningSeconds() {
160         return timeoutWarningSeconds;
161     }
162 
163     /**
164      * Setter for the number of seconds before timeout to give a warning dialog
165      *
166      * @param timeoutWarningSeconds
167      */
168     public void setTimeoutWarningSeconds(int timeoutWarningSeconds) {
169         this.timeoutWarningSeconds = timeoutWarningSeconds;
170     }
171 }