有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpring安全性:包含AuthenticationManager的方法。authenticate()引发异常

我有一个方法在里面使用了authenticate()方法,我发现令人困惑的是AuthenticationManager.authenticate()在身份验证失败时会抛出AuthenticationException,但是authenticateUser方法不会抛出任何异常,也不会触发编译错误

@PostMapping("/signin")
    public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginForm loginRequest){

        Authentication authentication = authenticationManager.authenticate(
                new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword()));

        SecurityContextHolder.getContext().setAuthentication(authentication);

    }


共 (0) 个答案