Java 如何强制只有登录的用户才能调用RESTAPI调用?

Java 如何强制只有登录的用户才能调用RESTAPI调用?,java,rest,spring-mvc,web,Java,Rest,Spring Mvc,Web,我使用的是带spring security的is spring mvc。为了安全起见,我使用请求头中的JWT令牌来验证客户端的真实性 我必须公开一个API,它允许用户发送一个“follow”请求 我当前的API如下所示 @RequestMapping(value = "/api/follow/{userProfileId}" ,method=POST) public ResponseEntity<Integer> follow(@PathVariable("userProfi

我使用的是带spring security的is spring mvc。为了安全起见,我使用请求头中的JWT令牌来验证客户端的真实性

我必须公开一个API,它允许用户发送一个“follow”请求

我当前的API如下所示

@RequestMapping(value = "/api/follow/{userProfileId}" ,method=POST)
    public ResponseEntity<Integer> follow(@PathVariable("userProfileId")
    Long  userProfileId , @RequestBody IdWrapper idWrapper) {

        //userProfileId , user to whom request is being sent
        //IdWrapper contains the ID of the user who is sending the 
        //follow request
        System.out.println("sending interest to "+userProfileId);

        //business logic 
        return new ResponseEntity<Integer>(0,HttpStatus.OK);;
    }
@RequestMapping(value=“/api/follow/{userProfileId}”,method=POST)
公共响应跟踪(@PathVariable(“userProfileId”)
长userProfileId,@RequestBody-IdWrapper-IdWrapper){
//userProfileId,向其发送请求的用户
//IdWrapper包含发送请求的用户的ID
//遵照要求
System.out.println(“将兴趣发送到”+userProfileId);
//业务逻辑
返回新的ResponseEntity(0,HttpStatus.OK);;
}
到目前为止还不错,但是如果某个客户端发现了api url并使用其他id(而不是自己的id)构造了一个api调用,该怎么办呢?这意味着用户1可以代表用户2向用户3发送follow请求

我认为REST的本质是无状态的,但是我如何在不跟踪状态的情况下解决这个问题呢?REST如何解决这些问题