Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring安全性:SecurityContextHolder.getContext().getAuthentication()在Wicket页上返回null_Spring_Google App Engine_Spring Security_Wicket 1.5 - Fatal编程技术网

Spring安全性:SecurityContextHolder.getContext().getAuthentication()在Wicket页上返回null

Spring安全性:SecurityContextHolder.getContext().getAuthentication()在Wicket页上返回null,spring,google-app-engine,spring-security,wicket-1.5,Spring,Google App Engine,Spring Security,Wicket 1.5,我正在谷歌应用程序引擎上使用SpringMVC(用于REST)、SpringSecurity3和ApacheWicket(UI)。一切正常,只是我在登录后无法通过SecurityContextHolder在Wicket页面上获得身份验证 我用谷歌搜索过这个问题,但似乎没有一个对我有用。我怀疑这是我的web xml有问题。谁能帮忙吗。谢谢 我正在使用Google App Engine上的Spring Security教程 这是我的web.xml <?xml version="1.0" enc

我正在谷歌应用程序引擎上使用SpringMVC(用于REST)、SpringSecurity3和ApacheWicket(UI)。一切正常,只是我在登录后无法通过SecurityContextHolder在Wicket页面上获得身份验证

我用谷歌搜索过这个问题,但似乎没有一个对我有用。我怀疑这是我的web xml有问题。谁能帮忙吗。谢谢

我正在使用Google App Engine上的Spring Security教程

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>        
 <display-name>MTP Portal</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/mtp-web-servlet.xml, /WEB-INF/mtp-web-security-context.xml
    </param-value>
</context-param>

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

<servlet>
    <servlet-name>mtp-web</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>mtp-web</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>WicketApp</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
        <param-name>applicationFactoryClassName</param-name>
        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
    </init-param>
</filter>

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

MTP门户
上下文配置位置
/WEB-INF/mtp-WEB-servlet.xml,/WEB-INF/mtp-WEB-security-context.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener
mtp网站
org.springframework.web.servlet.DispatcherServlet
mtp网站
/原料药/*
威克塔普
org.apache.wicket.protocol.http.WicketFilter
applicationFactoryClassName
org.apache.wicket.spring.SpringWebApplicationFactory
威克塔普
/*

这是我的spring安全配置:

<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
     xmlns:b="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     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">

<global-method-security pre-post-annotations="enabled"/>

<http pattern="/images/**" security="none"/>
<http pattern="/css/**" security="none"/>
<http pattern="/js/**" security="none"/>
<http pattern="/api/**" security="none"/>
<http pattern="/favicon.ico" security="none"/>
<http pattern="/disabled" security="none"/>

<http use-expressions="true" entry-point-ref="gaeEntryPoint" auto-config="true">
    <intercept-url pattern="/" access="permitAll"/>
    <intercept-url pattern="/api/**" access="permitAll"/>
    <intercept-url pattern="/admin/logout" access="permitAll"/>
    <intercept-url pattern="/register" access="hasRole('NEW_USER')"/>
    <intercept-url pattern="/admin/**" access="hasRole('ADMIN')"/>
    <custom-filter position="PRE_AUTH_FILTER" ref="gaeFilter"/>
</http>

<b:bean id="gaeEntryPoint"
        class="com.peerbuccoss.apps.mtp.web.authentication.impl.GoogleAccountsAuthenticationEntryPoint"/>

<b:bean id="gaeFilter" class="com.peerbuccoss.apps.mtp.web.authentication.filter.GaeAuthenticationFilter">
    <b:property name="authenticationManager" ref="authenticationManager"/>
    <b:property name="failureHandler">
        <b:bean class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
            <b:property name="exceptionMappings">
                <b:map>
                    <b:entry key="org.springframework.security.authentication.DisabledException"
                             value="/disabled"/>
                </b:map>
            </b:property>
        </b:bean>
    </b:property>
</b:bean>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="gaeAuthenticationProvider"/>
</authentication-manager>

<b:bean id="gaeAuthenticationProvider"
        class="com.peerbuccoss.apps.mtp.web.authentication.provider.GoogleAccountsAuthenticationProvider"/>


我不确定哪个URL无法获取SecurityContext(也许您可以提供一个示例URL),但不会为映射到security=“none”的任何URL填充SecurityContext。这是因为security=“none”指示Spring security完全忽略此URL。如果您需要在允许每个用户访问的URL上访问SecurityContext,则需要使用permitAll


PS:如果这没有帮助,您可能会提供一个示例URL,说明您在获取身份验证时遇到了问题。您还可以详细说明“在Wicket页面上获取身份验证时遇到问题”(即,是否为null、引发异常等)的含义。

感谢您的回复。基本上,我正在尝试访问以下url的管理页面,该url将我重定向到谷歌登录页面。使用电子邮件帐户(@peerbuccos.com)成功登录后,如果找不到电子邮件,我将重定向到注册页面,提示用户输入个人信息以完成注册过程,否则应重定向到管理页面。登录已成功,但在注册页面上调用SecurityContextHolder.getContext().getAuthentication()时,我将获得null。我添加了一个新角色,因此我的页面将重定向到注册页面。这里您可以看到我引用的代码示例()。但它使用的是SpringMVC+安全性和GAE。对于SpringWicket,我有一些额外的过滤器。我有同样的问题,我的register.htm(jsp)给了我一个403错误。您是如何解决这个问题的,因为我的身份验证用户拥有权限={NEW_user}如果我将拦截url从更改为,我就能够从安全上下文中获取身份验证对象