与GAE的春季安全 [英] Spring security with GAE

查看:97
本文介绍了与GAE的春季安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 没有bean命名'springSecurityFilterChain'被定义为

我将此配置添加到了我的web.xml中:

 < 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>

而在应用上下文中:

 <! - 配置安全性 - > 
< security:http auto-config =true>
< security:intercept-url pattern =/ **access =ROLE_USER/>
< / security:http>

< security:authentication-manager alias =authenticationManager>
< security:authentication-provider>
< security:user-service>
< security:user name =jimipassword =jimiauthorities =ROLE_USER,ROLE_ADMIN/>
< security:user name =bobpassword =bobauthorities =ROLE_USER/>
< / security:user-service>
< / security:authentication-provider>
< / security:authentication-manager>

什么可能导致错误?

解决方案

即使您没有在web.xml中指定contextConfigLocation,上下文实现也会使用默认位置(使用XmlWebApplicationContext:/WEB-INF/applicationContext.xml\").



所以我认为你已经有一个applicationContext.xml,但没有在你的web.xml中指定,但是Spring能够为你加载它。但现在你在一个单独的文件中有一个额外的安全配置。所以你需要在你的web.xml文件中指定这个新文件applicationContext-security.xml的位置:



这将处理这两个文件:

 < context-param> 
< param-name> contextConfigLocation< / param-name>
< param-value> /WEB-INF/applicationContext*.xml< / param-value>
< / context-param>

或者您可以单独指定为逗号或空格分隔列表,如下所示:

 < context-param> 
< param-name> contextConfigLocation< / param-name>
< param-value> /WEB-INF/applicationContext.xml /WEB-INF/applicationContext-security.xml</param-value>
< / context-param>

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

文档:ContextLoader


I'm trying to implement Spring security for my GAE application however I'm getting this error:

No bean named 'springSecurityFilterChain' is defined

I added this configuration to my web.xml:

<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>  

And in the application Context:

<!-- Configure security -->
<security:http auto-config="true">
    <security:intercept-url pattern="/**" access="ROLE_USER" />
</security:http>

<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider>
        <security:user-service>
            <security:user name="jimi" password="jimi" authorities="ROLE_USER, ROLE_ADMIN" />
            <security:user name="bob" password="bob" authorities="ROLE_USER" />
        </security:user-service>
    </security:authentication-provider>  
</security:authentication-manager>

What could be causing the error?

解决方案

Even if you do not specify the contextConfigLocation in your web.xml, the context implementation uses the default location (with XmlWebApplicationContext: "/WEB-INF/applicationContext.xml").

So I think you already have one applicationContext.xml but did not specify in your web.xml, but Spring was able to load it for you. But now you have an additional security configuration in a separate file. So you need to specify the location of this new file applicationContext-security.xml like this in your web.xml:

This will take care of both the files:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

or you can specify individually as a comma or space separated list also like below:

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml /WEB-INF/applicationContext-security.xml</param-value>
</context-param>

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

Documentation: ContextLoader

这篇关于与GAE的春季安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆