【发布时间】:2019-04-08 19:43:07
【问题描述】:
我正在开发一个 Web 应用程序并选择使用 Spring Security。这个想法是让用户通过身份验证以查看主页,如果用户未通过身份验证,他们将被重定向到登录页面。此登录页面还显示了一个注册表单的链接,这部分工作正常。
但是,我在尝试允许用户通过注册链接注册时遇到了问题。如果用户未通过身份验证(“showRegistrationForm”),则无法访问注册表单的链接
谁能提供关于为什么会发生这种情况的见解?我在下面的 SecurityConfig 中包含了代码 sn-p
@Override
protected void configure(HttpSecurity http) throws Exception {
//Restrict Access based on the Intercepted Servlet Request
http.authorizeRequests()
.antMatchers("/resources/**", "/register").permitAll()
.anyRequest().authenticated()
.antMatchers("/").hasRole("EMPLOYEE")
.antMatchers("/showForm/**").hasAnyRole("EMPLOYEE","MANAGER", "ADMIN")
.antMatchers("/save/**").hasAnyRole("MANAGER", "ADMIN")
.antMatchers("/delete/**").hasRole("ADMIN")
.and()
.formLogin()
// Show the custom form created for the below request mappings
.loginPage("/showSonyaLoginPage")
.loginProcessingUrl("/authenticateTheUser")
// No need to be logged in to see the login page
.permitAll()
.and()
// No need to be logged in to see the logout button.
.logout().permitAll()
.and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
【问题讨论】:
-
它看起来与注册时触发的操作有关。可以看看注册后触发了什么动作吗?
-
嗨阿米达拉,我已将注册码添加到原帖中。
-
映射到 registration-confirmation 的视图是什么? (假设你使用的是 spring-mvc)
-
注册确认显示一个基本的“注册成功”页面和一个返回用户登录的链接。用户输入用户名和密码即可成功登录,并将其带到“主页”
-
我想我想从“注册页面”中删除身份验证并允许任何人看到它,但是 .permiteall() 似乎没有做这项工作
标签: spring-boot spring-security