public boolean login() throws LoginException {
//perform callbacks
if (this.callbackHandler == null) {
throw new LoginException("Error: No callback handler installed to gather username and password.");
}
// create callbacks
NameCallback nameCallback = new NameCallback("User Name: ");
PasswordCallback passwordCallback = new PasswordCallback("Password: ",true);//turn on password echo(?)
RadiusCallback radiusCallback = new RadiusCallback();
Callback[] callbacks = new Callback[3];
callbacks[0] = nameCallback;
callbacks[1] = passwordCallback;
callbacks[2] = radiusCallback;
try {
// send callbacks to callback handler
this.callbackHandler.handle(callbacks);
} catch(IOException ioex) {
throw new LoginException(ioex.getMessage());
} catch(UnsupportedCallbackException uscbex) {
StringBuffer sb = new StringBuffer("Error: callback ");
sb.append(uscbex.getCallback().toString());
sb.append(" not supported.");
throw new LoginException(sb.toString());
}
this.userName = nameCallback.getName();
char[] userPassword = passwordCallback.getPassword();
if(userPassword == null){
//treat a null password as a zero length password
userPassword = new char[0];
}
//finally clear the password
passwordCallback.clearPassword();
//now authenticate
try{
this.radiusClient = new RadiusClient(radiusCallback.getHostName(),
radiusCallback.getAuthPort(),
radiusCallback.getAcctPort(),
radiusCallback.getSharedSecret(),
this.userName,
radiusCallback.getTimeout());
this.authenticate(userPassword, radiusCallback.getCallingStationID(), radiusCallback.getNumRetries() );
}catch(InvalidParameterException ivpex){
StringBuffer sb1 = new StringBuffer("Configuration of the RADIUS client is incorrect. ");
sb1.append(ivpex.getMessage());
throw new LoginException(sb1.toString());
}catch(SocketException sex){
StringBuffer sb2 = new StringBuffer("Configuration of the RADIUS client is incorrect. ");
sb2.append(sex.getMessage());
throw new LoginException(sb2.toString());
}catch(NoSuchAlgorithmException nsaex){
StringBuffer sb3 = new StringBuffer("Configuration of the RADIUS client is incorrect. ");
sb3.append(nsaex.getMessage());
throw new LoginException(sb3.toString());
}
//finally clear the password in memory
for(int i = 0; i < userPassword.length;i++){
userPassword[i] = ' ';
}
userPassword = null;
this.authenticationSucceeded = true;
//everything went well, return true
return true;
}
Authenticates this Subject against a RADIUS Server (phase 1). It uses
the callbacks to request a UserName and a Password, and possibly requests
a response to a challenge recieved from the RADIUS server. |