gpt4 book ai didi

java - spring 安全配置类出错

转载 作者:搜寻专家 更新时间:2023-11-01 02:08:46 25 4
gpt4 key购买 nike

在我的 spring 应用程序中,我使用的是 Spring 4.0.4 和 Spring Security 3.2.3。我直接从 sprin 网站上的教程复制了这段代码,但我在编译时遇到了问题,因为无法从 WebSecurityConfigurerAdapter 类和 中覆盖方法 registerAuthentication HttpSecurity 类没有方法 authorizeUrls。我缺少一个 jar 吗?还是版本问题?

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


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

@Override
protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("letsnosh").password("noshing").roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeUrls()
.antMatchers("/order/**").hasRole("USER")
.antMatchers("/checkout").hasRole("USER")
.anyRequest().anonymous()
.and()
//This will generate a login form if none is supplied.
.formLogin();
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}

最佳答案

3.2.0.RC1 开始,这似乎是 .authorizeRequests()。参见 https://jira.spring.io/browse/SEC-2202

关于java - spring 安全配置类出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23594159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com