猿问

spring security 不是来自 post ethod 的身份验证

我想通过 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);

请协助



缥缈止盈
浏览 172回答 2
2回答

慕工程0101907

Spring Security 中的默认登录路径类似于http://localhost:8080/login.&nbsp;按照此说明更改此路径。如果您已经这样做了,请提供您的实现。
随时随地看视频慕课网APP

相关分类

Java
我要回答