001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *      http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.apache.shiro.ee.filters;
015
016import org.apache.shiro.ee.filters.AuthenticationFilterDelegate.MethodsFromFilter;
017import javax.servlet.ServletRequest;
018import javax.servlet.ServletResponse;
019import lombok.experimental.Delegate;
020import lombok.extern.slf4j.Slf4j;
021import org.apache.shiro.authc.AuthenticationException;
022import org.apache.shiro.authc.AuthenticationToken;
023import org.apache.shiro.subject.Subject;
024
025/**
026 * Implements JSF Ajax redirection via OmniFaces
027 * Implements form resubmit and auto remember-me functionality
028 */
029@Slf4j
030public class PassThruAuthenticationFilter extends org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter {
031    private final @Delegate AuthenticationFilterDelegate delegate;
032
033    private final class Methods implements MethodsFromFilter {
034        @Override
035        public Subject getSubject(ServletRequest request, ServletResponse response) {
036            return PassThruAuthenticationFilter.super.getSubject(request, response);
037        }
038
039        @Override
040        public boolean isLoginRequest(ServletRequest request, ServletResponse response) {
041            return PassThruAuthenticationFilter.super.isLoginRequest(request, response);
042        }
043
044        @Override
045        public boolean onLoginFailure(AuthenticationToken token, AuthenticationException e,
046                ServletRequest request, ServletResponse response) {
047            throw new UnsupportedOperationException();
048        }
049
050        @Override
051        public String getLoginUrl() {
052            return PassThruAuthenticationFilter.super.getLoginUrl();
053        }
054
055        @Override
056        public boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
057            return PassThruAuthenticationFilter.super.preHandle(request, response);
058        }
059    };
060
061    public PassThruAuthenticationFilter() {
062        delegate = new AuthenticationFilterDelegate(new Methods());
063    }
064
065    @Override
066    protected String getPathWithinApplication(ServletRequest request) {
067        return org.apache.shiro.ee.filters.FormAuthenticationFilter
068                .getPathWithinApplication(request, () -> super.getPathWithinApplication(request));
069    }
070}