0

我希望 Spring 安全性可以阻止访问动态 URL 更改

http://domain.com/ /** shareURL 是一个 ID,我遇到的问题是,如果我使用 shareID 1 访问,程序告诉我需要登录(一切正常)但是当我登录时尝试运行 shareID 2,程序应该再次告诉我重新登录,因为不是我的会话,但是现在..程序允许我访问这个shareID。

如何在不登录的情况下阻止该用户更改 shareID?

我也在使用预身份验证,因为如果特定的 shareID 不需要密码,spring security 会通过身份验证以避免登录页面并注入假身份验证。如果这是最好的问题

ShareID 1(不需要密码) ShareID 2(需要特定密码)

如果我使用共享 1 登录(无需密码自动登录),我可以访问共享 ID 2(因为我已登录)但不应该这样做。

Spring-security.xml(仅问题配置)
-->

<!-- Share Authentication Manager-->        

<beans:bean id="shareUserService" class="com.segator.ownline.service.impl.OwnlineShareSecurityService" />
<beans:bean id="preAuthenticationProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <beans:property name="preAuthenticatedUserDetailsService"
                    ref="shareUserService" />
</beans:bean>

<beans:bean id="preAuthFilter"
            class="com.segator.ownline.controller.config.ShareLinkAuthenticationFilter">
    <beans:property name="authenticationManager" ref="appControlAuthenticationManager" />
</beans:bean>

<authentication-manager alias="appControlAuthenticationManager" id="shareAuth">
    <authentication-provider ref="preAuthenticationProvider" />
</authentication-manager>  

我想我需要一个额外的配置来告诉 Spring Security,如果用户更改 shareID 需要登录,例如,如果我可以实现正确的方法来拦截器 URL 示例

拦截 url 模式="/share/**" 访问="hasRole('ROLE_SHARE') && sameShareIDLogged()"

对不起我的英语不好,我现在只是学习。

4

1 回答 1

0

I solve the problem adding some properties on preAuthFilter

    <beans:property name="authenticationManager" ref="shareAuthenticationManager" />
    <beans:property name="checkForPrincipalChanges" value="true" />
    <beans:property name="invalidateSessionOnPrincipalChange" value="true" /> <!--Default true but i put to understand how work-->

checkForPrincipalChanges --> If the principal is diferent that the session(in my case principal=shareID, then try to relogin

invalidateSessionOnPrincipalChange--> Generate new Sesion

Now the problem i have is that when i run j_spring_security_check on my share Form Login is redirecting to my default login form

于 2014-06-15T14:59:13.797 回答