title: How to create my own filter with Spring MVC?
body: <p>I use Spring MVC (4.0.1) as a backend for rest services and angularjs as frontend.</p>
  
  <p>every request to my server backend has a http-header with a session id</p>
  
  <p>I can read this header in my server backend with the following code:</p>
  
  <pre><code>@Autowired
  protected HttpServletRequest request;
  String xHeader=request.getHeader("X-Auth-Token"); //returns the sessionID from the header
  </code></pre>
  
  <p>Now I call this method <code>getPermission(xHeader)</code> it return only true or false. If the user exists in my DB it return true else false!</p>
  
  <p>I want now create a filter with this behavior, that checks every request if the user have the permission to access my controllers! But if the method returns false it should send back a 401 error and not reach my controller!</p>
  
  <p>How can I do this and create my own filter? I use only Java Config and no XML.</p>
  
  <p>I think I must add the filter here:</p>
  
  <pre><code>public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
      @Override
      protected Filter[] getServletFilters() {
          MyOwnFilter=new MyOwnFilter();
          return new Filter[] {MyOwnFilter};
      }
  }
  </code></pre>