2016-07-01 20 views
2

我已經使用Spring Security的WebSecurityConfig來管理權限。 和剛剛加載一次Spring應用程序啓動時的權限。我該如何重新加載websecurityconfig運行時

如何在運行時手動重新加載WebSecurityConfig權限被更改?

這是我WebSecurityConfig代碼:

@Configuration 
@EnableWebSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter 
    { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
       .authorizeRequests() 
       .antMatchers("/css/**").permitAll() 
       .antMatchers("/js/**").permitAll() 
       .antMatchers("/rest/login").permitAll() 
       .anyRequest().authenticated() 
       .and() 

       .formLogin() 
       .loginPage("/boss/login") 
       .permitAll() 
       .and() 

       .logout() 
       .permitAll(); 
     http.csrf().disable(); 
    } 

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

} 

回答

0

剛剛獲得注入WebSecurityConfig任何你所需要的。您可以在WebSecurityConfig內使用@Autowire和@Value。

+0

我有同樣的問題(我需要Spring Boot來識別應用程序啓動後添加的用戶,並且它似乎只在啓動時才執行一次,並且從未再次運行)。你能舉個例子嗎?你如何從一個單獨的控制登錄頁面調用configureGlobal()?像這裏的GreetingController.java示例: https://spring.io/guides/gs/serving-web-content/ –

0

發現在本教程的解決方案: http://javasampleapproach.com/spring-framework/spring-security/use-spring-security-jdbc-authentication-postgresql-spring-boot

我有類似彈簧啓動安全指南的例子(https://spring.io/guides/gs/securing-web/)的東西,但我jdbcAuthentication取代inMemoryAuthentication上方部位(事做inMemoryAuthentication存在以下硬編碼和jdbcAuthentication是一個數據庫連接)。我通過在用戶和user_roles表中添加新行來測試它,同時spring-boot仍在運行,註銷,以新用戶登錄登錄,並且它工作正常。

相關問題