2016-09-29 137 views
0

我在春季啓動時很新穎。我試圖在後端使用mongodb製作REST服務。在mongodb中,我創建了Customers表和sekond用戶表。在用戶表中,我將用戶名,密碼和角色的列定義爲一系列。嘗試從桌面用戶身份驗證訪問REST服務的用戶。 在Internet上,我們在擴展WebSecurityConfigurerAdapter時發現了兩種情況,或者在擴展GlobalAuthenticationConfigurerAdapter時發現了兩種情況。在第一種情況下,我讓bean在web上創建了自定義AuthenticationProvider的示例,但第二種方式是處理UserDetailsS​​erivce。 我的問題是我如何能更深入地探究這個問題? 即使在源碼鱈魚巨大的接口端班,我不能做這些工作人員不同,如在教程中。 這兩種方式的主要區別是什麼? 誰處理或如何處理春季啓動的安全性(有沒有像一個調度的servlet誰處理MVC?)配置Spring Boot的安全性

回答

1

@vmaric我沒有用它啓動SpringSecurity一個例子,不過貌似邏輯是相同的:

@Configuration 
public class AuthenticationManagerConfiguration extends 
     GlobalAuthenticationConfigurerAdapter { 

    @Override 
    public void init(AuthenticationManagerBuilder auth) { 
     auth.inMemoryAuthentication() // ... etc. <------- 
    } 

}

0

根據春季安全,你必須提供的安全配置:

@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter 

與被覆蓋的方法提供的AuthenticationManager:

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {...} 

它可以在內存中執行:

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
auth.inMemoryAuthentication() .withUser("user").password("password").roles("USER").and() .withUser("admin").password("password").roles("USER", "ADMIN"); 
} 

或實現依賴於你的UserDetailsS​​ervice實現:

@Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
authenticationManagerBuilder 
       .userDetailsService(userDetailsService) 
       .passwordEncoder(passwordEncoder()); 
} 

Here是如何在春季啓動

+0

什麼GlobalAuthenticationConfigurerAdapter? – vmaric

+0

對不起,我沒有看到第一個迴應。 – vmaric