java - Barebonds Hello World 安全示例

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

我正在尝试设置一个具有安全性的 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] ERROR org.springframework.web.context.ContextLoader - Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [2]; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.authenticationManager' is defined: Did you forget to add a gobal element to your configuration (with child elements)? Alternatively you can use the authentication-manager-ref attribute on your and elements.

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

最佳答案

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

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

关于java - Barebonds Hello World 安全示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11657660/

相关文章:

java - 组织.apache.catalina.LifecycleException : Failed to start component

java - 如何使用 ModelAndview 将模型(bean)值从 Controller 传递到 jsp 页面?

java - RxJava : Thread pool for network calls

java - 无法 Autowiring RestTemplate 进行单元测试

java - 专家! Spring Boot 在依赖项目中提到了错误的依赖版本

Spring Boot - 在 Hibernate 中使用 JPA 存储库

java - Spring安全代理问题

java - 我正在努力在远程服务器中发送电子邮件,但它在本地工作,在远程服务器中抛出 'AuthenticationFailedException'

java - Hibernate 选择查询

java - 如何为 android 创建 vector 可绘制对象?