2011-07-13 23 views
1

這似乎很容易使用Spring Security下面的教程,但是當我嘗試做與此應用程序一樣,我可以得到它的工作(我必須承認,我的天堂」寫)。問題試圖使用Spring Security與我的jsp aplication

/-----------------編輯-------------------/

現在在一些偉大的人的幫助下,我終於得到了應用程序要求用戶進行身份驗證,但現在我遇到了一個新問題:當我嘗試使用下列用戶之一訪問應用程序時(applicationContext- security.xml文件),我得到這個消息:

enter image description here

這裏的web.xml代碼:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter>  
    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext-security.xml</param-value> 
    </context-param> 
    <welcome-file-list> 
     <welcome-file>redirect.jsp</welcome-file> 
    </welcome-file-list> 
    <error-page> 
     <error-code>403</error-code> 
     <location>/sinacceso.jsp</location> 
    </error-page> 
</web-app> 

context.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<Context antiJARLocking="true" path="/Test01"/> 

調度-servlet.xml中:

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans> 
    <!-- GENERALES --> 
    <bean id="viewResolver" 
      class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" 
        value="org.springframework.web.servlet.view.tiles2.TilesView" /> 
    </bean> 
    <bean id="tilesConfigurer" 
      class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
     <property name="definitions"> 
      <list> 
       <value>/WEB-INF/tiles.xml</value> 
      </list> 
     </property> 
    </bean> 

    <bean name="/index.htm" class="paginas.index"/> 
    <bean name="secure/villancicos.htm" class="paginas.villancicos"/> 
    <bean name="secure/administracion.htm" class="paginas.administracion"/> 
</beans> 

的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" 
      xmlns:p="http://www.springframework.org/schema/p" 
      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.1.xsd"> 

    <http> 
     <intercept-url pattern="/index.htm" filters="none" /> 
     <intercept-url pattern="/secure/administracion.htm" access="ROLE_SUPERVISOR" /> 
     <intercept-url pattern="/secure/**" access="ROLE_USER" /> 
     <form-login /> 
     <anonymous /> 
     <http-basic /> 
     <logout logout-success-url="/index.htm" /> 
    </http> 
    <authentication-manager alias="myAuthenticationManager"> 
     <authentication-provider> 
      <password-encoder hash="md5"/> 
      <user-service> 
       <user name="rod" password="a564de63c2d0da68cf47586ee05984d7" authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" /> 
       <user name="dianne" password="65d15fe9156f9c4bbffd98085992a44e" authorities="ROLE_USER,ROLE_TELLER" /> 
       <user name="scott" password="2b58af6dddbd072ed27ffc86725d7d3a" authorities="ROLE_USER" /> 
       <user name="peter" password="22b5c9accc6e1ba628cedc63a72d57f8" authorities="ROLE_USER" /> 
      </user-service> 
     </authentication-provider> 
    </authentication-manager> 
</beans:beans> 

此應用程序正在使用Spring 2.5的帶彈簧安全2.0.4(從我一直在關注本教程的版本相同)。

+0

看起來像您使用的版本3種模式:彈簧豆-3.0.xsd和彈簧安全3.0.xsd和 – Ritesh

+0

@ Ritesh-,哪些我應該使用? :(原因我已經嘗試過spring-beans-2.0.xsd和spring-security-2.0.1.xsd,但是我一直得到相同的錯誤:( – eddy

+0

那麼,如果你使用的是Spring 2.5,那麼它應該是spring -beans-2.5.xsd。spring-security-2.0.4.xsd應該和spring-security-2.0.4一起使用。還有,你是否看到任何日誌文件中的錯誤堆棧? – Ritesh

回答

0

你嘗試過什麼錯誤提示,並增加了一個別名屬性的認證管理器?喜歡的東西:

<authentication-manager alias="myAuthenticationManager"> 
    <authentication-provider> 
     ... 
+0

感謝。我做了什麼你建議和它的工作,我的意思是我沒有得到錯誤消息了,但我也不得不改變模式的版本(否則,我有更多的錯誤信息),所以現在我使用春豆 - ** 3.0 **。xsd和spring-security - ** 3.0 **。xsd,但即使在所有這些更改之後,我都無法使Spring安全工作,但它只是根本沒有做任何事情(我仍然可以在不登錄的情況下訪問這些頁面):( – eddy

+0

@eddy你如何訪問應用程序?你能給一個網頁的URL作爲例子嗎?如http://server/myApp/Layout/myPage.htm。 – Ritesh

+0

@ Ritesh- OK,你去那裏的http://本地主機:9090/TEST01/administracion.htm – eddy