Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community 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 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.
 package org.kuali.rice.kew.web;
This class establishes and initializes the KEW Preferences after a user logs in.

This filter assumes that a UserSession is already established.

Kuali Rice Team (
 public class UserPreferencesFilter implements Filter {
 	private static final Log LOG = LogFactory.getLog(UserPreferencesFilter.class);
 	public void init(FilterConfig configthrows ServletException {
 		this. = config;
 	public void doFilter(ServletRequest requestServletResponse responseFilterChain chainthrows IOExceptionServletException {
 		this.doFilter((HttpServletRequestrequest, (HttpServletResponseresponsechain);
 	private void doFilter(HttpServletRequest requestHttpServletResponse responseFilterChain chainthrows IOExceptionServletException {
 		final UserSession session = KRADUtils.getUserSessionFromRequest(request);
 		if (session == null) {
 			throw new IllegalStateException("A user session has not been established");
 		final String principalId = session.getPrincipalId();
 		if (session.retrieveObject(.) == null) {
 			final Preferences preferences = retrievePreferences(principalId);
 	public void destroy() {
 		 = null;
     private Preferences retrievePreferences(String principalId) {
     	Preferences preferences = this.getPreferenceService().getPreferences(principalId);
         if (preferences.isRequiresSave()) {
             .info("Detected that user preferences require saving.");
             preferences = this.getPreferenceService().getPreferences(principalId);
         return preferences;
     	if (this. == null) {
    		this. = KewApiServiceLocator.getPreferencesService();
    	return this.;
New to GrepCode? Check out our FAQ X