2011-08-21 71 views
1

我已經使用正確運行的example projectdocumentation)創建了一個使用Eclipse在Tomcat 7上與Spring Security一起使用的簡單JSF登錄頁面。上面的例子存儲用戶名,密碼和角色的applicationContext-security.xml文件的格式如下:將Spring和JDBC集成到JSF2登錄頁面

<authentication-provider> 
    <password-encoder hash="md5" /> 
    <user-service> 
    <user name="rod" 
      password="a564de63c2d0da68cf47586ee05984d7" 
      authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" /> 
    <user name="peter" 
      password="22b5c9accc6e1ba628cedc63a72d57f8" 
      authorities="ROLE_USER" /> 
    </user-service> 
</authentication-provider> 

我想修改它,這樣我可以通過JDBC使用認證數據庫。在做了一個簡單的修改之後,由於錯誤(Eclipse不提供細節,或者我不知道在哪裏尋找),我無法再訪問服務器上的我的項目(404)。你能給我一些關於可能出錯的建議嗎?謝謝。

下面是我的applicationContext更新-security.xml文件的完整副本:

<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" 
     access-denied-page="/accessDenied.jsp"> 

     <intercept-url 
      pattern="/faces/protected**" 
      access="ROLE_SUPERVISOR,ROLE_USER,ROLE_TELLER" /> 
     <intercept-url 
      pattern="/**" 
      access="IS_AUTHENTICATED_ANONYMOUSLY" /> 

     <form-login 
      login-processing-url="/j_spring_security_check" 
      login-page="/faces/login.jsf" 
      default-target-url="/" 
      authentication-failure-url="/faces/login.jsf" /> 
     <logout 
      logout-url="/logout*" 
      logout-success-url="/" /> 

    </http> 

    <authentication-provider> 
     <jdbc-user-service data-source-ref="dataSource"/> 
    </authentication-provider> 

<beans:bean id="userDetailsService" class="org.springframework.security.userdetails.jdbc.JdbcDaoImpl"> 
    <beans:property name="dataSource" ref="dataSource"/> 
</beans:bean> 

<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
    <beans:property name="url" value="jdbc:mysql:///mysampledb"/> 
    <beans:property name="username" value="root"/> 
    <beans:property name="password" value="root"/> 
</beans:bean> 

</beans:beans> 

回答

1

的問題就解決了!我不得不刪除它:

<beans:bean id="userDetailsService" class="org.springframework.security.userdetails.jdbc.JdbcDaoImpl"> 
    <beans:property name="dataSource" ref="dataSource"/> 
</beans:bean> 

因爲它創建了多個userDetailsS​​ervice實例,導致了錯誤。

+0

<豆:豆ID = 「的UserDetailsS​​ervice」 類= 「org.springframework.security.userdetails.jdbc.JdbcDaoImpl」> <豆:屬性名= 「數據源」 REF = 「數據源」/> – Lyubomir

+0

請結帳消息編輯器頂部的按鈕和消息編輯器內右列的消息格式規則。 – BalusC