2016-07-11 121 views
1

我有3個行家模塊:春季安全:某些URL禁用HTTPS

  1. 「控制器A」 - 春天啓動的Web應用程序, 「/ A/*」 的網址
  2. 「控制器B」 - 又一個春天啓動Web應用程序, 「/ b/*」 的網址
  3. 「常用」 - 共享春季安全配置

我想爲 「/ A/」 使用https和X509和 「/ b/」使用沒有安全性的http(或其他類型的安全 - 例如jwt)。

我現在的版本是:

public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests() 
       .antMatchers("https://stackoverflow.com/a/**").authenticated() 
       .and() 
       .x509() 
       .and().csrf().disable(); 
    } 

    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web.ignoring().antMatchers("/b/**"); 
    } 
} 

它仍然運行在HTTPS B和需要身份驗證。是否有可能配置我想要的而不創建單獨的安全配置?

回答

0

使用HTTP和HTTPS時,必須配置兩個連接器。如文檔中所述(請參閱http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-ssl),僅使用配置文件是不可能的。

您必須配置連接器中的一個(例如HTTPS),並添加其他編程。這個例子說明了如何:https://github.com/spring-projects/spring-boot/tree/v1.3.6.RELEASE/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors

順便說一句,不建議再使用普通HTTP。

+1

如果我跑的多連接器例子,嘗試調用HTTP URL我的瀏覽器切換到HTTPS和我得到異常'拋出:IllegalArgumentException:在方法名中發現無效字符。 HTTP方法名稱必須是標記'。 – user1648825

+0

如果您可以重現此問題,請打開https://github.com/spring-projects/spring-boot/issues問題。在這之前,請檢查您的Spring Boot版本。 但是,除非您在爲您處理SSL連接的逆向代理(這是PaaS環境中的情況)下運行Spring Boot,否則不推薦使用純HTTP。 – cdelmas