小编Mar*_*SKI的帖子

使用自己的登录表单重定向太多 - Spring Security

我想自己登录表格.当我更改登录页面时,我无法打开它.Google Chrome告诉我,此页面的重定向过多......

我的代码:

@RequestMapping(value="/login", method = RequestMethod.GET)
public ModelAndView loginPage() {
    ModelAndView modelAndView = new ModelAndView("login");
    return modelAndView;
}

@RequestMapping(value="/loginError", method = RequestMethod.GET)
public ModelAndView loginErrorPage() {
    ModelAndView modelAndView = new ModelAndView("login");
    modelAndView.addObject("error", "true");
    modelAndView.addObject("msg", "invalid login credentials");
    return modelAndView;
}
Run Code Online (Sandbox Code Playgroud)

设置:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable().authorizeRequests()
            .antMatchers("/**").access("hasRole('ROLE_USER')")
            .and().formLogin().loginPage("/login").defaultSuccessUrl("/index").failureUrl("/loginError");
}
Run Code Online (Sandbox Code Playgroud)

和登录表格:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
         pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD …
Run Code Online (Sandbox Code Playgroud)

spring jsp spring-security

4
推荐指数
1
解决办法
5754
查看次数

标签 统计

jsp ×1

spring ×1

spring-security ×1