From 55f5093ec718a33a0e83b7c5bb75305062149127 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Mon, 7 Nov 2005 03:04:47 +0000 Subject: [PATCH] SEC-94: DaoAuthenticationProvider to include UserDetails in BadCredentialsException. --- .../BadCredentialsException.java | 23 ++++++++++++++++++- .../dao/DaoAuthenticationProvider.java | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/BadCredentialsException.java b/core/src/main/java/org/acegisecurity/BadCredentialsException.java index 22ff077fad..9c6603e0ed 100644 --- a/core/src/main/java/org/acegisecurity/BadCredentialsException.java +++ b/core/src/main/java/org/acegisecurity/BadCredentialsException.java @@ -1,4 +1,4 @@ -/* Copyright 2004 Acegi Technology Pty Limited +/* Copyright 2004, 2005 Acegi Technology Pty Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,10 @@ package net.sf.acegisecurity; * @version $Id$ */ public class BadCredentialsException extends AuthenticationException { + //~ Instance fields ======================================================== + + private Object extraInformation; + //~ Constructors =========================================================== /** @@ -36,6 +40,11 @@ public class BadCredentialsException extends AuthenticationException { super(msg); } + public BadCredentialsException(String msg, Object extraInformation) { + super(msg); + this.extraInformation = extraInformation; + } + /** * Constructs a BadCredentialsException with the specified * message and root cause. @@ -46,4 +55,16 @@ public class BadCredentialsException extends AuthenticationException { public BadCredentialsException(String msg, Throwable t) { super(msg, t); } + + //~ Methods ================================================================ + + /** + * Any additional information about the exception. Generally a + * UserDetails object. + * + * @return extra information or null + */ + public Object getExtraInformation() { + return extraInformation; + } } diff --git a/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java b/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java index 132d5b3885..13c01b67f9 100644 --- a/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java +++ b/core/src/main/java/org/acegisecurity/providers/dao/DaoAuthenticationProvider.java @@ -120,7 +120,7 @@ public class DaoAuthenticationProvider if (!passwordEncoder.isPasswordValid(userDetails.getPassword(), authentication.getCredentials().toString(), salt)) { - throw new BadCredentialsException("Bad credentials"); + throw new BadCredentialsException("Bad credentials", userDetails); } }