我是Spring Security的新手,我正在尝试用Spring Security创建一个登录表单。
这是必需的场景:
1)用户使用用户名-密码登录应用程序(请注意,我使用的是spring Security提供的默认登录页面) 2)如果登录正常,则用户转到eventList.jsp 3)如果登录是KO (凭据错误),则会显示错误
我的WebSecurityConfigurerAdapter配置:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("amdin").password("111111").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().defaultSuccessUrl("/eventList");
}错误1:如果我插入了正确的凭据,我看不到/eventList,但我收到一个404Credentials为什么我不重定向到/eventList?(在我的RequestMapping注解中,/eventList只接受GET吗?
@RequestMapping(value = {"/eventList"}, method = RequestMethod.GET)错误2:如果我尝试通过在浏览器的/eventList末尾添加"eventList“来”手动“转到URL,则无需执行登录操作即可访问所请求的页面!THe我希望在不执行登录操作的情况下可以访问的唯一网址是登录页面本身!
行.anyRequest().authenticated()不应该允许所有这一切!
我怎样才能得到我想要的东西?
提前使用TY
发布于 2017-05-19 01:10:55
正确的安全链如下所示:
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/eventList")
.permitAll()
.and()
.logout()
.permitAll();您还忘记了定义loginPage() Hope的permitAll()语句,希望它能帮上忙!如果你需要进一步的帮助,请给我一个下午。
https://stackoverflow.com/questions/44052446
复制相似问题