Spring security Spring Security javaConfig登录帖子未解析

Spring security Spring Security javaConfig登录帖子未解析,spring-security,spring-java-config,Spring Security,Spring Java Config,它使用XMLConfig工作,但JavaConfig混淆了这一点。我有: gen controller正在为登录页提供服务,因此我可以在登录时列出客户端 自定义UserDetailsServiceImpl,这样我就可以根据DB进行身份验证 问题在于,发布登录表单会得到: HTTP状态405-不支持请求方法“POST” 启动时securityConfig中的断点显示它已加载,并且似乎是http。设置了配置程序,但是loginProcessingUrl似乎没有捕获登录表单帖子 公共类Spring

它使用XMLConfig工作,但JavaConfig混淆了这一点。我有:

  • gen controller正在为登录页提供服务,因此我可以在登录时列出客户端
  • 自定义
    UserDetailsServiceImpl
    ,这样我就可以根据DB进行身份验证
问题在于,发布登录表单会得到:

HTTP状态405-不支持请求方法“POST”

启动时
securityConfig
中的断点显示它已加载,并且似乎是
http。设置了配置程序
,但是
loginProcessingUrl
似乎没有捕获登录表单帖子

公共类SpringWebAppInitializer扩展了AbstractAnnotationConfigDispatcherServletInitializer{
@凌驾
受保护类[]getRootConfigClasses(){
返回新类[]{AppConfiguration.Class,SecurityConfiguration.Class};
}
@凌驾
受保护类[]getServletConfigClasses(){
返回新类[]{WebConfiguration.Class};
}
@凌驾
受保护的字符串[]getServletMappings(){
返回新字符串[]{“/conv/*”};
}
}
@配置
@启用Web安全性
公共类安全配置扩展了WebSecurity配置适配器{
@自动连线
私有用户详细信息ServiceImpl用户详细信息ServiceImpl;
@自动连线
public void configureGlobal(AuthenticationManagerBuilder auth)引发异常{
auth.userDetailsService(userDetailsServiceImpl);
}
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http.csrf().disable();
http.antMatcher(“/conv/u/**”).authorizeRequests().anyRequest().hasRole(“用户”);
http.antMatcher(“/conv/a/**”).authorizeRequests().anyRequest().hasRole(“ADMIN”);
http.formLogin().loginPage(“/conv/common/logon”);
http.formLogin().usernameParameter(“用户名”);
http.formLogin().passwordParameter(“密码”);
http.formLogin().defaultSuccessUrl(“/conv/”,true);
http.formLogin().loginProcessingUrl(“/conv/common/logon”);
http.formLogin().failureUrl(“/conv/common/logon?error=true”);
http.logout().logoutUrl(“/conv/common/logout”);
http.logout().invalidateHttpSession(true);
http.logout();
}
@凌驾
public void configure(WebSecurity web)引发异常{
忽略
.antMatchers(“/common/**”)
.antMatchers(“/favicon.ico”);
}
@豆子
公共SaltSource SaltSource(){
ReflectionSaltSource rss=新ReflectionSaltSource();
rss.setUserPropertyToUse(“xyz”);
返回rss;
}
@豆子
公共密码编码器PasswordEncoder(){
返回新的StandardPasswordEncoder();
}
}
@RequestMapping(method=RequestMethod.GET,value=“/common/logon”)
公共模型和视图logonHandler(HttpServletRequest请求,HttpServletResponse响应){
List clients=clientManager.searchClients(“”,null,null,null);
...
返回新的ModelAndView(“通用/登录”、“客户端”、客户端);
}

更改此选项

<form:form name="logonForm" action="/conv/common/logon" method="post" target="_top" autocomplete="off">
<input type="text" name="userLogon" required="required" autocomplete="off" autofocus="autofocus"/>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form:form>
@RequestMapping(method=RequestMethod.GET, value="/common/logon")
对此(刚刚删除的method=RequestMethod.GET)

改变这个

<form:form name="logonForm" action="/conv/common/logon" method="post" target="_top" autocomplete="off">
<input type="text" name="userLogon" required="required" autocomplete="off" autofocus="autofocus"/>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form:form>
@RequestMapping(method=RequestMethod.GET, value="/common/logon")
对此(刚刚删除的method=RequestMethod.GET)

我想出来了

第一个修正:

公共类SecurityWebAppInitializer扩展了AbstractSecurityWebApplicationInitializer{..} 在任何在线示例中都没有。 我甚至不知道这是必须的。 阅读新的spring.io4.0文档给了我答案

我补充说:

public class SecurityWebAppInitializer extends AbstractSecurityWebApplicationInitializer {
}

现在,将读取SecurityConfiguration中的设置


第二个修正:

安全配置中的“http”和“and()”从未在许多在线示例中解释过

阅读了spring.io中的4+个安全文档之后,才理解了它

混淆“http”在:configure(HttpSecurity-http)中,但“表示”旧xml配置文件中的“http”xml标记

从不知道“.and()”表示结束xml标记

为什么最后一项没有最后的“.and()”

为什么像.csrf().disable()这样的设置不需要用.and()关闭

.和()仅显示necc。要关闭父xml标记,而不是子xml标记,我找到了它

第一个修正:

公共类SecurityWebAppInitializer扩展了AbstractSecurityWebApplicationInitializer{..} 在任何在线示例中都没有。 我甚至不知道这是必须的。 阅读新的spring.io4.0文档给了我答案

我补充说:

public class SecurityWebAppInitializer extends AbstractSecurityWebApplicationInitializer {
}

现在,将读取SecurityConfiguration中的设置


第二个修正:

安全配置中的“http”和“and()”从未在许多在线示例中解释过

阅读了spring.io中的4+个安全文档之后,才理解了它

混淆“http”在:configure(HttpSecurity-http)中,但“表示”旧xml配置文件中的“http”xml标记

从不知道“.and()”表示结束xml标记

为什么最后一项没有最后的“.and()”

为什么像.csrf().disable()这样的设置不需要用.and()关闭


.和()仅显示necc。要关闭父xml标记,而不是子xml标记,请将:添加到jsp表单和/或显示控件,我有一个隐藏字段(添加在上面)。为清晰起见,还添加了处理GET登录请求的控制器。这是一个似乎没有被映射的帖子。我甚至试过forrm action=“j\u spring\u security\u check”也没用。启动时安全配置的断点屏幕快照添加到上面添加:在jsp表单和/或显示控件中,我有一个隐藏字段(添加到上面)。为清晰起见,还添加了处理GET登录请求的控制器。这是一个似乎没有被映射的帖子。我甚至试过forrm action=“j\u spring\u security\u check”也没用。启动时安全配置处的断点上面添加了screensnap