Spring Security 3 日志记录不适用于 Eclipse 中的 GAE

Posted

技术标签:

【中文标题】Spring Security 3 日志记录不适用于 Eclipse 中的 GAE【英文标题】:Spring Security 3 logging not working on GAE in Eclipse 【发布时间】:2011-08-09 15:01:19 【问题描述】:

我正在使用带有 Spring MVC 3 + Spring Security 3 + GAE 的 Eclipse Helios (3.6.2)。问题是我无法从 Spring Security 中记录任何内容。没有错误,但根本没有日志记录。我读到,当访问被拒绝或用户无法自动记录时,Eclipse 控制台应该显示调试消息,而不是我的情况。这是配置:

war/WRB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>ABM Monotributistas</display-name>    

    <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>/WEB-INF/securityContext.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>
    <!-- Enable Spring Security debug logging -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- Bootstrap listener to start up Spring's root WebApplicationContext -->
    <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>      
    </listener>
    <!-- For concurrent session-control support -->
    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener> 
    <!-- MVC -->
    <servlet>   
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servletContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>  
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

src/log4j.properties

# A default log4j configuration for log4j users.
#
# To use this configuration, deploy it into your application's WEB-INF/classes
# directory.  You are also encouraged to edit it as you like.

# Configure the console as our one appender
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%dHH:mm:ss,SSS %-5p [%c] - %m%n

# tighten logging on the DataNucleus Categories
log4j.category.DataNucleus.JDO=WARN, A1
log4j.category.DataNucleus.Persistence=WARN, A1
log4j.category.DataNucleus.Cache=WARN, A1
log4j.category.DataNucleus.MetaData=WARN, A1
log4j.category.DataNucleus.General=WARN, A1
log4j.category.DataNucleus.Utility=WARN, A1
log4j.category.DataNucleus.Transaction=WARN, A1
log4j.category.DataNucleus.Datastore=WARN, A1
log4j.category.DataNucleus.ClassLoading=WARN, A1
log4j.category.DataNucleus.Plugin=WARN, A1
log4j.category.DataNucleus.ValueGeneration=WARN, A1
log4j.category.DataNucleus.Enhancer=WARN, A1
log4j.category.DataNucleus.SchemaTool=WARN, A1

#Spring security debug logging
log4j.logger.org.springframework.security = DEBUG, A1

war/WRB-INF/logging.properties

# A default java.util.logging configuration.
# (All App Engine logging is through java.util.logging by default).
#
# To use this configuration, copy it into your application's WEB-INF
# folder and add the following to your appengine-web.xml:
# 
# <system-properties>
#   <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
# </system-properties>
#

# Set the default logging level for all loggers to WARNING
.level = WARNING

【问题讨论】:

【参考方案1】:

在我的项目中,我有我的“applicationContext-security.xml”配置文件。 (我假设您必须能够正确设置 Spring Security)

我有以下代码,当登录成功或被拒绝时,它似乎会给我输出到控制台。

<!-- Automatically receives AuthenticationEvent messages -->
<b:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>

我希望这就是你所追求的。

【讨论】:

以上是关于Spring Security 3 日志记录不适用于 Eclipse 中的 GAE的主要内容,如果未能解决你的问题,请参考以下文章

如何为 Spring Security 启用日志记录?

如何为 Spring Security 启用日志记录?

在 Spring Security 过滤器链之前记录请求标头

基于Spring Boot+Security+Redis权限管理系统,权限控制采用RBAC

甚至没有调用自定义 Spring Security 身份验证提供程序?

弹簧安全返回 403,日志记录不起作用