20

ご挨拶!

既存のデータベースに対して認証しようとすると、認証されますが、403ページが表示されます。間違ったパスワードを試しただけでは、期待どおりに「間違った資格情報」というメッセージが表示されます。SpringSecurityに含まれているサンプルアプリごとに認証を試みましたが、問題なく機能しました。

security-context.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:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">

    <global-method-security secured-annotations="enabled"></global-method-security>

    <http auto-config="true" >
        <intercept-url pattern="/admin/**" access="ROLE_TEST" />
        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />

        <form-login
            login-page="/login/index.jsp"
            default-target-url="/admin/test.jsp"
            authentication-failure-url="/login/index.jsp?login_error=1" />  
    </http>

    <authentication-provider user-service-ref="jdbcUserService">      
        <password-encoder ref="passwordEncoder">
                <salt-source system-wide="n103df"/>
        </password-encoder>        
    </authentication-provider>


    <beans:bean id="jdbcUserService"  class="org.springframework.security.userdetails.jdbc.JdbcDaoImpl">
        <beans:property name="rolePrefix" value="" />
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="enableAuthorities" value="true"/>
        <beans:property name="enableGroups" value="false"/>
        <beans:property name="authoritiesByUsernameQuery" value="SELECT username,authority FROM authorities WHERE username = ?" />
        <beans:property name="usersByUsernameQuery" value="SELECT username,password,enabled as enabled FROM users WHERE username = ?" />
        <beans:property name="groupAuthoritiesByUsernameQuery" value="" />

    </beans:bean>

<beans:bean id="passwordEncoder" class="org.springframework.security.providers.encoding.Md5PasswordEncoder"/>

助けていただければ幸いです:-)よろしくお願いします!

4

2 に答える 2

41

403コードを取得している場合は、ユーザーに必要な役割がないことを意味します。ですから、承認は問題ではなく、承認です。
何が起こっているかを知る唯一の方法は、ログレベルをデバッグすることです。より多くの情報があるはずです。ここに投稿してください。
あなたの役割には「ROLE_」プレフィックスが付いていますか?

于 2009-08-15T18:52:09.203 に答える
2

... 理解した。構成ファイルでROLE_TESTが指定されていて、データベースの「権限」列でも同じであるにもかかわらず、Spring-SecはROLE_SUPERVISORを期待していました。

[DEBUG、AbstractSecurityInterceptor、http-8084-7]セキュアオブジェクト:FilterInvocation:URL:/admin/test.jsp; ConfigAttributes:[ROLE_TEST]
[DEBUG、AbstractSecurityInterceptor、http-8084-7]以前に認証されたもの:org.springframework.security.providers.UsernamePasswordAuthenticationToken @ af840ed7:プリンシパル:org.springframework.security.userdetails.User@3ec100:ユーザー名:testUser; 守られたパスワード]; 有効:true; AccountNonExpired:true; 資格情報NonExpired:true; AccountNonLocked:true; 付与された権限:ROLE_SUPERVISOR; 守られたパスワード]; 認証済み:true; 詳細:org.springframework.security.ui.WebAuthenticationDetails@1c07a:RemoteIpAddress:127.0.0.1; SessionId:350B260FAFDDBF04D5CB4AAAB7B8A441; 付与された権限:ROLE_SUPERVISOR
[DEBUG、ExceptionTranslationFilter、http-8084-7]アクセスが拒否されました(ユーザーは匿名ではありません)。AccessDeniedHandlerへの委任
org.springframework.security.AccessDeniedException:アクセスが拒否されました
        org.springframework.security.vote.AffirmativeBased.decide(AffirmativeBased.java:68)で

...今、私は興味があります、どうしてですか?したがって、構成ファイルでROLE_TESTをROLE_SUPERVISORに変更した後、すべてが期待どおりに機能しました。

于 2009-08-17T16:22:49.977 に答える