【问题标题】:spring security 3.0 restfull authentification for mobile client移动客户端的spring security 3.0 RESTful认证
【发布时间】:2013-03-31 23:37:28
【问题描述】:

我们有一个现有的 jsf/spring 应用程序,它使用 spring security 进行身份验证和授权。

现在我们要添加一个 RESTful Web 服务层,供移动客户端(本机 android 应用程序)使用。现有的身份验证过程使用 j_spring_security_check 和自定义过滤器。

我可以在同一上下文中处理 restful api 身份验证和授权吗?如果是,怎么做?

【问题讨论】:

    标签: spring security rest authentication mobile


    【解决方案1】:

    一种可能性是为 API 领域创建另一个安全配置。将其配置为 HTTP BASIC 身份验证(如果适合您并且 API 通过 https 提供)。

    例如:

    <http use-expressions="true" pattern="/api/**" realm="API Realm" create-session="stateless">    
         ...
         <http-basic />
         ...
         <logout logout-url="/api/logout" />
    </http>
    

    编辑: 根据评论者的评论,我正在纠正我的答案:不幸的是,这种方法在 Spring Security 3.0 中不起作用,因为 Spring Security 配置中的多个 http 元素是在 3.1 中添加的。

    【讨论】:

    • 我不认为 spring security 3.0 允许多个 http 标签
    • 对于 3.0,也许可以在 Spring 安全配置中定义 DelegatingAuthenticationEntryPoint,将 Web 应用的 URL 委托给 LoginUrlAuthenticationEntryPoint,API URL 委托给 BasicAuthenticationEntryPoint。
    • 听起来合乎逻辑,我会试试的。但是现在我正在使用注释来保护我的 api 并且它可以工作! (当然,API 路径过滤器设置为“无”)
    猜你喜欢
    • 2017-09-17
    • 2015-11-05
    • 1970-01-01
    • 2012-11-06
    • 2012-06-30
    • 2012-03-13
    • 2018-02-14
    • 2016-07-17
    • 2012-10-22
    相关资源
    最近更新 更多