【发布时间】:2022-06-12 02:44:11
【问题描述】:
我正在尝试制作一个使用以下内容的 Web 应用程序: 春季启动, mysql, JDBC , MVC, DAO 百里香叶, IntelliJ
我正试图弄清楚 Spring 安全性是如何工作的(我遇到了很多困难)。 我的观点整理如下:
resources(folder): - ________static(folder)
|____templates(folder):__________images(folder)
|___userOnly(folder):_____header.html
| |__help.html
| |__menu.html
| |__newDocForm.html
| |__profil.html
|
|__firstPage.html
|__header.html
|__home.html
|__index.html
|__inscriptionForm.html
|__loginPage.html
我希望身份不明的用户可以访问除“userOnly”中包含的视图之外的所有视图,并且我的“loginPage”页面用作登录页面。
如果我理解正确,我必须创建一个继承自“WebSecurityConfigurerAdapter”的类。 我做了什么。 然后配置“配置”,我不能正确地做:(
@Configuration
@EnableWebSecurity
public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/userOnly/**").hasRole("USER")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/loginPage.html");
}
}
对不起,如果我的问题看起来很奇怪,但英语不是我的第一语言
【问题讨论】:
标签: java spring spring-boot spring-security