001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.view;
017
018import org.kuali.rice.krad.datadictionary.DictionaryBeanBase;
019import org.kuali.rice.krad.datadictionary.parse.BeanTag;
020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
021import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
022
023import java.io.Serializable;
024
025/**
026 * Holds configuration related to session handling of a view (and its related form)
027 *
028 * <p>
029 * The framework will keep track of the session for which a view is rendered in. When a request such as a
030 * post is made, the session id for the view will be compared against the current session. If different, or no
031 * session exists, a timeout will be assumed and the framework will take the action configured on this
032 * policy
033 * </p>
034 *
035 * <p>
036 * If none of the options are set here, the framework will allow a request after a timeout to go uninterrupted
037 * </p>
038 *
039 * <p>
040 * Notes carrying out the configured view session policy requires the filter
041 * {@link org.kuali.rice.krad.web.filter.UifSessionTimeoutFilter} to be configured first in the list of filters
042 * for the servlet
043 * </p>
044 *
045 * @author Kuali Rice Team (rice.collab@kuali.org)
046 */
047@BeanTag(name = "sessionPolicy", parent = "Uif-ViewSessionPolicy")
048public class ViewSessionPolicy extends UifDictionaryBeanBase implements Serializable {
049    private static final long serialVersionUID = -5187545712142535662L;
050
051    private boolean redirectToHome;
052    private String redirectUrl;
053    private boolean renderTimeoutView;
054    private boolean enableTimeoutWarning;
055    private int timeoutWarningSeconds;
056
057    public ViewSessionPolicy() {
058        super();
059
060        timeoutWarningSeconds = 120;
061    }
062
063    /**
064     * Indicates when a session timeout occurs the user should be redirect to the application home url
065     * (determined by the configuration parameter 'application.url')
066     *
067     * @return true if the user should be redirected to the home URL
068     */
069    @BeanTagAttribute
070    public boolean isRedirectToHome() {
071        return redirectToHome;
072    }
073
074    /**
075     * Setter for indicating whether the user should be redirected to the home URL on session timeout
076     *
077     * @param redirectToHome
078     */
079    public void setRedirectToHome(boolean redirectToHome) {
080        this.redirectToHome = redirectToHome;
081    }
082
083    /**
084     * URL the user should be redirected to when a session timeout occurs
085     *
086     * @return url to redirect user to
087     */
088    @BeanTagAttribute
089    public String getRedirectUrl() {
090        return redirectUrl;
091    }
092
093    /**
094     * Setter for the URL to redirect the user to when a session timeout occurs
095     *
096     * @param redirectUrl
097     */
098    public void setRedirectUrl(String redirectUrl) {
099        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}