-// ----------------------
- try {
-// Ask for username password
- Callback[] callbacks = new Callback[2];
- callbacks[0] = new NameCallback("username");
- callbacks[1] = new PasswordCallback("password", false);
-
- callbackHandler.handle(callbacks);
-
- String username = ((NameCallback)callbacks[0]).getName();
- String password = null;
- char[] entered = ((PasswordCallback)callbacks[1]).getPassword();
- if (entered != null) {
- password = new String(entered);
- ((PasswordCallback)callbacks[1]).clearPassword();
- }
-
-// Authentication
- User found = UserDirectory.selectUser(username, password);
- if (found != null) {
- identity = found;
- succeeded = true;
- Calendar today = java.util.Calendar.getInstance();
- Date datime = today.getTime();
- logger.info("RKV:Connection of " + identity.toString() + " " + datime.toString() + ".");
- return true;
- } else {
- identity = null;
- succeeded = false;
- found = UserDirectory.selectUser(username);
- String reason = "password";
- if (found == null) reason = "username";
- logger.info("Connection attempt as " + username + ".");
- throw new FailedLoginException(reason);
- }
- }
- catch (java.io.IOException ioe) {
- throw new LoginException(ioe.toString());
- }
- catch (UnsupportedCallbackException uce) {
- throw new LoginException("Error: " + uce.getCallback().toString() +
- " not available to garner authentication information" +
- " from the user");
- }
+ boolean res = false;
+ try {
+ // Ask for username password
+ Callback[] callbacks = new Callback[2];
+ callbacks[0] = new NameCallback("username");
+ callbacks[1] = new PasswordCallback("password", false);
+
+ _callbackHandler.handle(callbacks);
+
+ String username = ((NameCallback) callbacks[0]).getName();
+ String password = null;
+ char[] entered = ((PasswordCallback) callbacks[1]).getPassword();
+ if (entered != null) {
+ password = new String(entered);
+ ((PasswordCallback) callbacks[1]).clearPassword();
+ }
+
+ // Authentication
+ User found = ServiceLocatorImpl.getInstance().getUserService()
+ .selectUser(username, password);
+ _identity = found;
+ _succeeded = (found != null);
+ if (_succeeded) {
+ Calendar today = java.util.Calendar.getInstance();
+ Date datime = today.getTime();
+ LOG.info("Connection of " + _identity.toString() + " "
+ + datime.toString() + ".");
+ res = true;
+ } else {
+ found = ServiceLocatorImpl.getInstance().getUserService()
+ .selectUser(username);
+ String reason = "password";
+ if (found == null) {
+ reason = "username";
+ }
+ LOG.info("Connection attempt as " + username + ".");
+ throw new FailedLoginException(reason);
+ }
+ } catch (java.io.IOException ioe) {
+ throw new LoginException(ioe.getMessage()); // RKV: NOPMD: The message is sent into the constructor
+ } catch (UnsupportedCallbackException uce) {
+ throw new LoginException("Error: " // RKV: NOPMD: Stacktrace is printed
+ + uce.getCallback().toString()
+ + " not available to garner authentication information"
+ + " from the user");
+ }
+ return res;