我想通过 Spring Security 中的 POST 方法对用户进行身份验证。该帖子命中了控制器方法,但用户从未通过身份验证。这是场景@Autowired private AuthenticationManagerBuilder builder; @RequestMapping(value="/signin", method = RequestMethod.POST) public ResponseData<Client> login(@RequestParam(value="username") String name, @RequestParam(value="password") String password,HttpServletRequest req) { System.out.println("here..."); //this executes Client ac = accountRepository.findByEmailAndActive(name,true); //does the authentication final Authentication authentication = builder.getOrBuild().authenticate( new UsernamePasswordAuthenticationToken( name, password ) ); SecurityContextHolder.getContext().setAuthentication(authentication); return ResponseData.successData(ac); }这是我的弹簧安全方法/处理程序.antMatchers(HttpMethod.POST,"/signin").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login").defaultSuccessUrl("/index") .loginProcessingUrl("/signin2") .permitAll() .and() .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutSuccessUrl("/login?logout=true") .deleteCookies("JSESSIONID", "remember-me") .invalidateHttpSession(true) .and().csrf().disable() .rememberMe().tokenRepository(persistentTokenRepository()).tokenValiditySeconds(1200000);请协助
2 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
Spring Security 中的默认登录路径类似于http://localhost:8080/login
. 按照此说明更改此路径。如果您已经这样做了,请提供您的实现。
添加回答
举报
0/150
提交
取消