【问题标题】:Barebonds Hello World Example with Security具有安全性的 Barebonds Hello World 示例
【发布时间】:2012-07-24 08:27:54
【问题描述】:

我正在尝试设置一个带安全性的 Barebonds Hello World 示例。但我不断收到错误消息。

这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>MyFlow</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring/root-config.xml</param-value>
 </context-param>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

 <servlet>
  <servlet-name>spring</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value></param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>spring</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
    <filter-class>
        org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
</web-app>

这是我的 spring-security.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <security:http>
        <security:form-login />
        <security:http-basic />
        <security:logout />
        <security:intercept-url pattern="/**" access="ROLE_MEMBER" />
    </security:http>

    <security:user-service id="userService">
        <security:user name="habuma" password="letmein"
            authorities="ROLE_MEMBER,ROLE_ADMIN" />
        <security:user name="twoqubed" password="longhorns"
            authorities="ROLE_MEMEBER" />
        <security:user name="admin" password="admin"
            authorities="ROLE_ADMIN" />
    </security:user-service>
</beans>

以下是我的错误......请帮助我:

2012-07-25 15:54:46,607 [pool-2-thread-1] 错误 org.springframework.web.context.ContextLoader - 上下文初始化失败

org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.filterChains”的bean时出错:设置bean属性时无法解析对bean“org.springframework.security.web.DefaultSecurityFilterChain#0”的引用'sourceList' 键为 [0];嵌套异常是

org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.security.web.DefaultSecurityFilterChain#0' 的 bean 时出错:无法解析对 bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter# 的​​引用0' 同时使用键 [2] 设置构造函数参数;嵌套异常是

org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' 的 bean 时出错:无法解析对 bean 'org.springframework.security.authentication.ProviderManager# 的​​引用0' 同时设置 bean 属性 'authenticationManager';嵌套异常是

org.springframework.beans.factory.BeanCreationException:创建名为 'org.springframework.security.authentication.ProviderManager#0' 的 bean 时出错:无法解析对 bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean# 的引用0' 同时设置构造函数参数;嵌套异常是

org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0”的bean时出错:FactoryBean在创建对象时抛出异常;嵌套异常是

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.authenticationManager' is defined: 你忘了在你的配置中添加一个全局元素(带有子元素)吗?或者,您可以在 和 元素上使用 authentication-manager-ref 属性。

在 org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

【问题讨论】:

    标签: java spring spring-mvc spring-security spring-webflow-2


    【解决方案1】:

    我认为您错过了身份验证管理器声明 (see spring security docs)

        <security:authentication-manager>
        <security:authentication-provider
            user-service-ref="userService" />
        </security:authentication-manager>
    

    【讨论】:

      猜你喜欢
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-31
      • 1970-01-01
      • 2021-09-26
      相关资源
      最近更新 更多