Add logging category for authentication attempts
Login attempts will be logged to navalplan-logins.log. FEA: ItEr75S04BugFixing
This commit is contained in:
parent
d17eb8c0fc
commit
78ebb3f343
3 changed files with 98 additions and 5 deletions
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2011 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.users.services;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationException;
|
||||
import org.springframework.security.providers.AuthenticationProvider;
|
||||
|
||||
public class AuthenticationProviderLoggingDecorator implements AuthenticationProvider {
|
||||
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(AuthenticationProviderLoggingDecorator.class);
|
||||
|
||||
private AuthenticationProvider decoratedProvider;
|
||||
|
||||
public AuthenticationProvider getDecoratedProvider() {
|
||||
return decoratedProvider;
|
||||
}
|
||||
|
||||
public void setDecoratedProvider(AuthenticationProvider decoratedProvider) {
|
||||
this.decoratedProvider = decoratedProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication)
|
||||
throws AuthenticationException {
|
||||
Object principal = authentication != null ? authentication
|
||||
.getPrincipal() : null;
|
||||
LOG.info("trying to authenticate " + principal);
|
||||
try {
|
||||
Authentication result = decoratedProvider
|
||||
.authenticate(authentication);
|
||||
if (result != null) {
|
||||
LOG.info("successful authentication for: " + principal
|
||||
+ " with provider: " + decoratedProvider);
|
||||
}
|
||||
return result;
|
||||
} catch (AuthenticationException e) {
|
||||
LOG.info("unsuccesful authentication of " + principal
|
||||
+ " with provider: " + decoratedProvider);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class authentication) {
|
||||
return decoratedProvider.supports(authentication);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -60,10 +60,30 @@
|
|||
<logger name="profiling" additivity="false">
|
||||
<level value="info" />
|
||||
<appender-ref ref="ASYNC-profiling" />
|
||||
</logger>
|
||||
|
||||
<appender name="logins" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="file" value="${navalplan-log-directory}navalplan-logins.log" />
|
||||
<param name="datePattern" value="'.'yyyy-MM-dd" /> <!-- Rollover each midnight -->
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p [%d{dd-MMMM HH:mm:ss}] [%t] %c %x - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNC-logins" class="org.apache.log4j.AsyncAppender">
|
||||
<param name="BufferSize" value="1000" />
|
||||
<appender-ref ref="logins" />
|
||||
</appender>
|
||||
|
||||
<logger name="org.navalplanner.web.users.services.AuthenticationProviderLoggingDecorator"
|
||||
additivity="true">
|
||||
<level value="info" />
|
||||
<appender-ref ref="ASYNC-logins" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<priority value="info" />
|
||||
<appender-ref ref="ASYNC" />
|
||||
</root>
|
||||
</log4j:configuration>
|
||||
</log4j:configuration>
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@
|
|||
<beans:bean id="saltSource"
|
||||
class="org.springframework.security.providers.dao.salt.ReflectionSaltSource"
|
||||
p:userPropertyToUse="username" />
|
||||
<!-- <beans:bean id="authenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"
|
||||
<!-- <beans:bean id="realAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"
|
||||
p:passwordEncoder-ref="passwordEncoder" p:saltSource-ref="saltSource" p:userDetailsService-ref="dbUserDetailsService">
|
||||
<custom-authentication-provider/> </beans:bean> -->
|
||||
<!-- Beans used by the NavalPlan Web application when users are registered
|
||||
|
|
@ -98,16 +98,20 @@
|
|||
when an LDAP is used. Also will allow authenticate users in database. The
|
||||
property strUserId must be set with the proper value. It represents the property
|
||||
of the user in LDAP which will be used to check the username. -->
|
||||
<beans:bean id="authenticationProvider"
|
||||
<beans:bean id="realAuthenticationProvider"
|
||||
class="org.navalplanner.web.users.services.LDAPCustomAuthenticationProvider"
|
||||
p:userDetailsService-ref="ldapUserDetailsService"
|
||||
p:ldapTemplate-ref="ldapTemplate"
|
||||
p:passwordEncoderService-ref="dbPasswordEncoderService">
|
||||
<custom-authentication-provider />
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="authenticationProvider" class="org.navalplanner.web.users.services.AuthenticationProviderLoggingDecorator">
|
||||
<beans:property name="decoratedProvider" ref="realAuthenticationProvider"></beans:property>
|
||||
<custom-authentication-provider/>
|
||||
</beans:bean>
|
||||
|
||||
<!-- This bean is used to implement UserDetailsService with LDAP authentication
|
||||
Provider. -->
|
||||
<beans:bean id="ldapUserDetailsService"
|
||||
class="org.navalplanner.web.users.services.LDAPUserDetailsService" />
|
||||
</beans:beans>
|
||||
</beans:beans>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue