From 489c94110111bf585eecd8db455a764a14d37c11 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Sun, 28 Mar 2004 12:14:11 +0000 Subject: [PATCH] Improved detection of invalid parameters in constructors. --- .../java/org/acegisecurity/userdetails/User.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/userdetails/User.java b/core/src/main/java/org/acegisecurity/userdetails/User.java index 67841758ab..e4a2bd8b6b 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/User.java +++ b/core/src/main/java/org/acegisecurity/userdetails/User.java @@ -46,17 +46,24 @@ public class User { * @param authorities the authorities that should be granted to the caller * if they presented the correct username and password and the user * is enabled + * + * @throws IllegalArgumentException if a null value was passed */ public User(String username, String password, boolean enabled, - GrantedAuthority[] authorities) { + GrantedAuthority[] authorities) throws IllegalArgumentException { + if ((username == null) || (password == null) || (authorities == null)) { + throw new IllegalArgumentException( + "Cannot pass null values to constructor"); + } + this.username = username; this.password = password; this.enabled = enabled; this.authorities = authorities; } - private User() { - super(); + protected User() { + throw new IllegalArgumentException("Cannot use default constructor"); } //~ Methods ================================================================