123: public boolean login() throws LoginException { 124: if (iCallbackHandler == null) 125: throw new LoginException("error: no CallbackHandler available"); 126: 127: Callback[] cb = new Callback[2]; 128: cb[0] = new NameCallback("username: "); 129: cb[1] = new PasswordCallback("password: ",false); 130: 131: try { 132: iCallbackHandler.handle(cb); 133: iUserName = ((NameCallback)cb[0]).getName(); 134: 135: char[] tmpPassword = ((PasswordCallback)cb[1]).getPassword(); 136: if (tmpPassword == null) 137: tmpPassword = new char[0]; 138: iPassword = new char[tmpPassword.length]; 139: System.arraycopy(tmpPassword,0,iPassword,0,tmpPassword.length); 140: ((PasswordCallback)cb[1]).clearPassword(); 141: 142: } catch (IOException ioe) { 143: throw new LoginException(ioe.toString()); 144: } catch (UnsupportedCallbackException uce) { 145: throw new LoginException(uce.getCallback().toString()); 146: } 147: 148: printDebug(DEBUG_USERNAME); 149: printDebug(DEBUG_PASSWORD); 150: 151: if (verifyPassword()) { 152: printDebug(DEBUG_AUTH); 153: iAuthOk = true; 154: return true; 155: } else { 156: printDebug(DEBUG_NOAUTH); 157: clearState(); 158: throw new FailedLoginException(); 159: } 160: } 161: 162: ///////////////////////////////////////////////////////// 262: 263: private boolean verifyPassword() throws LoginException { 264: int rc = -1; 265: try { 266: String cmd; 267: if (iDebugNative) 268: cmd = NATIVE_CMD+" -d "+iUserName+" "+iPassword; 269: else 270: cmd = NATIVE_CMD+" "+iUserName+" "+iPassword; 271: Process pr = Runtime.getRuntime().exec(cmd); 272: cmd = null; 273: pr.waitFor(); 274: rc = pr.exitValue(); 275: if (rc == 0) { 276: // add UnixPrincipal 277: iPrincipals = new HashSet(); 278: iGroups = new HashSet(); 279: iPrimaryGroup = true; 280: UnixPrincipal up = new UnixPrincipal(iUserName); 281: iPrincipals.add(up); 282: 283: //add UnixNumericUserPrincipal/UnixNumericGroupPrincipal 284: InputStreamReader isr = new InputStreamReader(pr.getInputStream()); 285: BufferedReader input = new BufferedReader(isr); 286: while (true) { 287: String line = input.readLine(); 288: if (line == null) 289: break; 290: else 291: addPrincipal(line); 292: } 293: input.close(); 294: } 305: input.close(); 306: } 307: } catch (Exception e) { 308: throw new LoginException(e.toString()); 309: } 310: return rc == 0; 311: }