0

最近、iOS のホーム画面から Web アプリを起動するかフォアグラウンドに移動するたびに再認証されるという問題に遭遇しました (最初は Safari からホーム画面に追加しました)。これは、直接 Safari を使用している場合には発生しません。

私の調査によると、セッションを作成/再開し、次のようにセッション Cookie を追加することで、これを php で克服できることが示されています。

// Start or resume session
session_start(); 

// Extend cookie life time by an amount of your liking
$cookieLifetime = 365 * 24 * 60 * 60; // A year in seconds
setcookie(session_name(),session_id(),time()+$cookieLifetime);

プログラムでこれを行うのではなく、XML 構成を介してこれを行う方法があるかどうか疑問に思っていました。そうでなければ、どうすれば Spring Security で同様のことを達成できますか?

ここに私のsecurity-ctx.xmlがあります:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:sec="http://www.springframework.org/schema/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/security
          http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <bean id="http403EntryPoint" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint">
    </bean>

    <sec:http auto-config="false" entry-point-ref="http403EntryPoint">
        <sec:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
    </sec:http>

    <bean id="siteminderFilter" class=
            "org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
        <property name="principalRequestHeader" value="x-paas-uid"/>
        <property name="authenticationManager" ref="authenticationManager"/>
    </bean>

    <bean id="preauthAuthProvider"
          class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
        <property name="preAuthenticatedUserDetailsService">
            <bean id="userDetailsServiceWrapper"
                  class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
                <property name="userDetailsService" ref="ldapUserDetailsService"/>
            </bean>
        </property>
    </bean>

    <sec:authentication-manager alias="authenticationManager">
        <sec:authentication-provider ref="preauthAuthProvider"/>
    </sec:authentication-manager>

    <!-- Example using LDAP, but will ultimately use database service -->
    <sec:ldap-server id="ldapServer" port="636" root="o=home"
                          url="ldaps://ldap.home.com"/>


    <sec:ldap-user-service id="ldapUserDetailsService" server-ref="ldapServer"
                           group-search-base="ou=groups,o=home"
                           role-prefix="ROLE_" group-role-attribute="cn"
                           user-search-base="ou=people,o=home" user-search-filter="uid={0}"/>
</beans>
4

1 に答える 1

0

私の知る限り、Spring Security はセッション タイムアウト値を管理していません。そのため、すぐに使用できるセキュリティ xml でそれを行う方法はありません。この値をシステム全体 (すべてのセッションに対して) に定義する場合は、サーブレット コンテナー/アプリケーション サーバーのドキュメントを参照してください。Tomcat の場合、次のスニペットをweb.xml記述子に追加できます。

<web-app ....>

    .....
    <session-config>
        <!-- value is in minutes -->
        <!-- 60x24x365 -->
        <session-timeout>525600</session-timeout>
    </session-config>
    ....
</web-app>
于 2013-03-20T17:46:00.463 に答える