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