java - 如何在没有弹簧安全的情况下使用 api 密钥保护 rest api
问题描述
我有一个 rest api MyRestApi.war
,它是一个 spring boot 和 spring mvc 项目。
还有另一个 web 项目A.war
是一个普通的 spring 项目。它的前端如javascript
和后端java code
如需调用MyRestApi
。用户需要登录A.war
才能使用。
我不需要对 进行权限控制MyRestApi
,只有用户登录才能通过前端和后端A.war
访问MyRestApi
A.war
有一些解决方案,例如API key
, 。jwt
OAuth
我想尝试这三种方法,然后选择一种。
但是当我搜索类似的东西时api key authentication
,他们都习惯spring security
这样做。
那么如何在MyRestApi
没有弹簧安全的情况下使用 api 密钥进行保护。
解决方案
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.
推荐阅读
- javascript - 如何发送带有 BinaryArray 的 json?
- salesforce - Salesforce 社区 - 通过 Apex 登录的用户不会更新当前用户
- python - 如何使用 Python/pandas 获取带有行摘要的分钟/小时财务数据?
- nativescript - 失败的“tns run android –bundle”无效的选项对象
- c++ - Live555“testWAVAudioStreamer”流原始 pcm a-law 音频(无文件头)
- javascript - 使用 chartjs 和 ng2 的角度数据可视化
- flutter - 重用输入验证器
- javascript - 使用ajax一次上传多个文件
- python - 通过在 Python 中指定时间戳的日期格式从时间戳中提取月份
- excel-formula - 如果公式正确,时间在 Excel 中显示不正确