From 78ebb3f343e848adb40c5202d23c217eda8456f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Wed, 10 Aug 2011 18:32:29 +0200 Subject: [PATCH] Add logging category for authentication attempts Login attempts will be logged to navalplan-logins.log. FEA: ItEr75S04BugFixing --- ...uthenticationProviderLoggingDecorator.java | 69 +++++++++++++++++++ .../src/main/resources/log4j.xml | 22 +++++- ...lplanner-webapp-spring-security-config.xml | 12 ++-- 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 navalplanner-webapp/src/main/java/org/navalplanner/web/users/services/AuthenticationProviderLoggingDecorator.java diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/users/services/AuthenticationProviderLoggingDecorator.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/services/AuthenticationProviderLoggingDecorator.java new file mode 100644 index 000000000..015978306 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/users/services/AuthenticationProviderLoggingDecorator.java @@ -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 . + */ + +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); + } + +} diff --git a/navalplanner-webapp/src/main/resources/log4j.xml b/navalplanner-webapp/src/main/resources/log4j.xml index 7dc4628d6..5adfde35d 100644 --- a/navalplanner-webapp/src/main/resources/log4j.xml +++ b/navalplanner-webapp/src/main/resources/log4j.xml @@ -60,10 +60,30 @@ + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/navalplanner-webapp/src/main/resources/navalplanner-webapp-spring-security-config.xml b/navalplanner-webapp/src/main/resources/navalplanner-webapp-spring-security-config.xml index 59d45a062..c234d1699 100644 --- a/navalplanner-webapp/src/main/resources/navalplanner-webapp-spring-security-config.xml +++ b/navalplanner-webapp/src/main/resources/navalplanner-webapp-spring-security-config.xml @@ -68,7 +68,7 @@ - - - + + + + + - \ No newline at end of file +