首页 > 解决方案 > 如何在没有弹簧安全的情况下使用 api 密钥保护 rest api

问题描述

我有一个 rest api MyRestApi.war,它是一个 spring boot 和 spring mvc 项目。

还有另一个 web 项目A.war是一个普通的 spring 项目。它的前端如javascript和后端java code如需调用MyRestApi。用户需要登录A.war才能使用。

我不需要对 进行权限控制MyRestApi,只有用户登录才能通过前端和后端A.war访问MyRestApiA.war

有一些解决方案,例如API key, 。jwtOAuth

我想尝试这三种方法,然后选择一种。

但是当我搜索类似的东西时api key authentication,他们都习惯spring security这样做。

那么如何在MyRestApi没有弹簧安全的情况下使用 api 密钥进行保护。

标签: javaspringrestrestful-authenticationrest-security

解决方案


You can write your own filter if you don't want to use spring security. This filter will interecept all the URLs. In this filter you can check for the API key in the headers and validate. If it's validate, let the chain continue else throw some meaningful error to the user/application.


推荐阅读