MSAL4JSample startup exception in authFilter

Gregory Knott 96 Reputation points
2021-08-27T12:50:26.043+00:00

From tomcat deployment:

27-Aug-2021 14:22:01.726 SEVERE [localhost-startStop-2] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [authFilter]
java.lang.AbstractMethodError
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:110)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4538)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:970)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1840)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

  • OR - from IDE:

2021-08-27 14:17:23.079 ERROR 19656 --- [ost-startStop-1] o.a.c.c.C.[.[.[/msal-web-sample] : Exception starting filter [authFilter]

java.lang.AbstractMethodError: null
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:283) ~[catalina.jar:8.5.46]
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:112) ~[catalina.jar:8.5.46]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4546) [catalina.jar:8.5.46]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5191) [catalina.jar:8.5.46]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.46]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412) [catalina.jar:8.5.46]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402) [catalina.jar:8.5.46]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_212]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]

Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
12,705 questions
{count} votes

Accepted answer
  1. Gregory Knott 96 Reputation points
    2021-09-15T11:20:43.397+00:00

    I have fixed several issues with the sample code and it is now working for me. I ended up creating a fresh spring boot application from https://start.spring.io/

    Issue 1:

    The @SprintBootApplication annotation in the main application file did not seem to be scanning the java package for other classes marked with @Component and @Xbox One X etc. To fix I had to also add e.g. @ComponentScan("org.example.msal4jsample")

    Use the package name for your project.

    Issue 2:

    The @RequestMapping annotations on the routes in the PageController file are incorrect and I had to shorten them to just "/", "/secure/aad", "/sign_out", "/graph/me"

    Issue 3:

    An exception occurs as posted above from the AuthFilter class since it implements javax.servlet.FIlter. I had to add the following lines to correct:

    	@Override  
    	public void init(FilterConfig config) {}  
    	  
    	@Override  
    	public void destroy() {}  
    

    Issue 4:

    In the getAuthResulteByAuthCode function in the AuthHelper class -> the URI passed in parameters to acquireToken must have the full redirectUriSignin from config rather that the currentUri passed from the AuthFilter class.

    No comments

1 additional answer

Sort by: Most helpful
  1. LiquidMusic1 1 Reputation point
    2022-05-06T17:57:24.777+00:00

    Tacking on to GregoryKnott-6972 answer:

    Another issue that could be going on is with Spring Filter registration. Instead of simply dropping a filter into your app, you might need to register it in Spring. This requires that it extend one of Spring's FilterBeans. In my case (i had this same issue), i extended GenericFilterBean in a separate class and then registered the bean in a different class. See below:

    FILTER

    public class VaryHeaderFilter extends GenericFilterBean {
    
        @Override
        public void destroy(){}
    
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{
            chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response){
    
                @Override
                public void addHeader(String name, String value){
                    ...do some stuff
                }
    
                @Override
                public void setHeader(String name, String value){
                     .. do some stuff
                }
            });
        }
    

    FILTER REGISTRATION

    @Configuration
    public class FilterConfig {
    
        @Bean
        public FilterRegistrationBean<VaryHeaderFilter> filterFilterRegistrationBean(){
            FilterRegistrationBean<VaryHeaderFilter> filterBean = new FilterRegistrationBean<>();
            VaryHeaderFilter filter = new VaryHeaderFilter();
            filterBean.setFilter(filter);
            return filterBean;
        }
    
    }
    
    No comments