在用户使用Spring Security初次登录时,实现强制密码更改的最优雅方法是什么?
我尝试实现这里AuthenticationSuccessHandler提到的自定义,但正如rodrigoap所提到的,如果用户在地址栏手动输入URL,即使用户没有更改密码,用户仍然可以继续访问该页面.
我用过滤器ForceChangePasswordFilter做了这个.因为如果用户手动键入url,他们可以绕过更改密码表单.使用过滤器,请求始终被截获.
因此,我继续实施自定义过滤器.
我的问题是,当我实现一个自定义过滤器和发送里面重定向,它会通过过滤器再次提到引起无限重定向循环这里.我尝试通过在security-context.xml中声明两个http标签来实现所提到的解决方案,第一个标签具有pattern属性,但它仍然通过我的自定义过滤器:
<http pattern="/resources" security="none"/>
<http use-expressions="true" once-per-request="false"
auto-config="true">
<intercept-url pattern="/soapServices/**" access="permitAll" requires-channel="https"/>
...
<custom-filter position="LAST" ref="passwordChangeFilter" />
</http>
...
<beans:bean id="passwordChangeFilter"
class="my.package.ForcePasswordChangeFilter"/>
<beans:bean id="customAuthenticationSuccessHandler"
class="my.package.CustomAuthenticationSuccessHandler" >
</beans:bean>
<beans:bean id="customAuthenticationFailureHandler"
class="my.package.CustomAuthenticationFailureHandler" >
<beans:property name="defaultFailureUrl" value="/login"/>
</beans:bean>
Run Code Online (Sandbox Code Playgroud)
我当前的实现(有效)是:
isFirstLoginisFirstLogin是否已设置
chain.doFilter()我对此实现的问题是访问我的资源文件夹也会通过此过滤器导致我的页面失真(因为*.js和*.css未成功检索).这就是我<http>在我的安全应用程序context.xml中尝试使用两个标签的原因(这不起作用).
因此,如果servletPath启动或包含"/ resources",我最终必须手动过滤请求.我不希望它像这样 - 必须手动过滤请求路径 - 但现在它就是我拥有的.
这样做的优雅方式是什么?