2016-07-14 55 views
0

我在我的應用程序中實現登錄功能,我想保護我的控制器,它負責系統中的用戶。在此期間,我不想在所有控制器上使用https。有沒有可能,或者我必須對所有控制器使用http或https?Http和Https控制器與Spring啓動

回答

0

我沒有在java中配置Spring,但幾乎100%確定你可以這樣做。

@Configuration 
@EnableWebMvcSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
      .antMatchers("/secure").hasRole("USER") 
      .antMatchers("/supersecure").hasRole("USER") 
      .anyRequest().permitAll(); 
      .and() 
      .requiresChannel() 
      .antMatchers("/supersecure").requiresSecure(); //at this part you set up https 
    } 
}