【问题标题】:how could I reload websecurityconfig runtime我如何重新加载 websecurityconfig 运行时
【发布时间】:2016-11-03 11:44:36
【问题描述】:

我使用 Spring Security 的 WebSecurityConfig 来管理权限。 并且权限只在 spring 应用程序启动时加载一次。

那么当权限改变时,如何在运行时手动重新加载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);
    }

}

【问题讨论】:

  • 您的问题找到解决方案了吗?

标签: spring-security spring-boot


【解决方案1】:

只需将您需要的任何东西注入 WebSecurityConfig 即可。您可以在 WebSecurityConfig 中使用 @Autowire 和 @Value。

【讨论】:

  • 我有同样的问题(我需要 Spring Boot 来识别在应用程序启动后添加的用户,而且似乎这个类在它启动时只执行一次并且再也不会运行)。你能举个例子吗?如何从控制登录的单独页面调用 configureGlobal()?就像来自 GreetingController.java 的例子一样:spring.io/guides/gs/serving-web-content
  • @NoonTime 你找到解决问题的方法了吗?
  • @faraa 我最终使用了 jdbcAuthentication。我在下面添加了一个答案:stackoverflow.com/a/47232751/1363715
  • @NoonTime 谢谢...但我必须使用 jdbcAuthentication
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-22
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 2013-02-22
  • 2012-01-30
  • 1970-01-01
相关资源
最近更新 更多