1

私が欲しいのは、単純な記憶だけです。http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.htmlを読みました

私がこれまでに行ったこと:

  1. UserDetailsServiceHibernate / JPAで動作するように独自に作成しました。私の実装。覚えているものは考慮されません
  2. appContext による考慮された構成<security:remember-me key="89dqj219dn910lsAc12" user-service-ref="jpaUserDetailsService" token-validity-seconds="864000"/>
  3. CookieSPRING_SECURITY_REMEMBER_ME_COOKIEが実際に設定されていることを確認しました
  4. セキュリティで保護されたサイトにログインし、機能する
  5. ブラウザを再起動すると、エラーが発生し続けます。

    org.springframework.security.access.AccessDeniedException: アクセスが拒否されました文字列としての認証オブジェクト: org.springframework.security.authentication.RememberMeAuthenticationToken@9ab72a70: プリンシパル: de.myapp.businessobjects.AppUser@61f68b18: ユーザー名: myad; 守られたパスワード]; 有効: true; AccountNonExpired: 真; credentialsNonExpired: true; AccountNonLocked: 真; 個人情報: 65537; ; 資格情報: [保護]; 認証済み: true; 詳細: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; セッション ID: null; 付与された権限: ROLE_ADMIN、ROLE_USER

そして、ここに私のsecContext.xmlがあります:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="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/security
           http://www.springframework.org/schema/security/spring-security-3.0.xsd">

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

    <security:http use-expressions="true" access-denied-page="/accessDenied">
        <security:form-login
                login-page="/login"
                login-processing-url="/loginProcess"
                default-target-url="/intro"
                authentication-failure-url="/login?login_error=1"
                />
        <security:logout
                logout-url="/logout"
                logout-success-url="/logoutSuccess"/>

        <security:intercept-url pattern="/**" access="permitAll"/>
        <security:intercept-url pattern="/login" access="permitAll"/>
        <security:intercept-url pattern="/styles/**" access="permitAll"/>
        <security:intercept-url pattern="/scripts/**" access="permitAll"/>
        <security:remember-me key="89dqj219dn910lsAc12" user-service-ref="jpaUserDetailsService"
                              token-validity-seconds="864000"/>
    </security:http>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider user-service-ref="jpaUserDetailsService">
            <security:password-encoder hash="sha">
            </security:password-encoder>
        </security:authentication-provider>
    </security:authentication-manager>

    <bean id="rememberMeFilter" class=
            "org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
        <property name="rememberMeServices" ref="rememberMeServices"/>
        <property name="authenticationManager" ref="authenticationManager"/>
    </bean>

    <bean id="rememberMeServices" class=
            "org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
        <property name="userDetailsService" ref="jpaUserDetailsService"/>
        <property name="key" value="89dqj219dn910lsAc12"/>
    </bean>

    <bean id="rememberMeAuthenticationProvider" class=
            "org.springframework.security.authentication.RememberMeAuthenticationProvider">
        <property name="key" value="89dqj219dn910lsAc12"/>
    </bean>
</beans>

そして最後にいくつかのデバッグ トレース

03:45:14.598 [7225609@qtp-10131947-7] DEBUG o.s.w.b.a.s.HandlerMethodInvoker - Invoking request handler method: public java.lang.String de.myapp.controller.bstController.showbstpage(java.lang.String,javax.servlet.http.HttpServletResponse)
03:45:14.598 [7225609@qtp-10131947-7] DEBUG o.s.s.a.i.a.MethodSecurityInterceptor - Secure object: ReflectiveMethodInvocation: public java.lang.String de.myapp.controller.bstController.showbstpage(java.lang.String,javax.servlet.http.HttpServletResponse); target is of class [de.myapp.controller.bstController]; Attributes: [[authorize: 'isFullyAuthenticated() and #username == principal.username', filter: 'null', filterTarget: 'null']]
03:45:14.598 [7225609@qtp-10131947-7] DEBUG o.s.s.a.i.a.MethodSecurityInterceptor - Previously Authenticated: org.springframework.security.authentication.RememberMeAuthenticationToken@9ab72a70: Principal: de.myapp.businessobjects.AppUser@61f68b18: Username: myad; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; PersonalInformation: 65537; ; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Granted Authorities: ROLE_ADMIN, ROLE_USER
03:45:14.599 [7225609@qtp-10131947-7] DEBUG o.s.c.c.s.GenericConversionService - Converting value false of [TypeDescriptor java.lang.Boolean] to [TypeDescriptor java.lang.Boolean]
03:45:14.599 [7225609@qtp-10131947-7] TRACE o.s.c.c.s.GenericConversionService - Matched cached converter NO_OP
03:45:14.599 [7225609@qtp-10131947-7] DEBUG o.s.c.c.s.GenericConversionService - Converted to false
03:45:14.599 [7225609@qtp-10131947-7] DEBUG o.s.s.access.vote.AffirmativeBased - Voter: org.springframework.security.access.prepost.PreInvocationAuthorizationAdviceVoter@a866a9, returned: -1
03:45:14.599 [7225609@qtp-10131947-7] DEBUG o.s.s.access.vote.AffirmativeBased - Voter: org.springframework.security.access.vote.RoleVoter@1ebf305, returned: 0
03:45:14.599 [7225609@qtp-10131947-7] DEBUG o.s.s.access.vote.AffirmativeBased - Voter: org.springframework.security.access.vote.AuthenticatedVoter@19ffd6f, returned: 0

どこでデバッグを続けるべきか本当にわかりません。私は何を逃したのですか?remember-me の独自の実装を作成する必要がありますか?

springs remember-me のデフォルトの実装を示す実用的なサンプル アプリケーションを本当に感謝しています...

- - - - 編集 - - - - - -

springsecurity 自体によって、remember-me リファレンス アプリ (spring-security\samples\tutorialアカウント アプリと連絡先アプリ) をコンパイルして実行しました。実際、私はまったく同じ問題を抱えています?!?。私はfirefox、opera、そしてieを試しました...私は粉々になりました...

4

2 に答える 2

1

remember-me cookie から有効な認証トークンを取得しているため、remember-me 認証はアプリケーションで正常に機能していたようです。

bstController.showbstpageただし、ログ出力は、式から、「完全な」認証を必要とするコントローラー メソッドにメソッド アクセス制御アノテーションがあることを示していますisFullyAuthenticated() and #username == principal.username。Remember-me は完全な認証とは見なされないため、式は現在の認証を拒否します。

余談ですが、 が一番上にあり、すべてのリクエストに適用されるため、intercept-url要素の順序が間違っているため、/**他の要素が冗長になります。

また、サンプル アプリケーションでは、操作に完全な認証が必要ないため、同じ問題が発生することはありません。そのため、別の問題があったに違いありません。

于 2012-02-01T14:32:56.773 に答える
0

ログイン時に、UserDetails オブジェクトの「パスワード」フィールドが null 以外/空でない値に設定されていますか? 私のアプリケーションでは、実際の認証は別のシステムに委任されており、ユーザーが送信したパスワードを UserDetails オブジェクトに保存していません。password プロパティを値に設定するまで、RememberMe Cookie を機能させることができませんでした。私の場合、プロパティを「パスワード」という単語にデフォルト設定しただけで、null/空の文字列にならないようにしました。

それがあなたのシナリオに似ているかどうかはわかりませんが、理解するまで、これは私を夢中にさせました.

于 2011-02-06T21:42:52.233 に答える