
所需的业务是:
>典型的客户端 – 服务器架构:服务器端的移动客户端和RESTful服务
>客户有不同的登录移动应用程序的选择:应用程序登录和Facebook登录
>必须保护服务器端的所有RESTful服务免受未经授权的用户的攻击
我的职责是开发RESTful服务.我非常擅长应用服务器,Java EE,JMS,JDBC,分布式事务(XA),但我不太擅长安全性:(
我用Spring开发了一些STATELESS RESTful webservices.这些服务不受保护,所以每个人都可以使用它们.
例如:
> http://…../API/country/ {** user_ID **}
> http://…../API/country/ {** user_ID **},{country_ID}
> ……
我的每个webservices都有一个user_ID输入参数,因为我需要识别哪个用户进行了服务器调用. Web服务的结果取决于用户.当然,这绝对是正常的.
现在,我必须开发一些新东西,因为我必须保护这些Web服务免受未经授权的用户的攻击.
我的想法是:
(*)我将创建两个这样的新web服务:
applicationLogin(String username,String password)[/ INDENT]
和
facebookLogin(String accesstoken)
> http://…../API/login/ {username},{password}
> http://….. / API / login / {facebook access token}
(*)我必须保护我的网络服务免受未经授权的用户的侵害
用户日志记录过程可能如下所示:
(1)用户填写他/她的移动设备上的用户名和密码字段
(2)单击应用程序登录按钮
(3)移动应用程序向http://….. / API / login / {username},{password}公共服务发出服务器调用
(4)如果用户名和密码正确,我将生成一个令牌(一个带有过期日期信息的长字符串),我将把用户名和令牌字符串放入http头的答案中
(5)之后,所有客户端在进行webservice调用时必须将这两个参数(用户名和令牌)发送回服务器.
在服务器端,我可以从http请求中读取用户名,因此我可以从所有Web服务的签名中删除user_ID参数.
我试图在Spring中实现这个过程.我想我需要使用Spring安全模块中的PRE_AUTH_FILTER.但我不知道我的想法是否合适?
我做的:
web xml
<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class></filter><filter-mapPing> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/API/country/*</url-pattern></filter-mapPing><context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-security.xml,/WEB-INF/applicationContext.xml</param-value></context-param>
的applicationContext-security.xml文件
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> <security:http use-Expressions="true" create-session="stateless" auto-config="false" entry-point-ref="authenticationEntryPoint"> <security:intercept-url pattern="/API/login/*" access="permitAll"/> <security:intercept-url pattern="/API/country/*" access="isAuthenticated()" /> <security:custom-filter position="PRE_AUTH_FILTER" ref="authenticationTokenProcessingFilter" /> </security:http> <bean ID="authenticationEntryPoint" /> <bean ID="userDetailsServiceImpl" /> <bean ID="preAuthenticationProvIDer" > <property name="preAuthenticatedUserDetailsService" ref="userDetailsServiceImpl" /> </bean> <bean ID="authenticationTokenProcessingFilter" > <property name="authenticationManager" ref="appControlAuthenticationManager" /> </bean> <security:authentication-manager alias="appControlAuthenticationManager"> <security:authentication-provIDer ref="preAuthenticationProvIDer" /> </security:authentication-manager> </beans>
您如何看待我的登录流程?这是开始实现令牌处理方法的好方法吗?
@R_404_6120@ 如果您接受一个小的更改,您可以使用开箱即用的安全性.Spring安全性使用http会话来存储用户详细信息.并且https由包含会话密钥或JsessionID参数的会话cookie进行正常跟踪.
另外一个提示:使用https而不是http.
总结以上是内存溢出为你收集整理的web-services – RESTful webservice Spring令牌认证全部内容,希望文章能够帮你解决web-services – RESTful webservice Spring令牌认证所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)