Spring和Spring安全性的REST身份验证

时间:2014-05-15 08:41:52

标签: java spring rest spring-security

我想使用Spring和Spring Security开发一个带REST的RESTfull Web服务。 我的所有用户都将使用加密的密码和角色存储在数据库中。 会话应存储在上下文中,直到会话超时或注销以允许使用其他Web服务。

如果有人可以帮助我会很棒。

由于

2 个答案:

答案 0 :(得分:0)

看一下Jersey with Spring及其ContextSecurityFilter,我不建议使用spring security。如果你做了一个很好的授权尝试使用@RolesAllowed方法。

答案 1 :(得分:-1)

您需要创建一个Spring安全上下文并包含在您的Web应用程序中。

     <security:http pattern="/../../../**" entry-point-   
       ref="CustomAuthenticationEntryPoint"
    <security:custom-filter ref="authenticationTokenProcessingFilter"
        position="FORM_LOGIN_FILTER" />
    <security:intercept-url pattern="/.*"
        access="isAuthenticated()" />
    <security:intercept-url pattern="/../../../.*"
        access="isAuthenticated()" />
    <security:intercept-url pattern="/../../../.*"
access="isAuthenticated()" /> />

您可以根据您的网址或其他人选择决策选民。

    <bean id="accessDecision"          
         class="org.springframework.security.access.vote.UnanimousBased">
    <property name="decisionVoters">
        <set>
            <bean  
     class="org.springframework.security.web.access.expression.WebExpressionVoter">
    </bean>
            <bean c   
    class="org.springframework.security.access.vote.AuthenticatedVoter"></bean>
        </set>
    </property>
</bean>

您可以拥有自己的自定义身份验证入口点并添加代码。

可以找到更多详细信息here