title: Spring boot rest external tomcat 401 error
body: <p>I have spring boot REST application that works perfectly fine when running on embedded tomcat. But as soon as I deploy it on external tomcat it gives 401 even for login requests</p>
  
  <p>I followed <a href="https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/" rel="nofollow noreferrer">https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/</a> and was able to deploy on tomcat.</p>
  
  <pre><code>@SpringBootApplication
  @EnableJpaAuditing
  public class Application  extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder         application) {
          return application.sources(Application.class);
      }
  
  }
  
  @Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
  
    @Autowired
    private EntryPointUnauthorizedHandler unauthorizedHandler;
  
    @Autowired
    private UserDetailsService userDetailsService;
  
    @Autowired
    private SecurityService securityService;
  
    @Autowired
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
      authenticationManagerBuilder
        .userDetailsService(this.userDetailsService)
          .passwordEncoder(passwordEncoder());
    }
  
    @Bean
    public PasswordEncoder passwordEncoder() {
      return new BCryptPasswordEncoder();
    }
  
    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
      return super.authenticationManagerBean();
    }
  
    @Bean
    public AuthenticationTokenFilter authenticationTokenFilterBean() throws     Exception {
      AuthenticationTokenFilter authenticationTokenFilter = new     AuthenticationTokenFilter();
          authenticationTokenFilter.setAuthenticationManager(authenticationManagerBean());
  return authenticationTokenFilter;
    }
  
    @Bean
    public SecurityService securityService() {
      return this.securityService;
    }
  
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
      httpSecurity
        .csrf()
          .disable()
        .exceptionHandling()
          .authenticationEntryPoint(this.unauthorizedHandler)
          .and()
        .sessionManagement()
          .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
          .and()
        .authorizeRequests()
          .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
          .antMatchers("/auth/**").permitAll()
          .anyRequest().authenticated()
           .and()
        .cors();
  
      // Custom JWT based authentication
      httpSecurity
        .addFilterBefore(authenticationTokenFilterBean(),     UsernamePasswordAuthenticationFilter.class);
    }
  </code></pre>
  
  <p>}</p>
  
  <p>Response on login</p>
  
  <pre><code>{
  "timestamp": 1522175007525,
  "status": 401,
  "error": "Unauthorized",
  "message": "Access Denied",
  "path": "/test-app/api/auth"
  </code></pre>
  
  <p>}</p>