From d10fdee93467fad9d2c05f092eff41e78e4ebfd0 Mon Sep 17 00:00:00 2001 From: Jyoti Wadhwani Date: Tue, 31 Jul 2018 10:10:52 -0700 Subject: [PATCH] address reviewer comments --- .../app/security/AuthenticationManager.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wherehows-frontend/app/security/AuthenticationManager.java b/wherehows-frontend/app/security/AuthenticationManager.java index c65f159bb8e..a410cc62384 100644 --- a/wherehows-frontend/app/security/AuthenticationManager.java +++ b/wherehows-frontend/app/security/AuthenticationManager.java @@ -24,20 +24,17 @@ import javax.security.auth.login.LoginException; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.Callback; +import com.google.common.base.Preconditions; + public class AuthenticationManager { public static void authenticateUser(String userName, String password) throws NamingException { - if (userName == null || userName.isEmpty() || password == null || password.isEmpty()) { - throw new IllegalArgumentException("Username and password can not be blank."); - } - LoginContext lc = null; - try { - lc = new LoginContext("WHZ-Authentication", new WHZCallbackHandler(userName, password)); - } catch (LoginException le) { - throw new AuthenticationException(le.toString()); - } - + Preconditions.checkNotNull(userName, "Username String cannot be null"); + Preconditions.checkNotNull(password, "Password String cannot be null"); + Preconditions.checkArgument(!userName.isEmpty(), "Username cannot be empty"); + Preconditions.checkArgument(!password.isEmpty(), "Password cannot be empty"); try { + LoginContext lc = new LoginContext("WHZ-Authentication", new WHZCallbackHandler(userName, password)); lc.login(); } catch (LoginException le) { throw new AuthenticationException(le.toString()); @@ -51,6 +48,8 @@ public class AuthenticationManager { this.username = username; this.password = password; } + + @Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException { NameCallback nc = null;