title: Spring Rest Set Custom Object in Context
body: <p>I am using Spring Rest for creating Rest APIs. For authentication, I have created a filter that extends from <code>OncePerRequestFilter</code>, this filter check if a valid token is present in the header. I have to set some custom object information in Spring context. So that I can retrieve it in my Controller classes. Something like: </p>
  
  <pre><code>AuthenticationFilter extends OncePerRequestFilter {
      // validation goes here
  
      requestContext.setSecurityContext(new SecurityContext() {
          public Principal getUserPrincipal() {
              return new UserInfo("", token, userID, userType);
          }
      }
  });
  </code></pre>