title: How to validate user using info in headers in spring security
body: <p>Currently I'm creating the web without login page.</p>
  
  <p>I have another website that will send a header with info:</p>
  
  <pre><code>user:John
  userCode:1234567
  </code></pre>
  
  <p>So my current website will check the content of the headers and validate the user in authentication manager like this:</p>
  
  <p>First I create the <code>AuthenticationEntryPoint</code> so the unauthentication user will go there.In the <code>AuthenticationEntryPoint</code> I create a token and redirect the user to main page,so before its goes to the main page,spring will authenticate the user and give a token for a valid user to use the page. The code is like this: </p>
  
  <pre><code>@Component
  public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
           if(authException.getClass().getSimpleName().equals("InsufficientAuthenticationException")) {
              if (request.getHeader("user") != null) {
                  UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(request.getHeader("user"), request.getHeader("userCode"));
                  SecurityContextHolder.getContext().setAuthentication(auth);
                  response.sendRedirect(request.getContextPath());
              }
          }
  }
  </code></pre>
  
  <p>In the <code>AuthenticationManager</code> the process will go as usual and give token if the user is valid. Is there anything I need to change or another approach that can be used in spring?</p>
  
  <p>Thanks!</p>