Вы можете добавить повара ie с уникальным идентификатором в браузер, который отправил запросы.
Следующие запросы будут отправлены с этим поваром ie, и вы можете использовать его значение, чтобы проверить, посылал ли этот браузер запросы к вашему сервису.
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@RestController
public class ExampleController {
Map<String, String> agents = new HashMap<>();
@GetMapping("/foo")
public void foo(HttpServletResponse response, @CookieValue("agent-id") String agentId) {
// If the cookie is not present in the browser, the value of agentId is null
if (agentId == null) {
String newAgentId = UUID.randomUUID().toString();
agents.put(newAgentId, "request specific information");
Cookie newAgentIdCookie = new Cookie("agent-id", newAgentId);
response.addCookie(newAgentIdCookie);
System.out.println("Now I know you");
} else if (agents.containsKey(agentId)) {
System.out.println(agents.get(agentId));
}
}
}