尝试在我的jsp应用程序中使用spring security时遇到问题

时间:2011-07-13 23:32:14

标签: spring jsp spring-security

在教程之后使用spring安全性似乎很容易,但是当我尝试使用这个应用程序时,我可以让它工作(我必须承认我还没写过)。

/ -----------------编辑------------------- / < / p>

现在在一些优秀人员的帮助下,我终于得到了要求用户验证自己的应用程序,但现在我遇到了一个新问题:当我尝试使用下面列出的一个用户访问该应用程序时( 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-security-2.0.4的spring 2.5(与我一直关注的教程中的版本相同)。

1 个答案:

答案 0 :(得分:0)

您是否尝试过该错误建议并为您的身份验证管理器添加了别名属性?类似的东西:

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