2016-07-01 13 views
2

私は、Spring SecurityのWebSecurityConfigを管理者権限に使用しています。 と、春のアプリケーションが起動したときにアクセス権が1回だけロードされました。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ブートが必要ですが、このクラスは起動時に一度だけ実行され、再度実行されなかったようです)。コードを使って例を挙げてもらえますか?ログインを制御する別のページからconfigureGlobal()をどのように呼び出しますか? GreetingController.javaのように、ここの例: https://spring.io/guides/gs/serving-web-content/ –

0

は、このチュートリアルで解決策を見つけた:私は春ブートセキュリティガイドの例(https://spring.io/guides/gs/securing-web/)に似た何かを持っていたが、私はinMemoryAuthenticationされた状態で行うには(何か上記のサイト次jdbcAuthenticationinMemoryAuthenticationを置き換え http://javasampleapproach.com/spring-framework/spring-security/use-spring-security-jdbc-authentication-postgresql-spring-boot

ハードコードされ、jdbcAuthenticationはdb接続です)。私は、spring-bootがまだ実行されていて、ログアウトして、新しいユーザーログインでログインしている間に、usersとuser_rolesテーブルに新しい行を追加することでそれをテストしました。

関連する問題