3

我正在使用 Spring MVC 和 Spring Security。在我找到这篇文章之前,我的重定向正在将 https 切换为 http。Spring MVC“redirect:”前缀总是重定向到http——我如何让它留在https上?。我还必须在我的 AjaxUrlBasedViewResolver 中将 redirectHttp10Compatible 属性设置为 false。

问题是https登录后仍然切换到http。登录后,我可以在地址栏中将我的应用程序设置回 https 并且它会保持不变。此外,由于上述解决方案,我正在为大多数用户使用 IP 身份验证,在这种情况下,https 仍然存在。

我正在尝试将 redirectHtp10Compatible 添加到 login_security_check 或类似的东西,但被卡住了。这里我的security-config.xml.

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
         xmlns:beans="http://www.springframework.org/schema/beans"
         xmlns:util="http://www.springframework.org/schema/util"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

<global-method-security pre-post-annotations="enabled" />

<http auto-config='true' access-denied-page="/login">
    <intercept-url pattern="/static/styles/**" filters="none" />
    <intercept-url pattern="/static/scripts/**" filters="none" />

    <intercept-url pattern="/login/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/error/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/api/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/ajaxTimeOut" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/checkSystem" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/adminUser/**" access="ROLE_SSADMIN" />
    <intercept-url pattern="/**" access="ROLE_USER" />

    <form-login login-page="/ajaxTimeOut" login-processing-url="/login_security_check" authentication-failure-url="/login?login_error=t" default-target-url="/" always-use-default-target="true" />
    <logout logout-url="/logout" logout-success-url="/"/>
    <custom-filter position="PRE_AUTH_FILTER" ref="ipPreAuthFilter" />
</http>

<beans:bean id="ipAuthDetailsSource" class="com.mydomain.security.IPBasedPreAuthenticatedDetailsSource" />

<beans:bean id="ipPreAuthFilter" class="com.mydomain.security.IPPreAuthenticationFilter">
    <beans:property name="authenticationManager" ref="preAuthManager" />
    <beans:property name="authenticationDetailsSource" ref="ipAuthDetailsSource" />
</beans:bean>

<beans:bean id="preAuthManager" class="org.springframework.security.authentication.ProviderManager">
    <beans:property name="providers">
        <beans:list>
            <beans:ref local="preAuthProvider"/>
        </beans:list>
    </beans:property>
</beans:bean>

<beans:bean id="preAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <beans:property name="preAuthenticatedUserDetailsService" ref="preAuthUserService" />
</beans:bean>

<beans:bean id="preAuthUserService" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService" />

<authentication-manager>
    <authentication-provider user-service-ref="userService">
        <password-encoder ref="passwordEncoder" >
            <salt-source user-property="salt" />
        </password-encoder>
    </authentication-provider>
</authentication-manager>

<beans:bean id="userService" class="com.mydomain.security.UserServiceImpl" />
<beans:bean id="passwordEncoder" class="com.mydomain.security.PasswordEncoder">
    <beans:constructor-arg value="256" />
</beans:bean>
4

2 回答 2

2

你有没有试过这个:

<http>
    <intercept-url pattern="/secure/**" access="ROLE_USER" requires-channel="https"/>
    ...
</http>

http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-requires-channel

于 2012-06-11T13:19:38.190 回答
1

得到了解决方案。

<security:form-login login-page="/Login"
                             login-processing-url="/j_spring_security_check"
                             default-target-url="https://127.0.0.1/abcWeb/"
                             always-use-default-target="true"
                             authentication-failure-url="https://127.0.0.1/abcWeb/loginfailed"
                                  />
    <security:logout logout-success-url="https://127.0.0.1/abcWeb/logout" />

我为登录处理添加了绝对路径,其余部分我将此 p:redirectHttp10Compatible="false" 添加到 InternalViewResolver

于 2012-06-12T09:21:25.473 回答