2009-08-14 14 views
17

Greetings!403 - 認証後にアクセスが拒否される

私の既存のデータベースに対して認証を試みると、認証されていますが、私は403ページを取得します。私がちょうど間違ったパスワードを試みた場合、私は期待通りに「間違った資格情報」メッセージを受け取ります。 私はSpringSecurityに含まれているサンプルアプリケーションごとに認証しようとしましたが、うまくいきました。

セキュリティの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"/> 

は、事前に 感謝:-)任意の助けに感謝します!

答えて

34

403コードを取得している場合は、ユーザーに必要な役割がないことを意味します。だから、認証は問題ではなく、認可です。
何が起きているのかを知る唯一の方法は、ログレベルをデバッグすることです。詳細情報が必要です。ここに投稿してください。
役割に「ROLE_」という接頭辞がありますか?

+0

良い点、骨頭のポストについて申し訳ありません、あまりにも疲れていて、まっすぐ思う気が散漫でした:-( – vector

+0

これは私のエラーの原因でした!ありがとうございました! –

2

...考え出しました。 DBの「権威」欄の設定ファイルと同じに指定さROLE_TESTを持つにもかかわらず、春-SECはROLE_SUPERVISORを期待していた。

 
[DEBUG,AbstractSecurityInterceptor,http-8084-7] Secure object: FilterInvocation: URL: /admin/test.jsp; ConfigAttributes: [ROLE_TEST] 
[DEBUG,AbstractSecurityInterceptor,http-8084-7] Previously Authenticated: org.springf[email protected]af840ed7: Principal: [email protected]: Username: testUser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_SUPERVISOR; Password: [PROTECTED]; Authenticated: true; Details: [email protected]: RemoteIpAddress: 127.0.0.1; SessionId: 350B260FAFDDBF04D5CB4AAAB7B8A441; Granted Authorities: ROLE_SUPERVISOR 
[DEBUG,ExceptionTranslationFilter,http-8084-7] Access is denied (user is not anonymous); delegating to AccessDeniedHandler 
org.springframework.security.AccessDeniedException: Access is denied 
     at org.springframework.security.vote.AffirmativeBased.decide(AffirmativeBased.java:68) 

...今私が来るか、興味が? configファイル内のROLE_TESTをROLE_SUPERVISORに変更した後、すべて期待通りに機能しました。

+2

....私は今日、間違ったデータベースで "と言いました。 タクシーは結構ですが、助けになりました! – vector

関連する問題