2

参考我之前关于Spring Security 和 REST 的问题,我取得了一些进展,但仍有一些问题。

  1. someaddres.com/rest/login正如我之前所说,用户将使用 HTTP 基本身份验证通过 POST 登录到我的 REST Web 服务。我仍然不知道如何做到这一点,但我已经将我的应用程序配置为使用org.springframework.security.web.authentication.www.BasicAuthenticationFilter,剩下的是实际映射还是我应该制作单独的@Controller(我正在使用 Spring MVC 进行 REST 映射)?我会很感激一个例子。
  2. 其次,正如我之前所说,我想在登录成功与否后执行一些自定义操作(某种日志 - 谁、何时以及从何处尝试登录和注销)。我已经尝试成功实现org.springframework.security.web.authentication.AuthenticationSuccessHandlerorg.springframework.security.web.authentication.AuthenticationFailureHandler但没有成功,因为我无法获得用于从任何地方登录的用户名,因为AuthenticationException#getAuthentication方法已被弃用。由于这些方法似乎是空的,所以我应该继承BasicAuthenticationFilter并覆盖它onSuccessfulAuthentication,还有什么?onUnsuccessfulAuthentication
  3. 实施密码恢复的最佳方法是什么?我想过简单地发布一些资源,这些资源会生成新密码并通过电子邮件发送。
  4. 如何配置安全性以生成令牌,该令牌将存储在会话中,假设在最后一次操作后的 10 分钟内有效?是否可以不使用 cookie 并将所有内容存储在服务器端?

这是我的安全bean:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:sec="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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop 
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    <sec:global-method-security secured-annotations="enabled" />
    <sec:http entry-point-ref="authenticationEntryPoint">
        <sec:intercept-url pattern="/*" />
        <sec:custom-filter position="BASIC_AUTH_FILTER" ref="basicAuthenticationFilter" />
        <sec:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" invalidate-session="true"/>
    </sec:http>
    <sec:authentication-manager alias="authenticationManager" erase-credentials="true">
        <sec:authentication-provider ref="daoAuthenticationProvider" />
    </sec:authentication-manager>
    <bean id="basicAuthenticationFilter" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManager" />
        <property name="authenticationEntryPoint" ref="authenticationEntryPoint" />
    </bean>
    <bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint">
        <property name="realmName" value="rms-rest" />
    </bean>
    <bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
        <property name="userDetailsService" ref="userDetailsService" />
    </bean>
    <bean id="authenticationSuccessHandler" class="pl.bcichecki.rms.handlers.impl.AuthenticationSuccessHandlerImpl" />
    <bean id="authenticationFailureHandler" class="pl.bcichecki.rms.handlers.impl.AuthenticationFailureHandlerImpl" />
    <bean id="logoutSuccessHandler" class="pl.bcichecki.rms.handlers.impl.LogoutSuccessHandlerImpl" />
</beans>

我感谢您的帮助。

4

0 回答 0