2017-07-26 50 views
0

我想要禁用http TRACE。我正在使用彈簧引導,默認情況下,它提供了它。我已經排除了tomcat並使用了下行。我在其他stackoverflow帖子(here)得到了tomcat的答案,但我無法找到相同的承運人。這是我迄今爲止所做的。使用彈簧啓動禁用http TRACK/TRACE

@Bean 
    public EmbeddedServletContainerCustomizer containerCustomizer() { 
     return new EmbeddedServletContainerCustomizer() { 
      @Override 
      public void customize(ConfigurableEmbeddedServletContainer container) { 
       if (container.getClass().isAssignableFrom(UndertowEmbeddedServletContainerFactory.class)) { 
        UndertowEmbeddedServletContainerFactory underTowContainer = (UndertowEmbeddedServletContainerFactory) container; 
        underTowContainer.addDeploymentInfoCustomizers(new ContextSecurityCustomizer()); 
       } 
      } 
     }; 
    } 

    private static class ContextSecurityCustomizer implements UndertowDeploymentInfoCustomizer { 
     @Override 
     public void customize(DeploymentInfo deploymentInfo) { 
      DeploymentInfo info = new DeploymentInfo(); 
      // What next after this 
     } 
    } 

請幫我完成這段代碼。我是否正朝着正確的方向前進?在此先感謝

回答

1

這應該暗流工作:

@Bean 
    public EmbeddedServletContainerCustomizer containerCustomizer() { 
     return new EmbeddedServletContainerCustomizer() { 
      @Override 
      public void customize(ConfigurableEmbeddedServletContainer container) { 
       if (container.getClass().isAssignableFrom(UndertowEmbeddedServletContainerFactory.class)) { 
        UndertowEmbeddedServletContainerFactory undertowContainer = (UndertowEmbeddedServletContainerFactory) container; 
        undertowContainer.addDeploymentInfoCustomizers(new ContextSecurityCustomizer()); 
       } 
      } 
     }; 
    } 

    private static class ContextSecurityCustomizer implements UndertowDeploymentInfoCustomizer { 

     @Override 
     public void customize(io.undertow.servlet.api.DeploymentInfo deploymentInfo) { 
      SecurityConstraint constraint = new SecurityConstraint(); 
      WebResourceCollection traceWebresource = new WebResourceCollection(); 
      traceWebresource.addUrlPattern("/*"); 
      traceWebresource.addHttpMethod(HttpMethod.TRACE.toString()); 
      constraint.addWebResourceCollection(traceWebresource); 
      deploymentInfo.addSecurityConstraint(constraint); 
     } 

    }