【问题标题】:Spring Security Spring-boot-starter-web migrate from 1.2.5 to 1.3.2.RELEASESpring Security Spring-boot-starter-web 从 1.2.5 迁移到 1.3.2.RELEASE
【发布时间】:2016-06-03 21:25:40
【问题描述】:

我在我的应用程序中使用 Spring Security。到现在为止我用过

org.springframework.boot spring-boot-starter-web 1.2.5 发布

现在我想使用

org.springframework.boot spring-boot-starter-web 1.3.2 发布

我的 SecurityConfiguration.java 如下所示:

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailsService userService;

@Autowired
public void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userService).passwordEncoder(new BCryptPasswordEncoder());
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().anyRequest().authenticated().and().formLogin().loginPage("/login.html")
            .failureUrl("/login.html?error").defaultSuccessUrl("/index", true).permitAll().and().logout()
            .logoutSuccessUrl("/logout.html").permitAll().and().csrf().disable();
 }
}

我的一项休息服务如下所示:

@RequestMapping("/test")
@PreAuthorize("hasRole('ADMIN')")
public List<Tests> getTests() {
    return ...
}

旧版本有效。使用较新的版本,如果我尝试调用其余服务,则会收到 403 禁止。有谁知道如何让它再次工作?

【问题讨论】:

    标签: spring spring-mvc spring-security spring-boot


    【解决方案1】:

    从 1.2.5 升级到 1.3.2 时,您还会将 spring-security 从 3.X 更新到 4.X。

    您可以在自己的项目中覆盖 spring 安全依赖项以保留以前版本的 spring-security。 (我觉得不推荐,至少启动时会看到警告)

    或者,您可以仔细阅读下面的文档并在从 spring-security 3.X 迁移到 4.X 时执行所有必要的配置更新

    Migration from spring security 3 to 4 (xml config)

    Migration from spring security 3 to 4 (java config)

    【讨论】:

    • 感谢您的回答。我阅读了这些文章,但没有实现任何这些更改的功能。
    猜你喜欢
    • 1970-01-01
    • 2015-10-05
    • 2020-07-07
    • 2018-03-28
    • 2021-09-23
    • 2016-01-29
    • 1970-01-01
    • 2017-08-14
    • 2021-03-08
    相关资源
    最近更新 更多