java如何使用SpringSecurity4.0.1使用Auth令牌实现Rest完整Web服务。释放
我正在尝试用RESTfulWebService设计一个API管理器。在Spring的新版本中,我们可以在Java代码中组合所有内容,而无需使用web.xml
或securityconfig.xml
。
根据Authtoken的概念,API管理器应该具有用于用户身份验证的Authtoken和刷新令牌。
请告诉我如何使用Spring Security实现RESTfull Web服务的示例源代码或指导
- 我需要知道如何在Java代码中实现所有配置李>
- 它还应该具有Authtoken概念李>
本教程介绍了正确的方法
http://www.beingjavaguys.com/2014/10/spring-security-oauth2-integration.html
但是Spring配置在Spring中。xml文件
我还需要把它们放到Java级别
# 1 楼答案
在Stormpath的人们有一个实现Oauth的非常简单的解决方案。请看一下Using Stormpath for API Authentication
作为总结,您的解决方案如下所示:
当用户按下登录按钮时,前端将通过RESTAPI安全地将凭据发送到后端
2.1。顺便说一下,Stormpath大大增强了这里的所有可能性。您可以通过Stormpath的IDSite将登录/注册功能完全委托给Stormpath,也可以将其委托给Servlet Plugin,而不必拥有自己的登录页面。Stormpath还支持Google、Facebook、LinkedIn和Github登录
然后,您的后端将尝试根据Stormpath后端对用户进行身份验证,并将返回一个
access token
,结果:然后,对于每个经过身份验证的请求,您的后端将执行以下操作:
所有这些都不需要任何特殊的Spring安全配置,这是可以在任何框架中运行的普通Java代码
请查看here了解更多信息
希望有帮助
免责声明,我是一名积极的Stormpath贡献者