| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AutoLoginFilter |
|
| 1.5;1.5 | ||||
| AutoLoginFilter$1 |
|
| 1.5;1.5 |
| 1 | /** | |
| 2 | * Copyright 2005-2011 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.web.filter; | |
| 17 | ||
| 18 | import java.io.IOException; | |
| 19 | ||
| 20 | import javax.servlet.Filter; | |
| 21 | import javax.servlet.FilterChain; | |
| 22 | import javax.servlet.FilterConfig; | |
| 23 | import javax.servlet.ServletException; | |
| 24 | import javax.servlet.ServletRequest; | |
| 25 | import javax.servlet.ServletResponse; | |
| 26 | import javax.servlet.http.HttpServletRequest; | |
| 27 | import javax.servlet.http.HttpServletRequestWrapper; | |
| 28 | ||
| 29 | /** | |
| 30 | * Automatically logs in with the user specified via filter init parameter {@link AutoLoginFilter#USER_PARAM_NAME}. | |
| 31 | * <p> | |
| 32 | * There are no guarantees made that the user specified is a valid user in the system. | |
| 33 | * </p> | |
| 34 | * <p> | |
| 35 | * In rice this Filter can be used via config like that following assuming the bootstrap filter is used: <br /> | |
| 36 | * {@code <param name="filter.login.class">org.kuali.kra.test.infrastructure.AutoLoginFilter</param>} <br /> | |
| 37 | * {@code <param name="filtermapping.login.1">/*</param>} <br /> | |
| 38 | * {@code <param name="filter.login.autouser">admin</param>} <br /> | |
| 39 | * </p> | |
| 40 | */ | |
| 41 | 0 | public class AutoLoginFilter implements Filter { |
| 42 | public static final String USER_PARAM_NAME = "autouser"; | |
| 43 | ||
| 44 | private FilterConfig filterConfig; | |
| 45 | ||
| 46 | /** {@inheritDoc} */ | |
| 47 | public void init(FilterConfig config) throws ServletException { | |
| 48 | 0 | this.filterConfig = config; |
| 49 | 0 | } |
| 50 | ||
| 51 | /** {@inheritDoc} */ | |
| 52 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
| 53 | 0 | if (filterConfig.getInitParameter(USER_PARAM_NAME) == null) { |
| 54 | 0 | throw new IllegalStateException("the " + USER_PARAM_NAME + " param is not set"); |
| 55 | } | |
| 56 | ||
| 57 | 0 | chain.doFilter(new HttpServletRequestWrapper((HttpServletRequest) request) { |
| 58 | @Override | |
| 59 | public String getRemoteUser() { | |
| 60 | 0 | return AutoLoginFilter.this.filterConfig.getInitParameter(USER_PARAM_NAME); |
| 61 | } | |
| 62 | }, response); | |
| 63 | 0 | } |
| 64 | ||
| 65 | /** {@inheritDoc} */ | |
| 66 | public void destroy() { | |
| 67 | 0 | this.filterConfig = null; |
| 68 | 0 | } |
| 69 | } |