spring - GAE中使用Spring Security遇到的问题

标签 spring google-app-engine spring-security

我正在关注这篇文章以在我的 GAE 项目中实现 spring 安全性 http://blog.springsource.com/2010/08/02/spring-security-in-google-app-engine/

我无法让它工作,我配置为 protected URL 没有得到保护,应用程序没有将我重定向到谷歌登录页面。这是我的 web.xml 和 security-config.xml。请帮忙,因为我已经花了很多时间在这上面。我认为有一些我无法捕捉到的小问题。

web.xml

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

<!-- Enables Spring Security -->
<filter>
    <filter-name>authenticationFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<!-- Reads request input using UTF-8 encoding -->
<filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>authenticationFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

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

<servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

安全配置.xml

   <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.0.xsd
   http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<security:http pattern="/static/**" security="none" />
<security:http pattern="/favicon.ico" security="none" />

<security:http use-expressions="true" entry-point-ref="entryPoint"
    access-denied-page="/">
    <security:intercept-url pattern="/" access="isAuthenticated()" />
    <security:intercept-url pattern="/sample"
        access="isAuthenticated()" />
    <security:custom-filter position="PRE_AUTH_FILTER"
        ref="authenticationFilter" />
</security:http>

<bean id="entryPoint"
    class="com.generic.gae.security.GoogleAccountsAuthenticationEntryPoint" />

<bean id="authenticationFilter" class="com.generic.gae.security.GaeAuthenticationFilter">
    <property name="authenticationManager" ref="authenticationManager" />
</bean>

<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider
        ref="authenticationProvider" />
</security:authentication-manager>

<bean id="authenticationProvider"
    class="com.generic.gae.security.GoogleAccountsAuthenticationProvider" />

谢谢

最佳答案

authenticationFilter 在 security-config.xml 中定义的不是您在 web.xml 中使用的那个。默认情况下,Spring Security 为您提供名称为 springSecurityFilterChain 的过滤器 bean。所以你在 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>

参见第 2.2 节 Security Namespace Configuration

关于spring - GAE中使用Spring Security遇到的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4981625/

相关文章:

java - 在 Servlet Filter 内部调用容器的 session 对象,而不是 GemFire 的 session 对象

spring - 如何使用Spring RestTemplate执行设置http请求正文?

java - Appengine 之上的键值对

java - Spring Boot + Angular JS JBoss 部署

java - 如何在 Spring 中为计划进程验证系统用户身份?

java - Spring Security 身份验证被忽略

java - 你能@Autowired一个@MessageGateway到RestController中吗

java - 无法将应用引擎端点导入 Android Studio 中的 EndpointsAsyncClass

python - 在谷歌应用引擎上,为什么我的 'import' 语句在 Live 上失败,但在 Dev(localmachine) 上工作?

Grails:.save(flush:flush, insert:true) 与 .save(flush:true) 有何不同