log.log(Level.FINE, "login failed, no trust manager found");
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
NameCallback usernameCallback = new NameCallback("username");
PasswordCallback passwordCallback = new PasswordCallback("password", true);
try {
callbackHandler.handle(new Callback[]{usernameCallback, passwordCallback});
} catch (UnsupportedCallbackException ex) {
LoginException le = new LoginException("callback is not supported");
le.initCause(ex);
throw le;
} catch (IOException ex) {
LoginException le = new LoginException("io error in callback handler");
le.initCause(ex);
throw le;
}
String password = new String(passwordCallback.getPassword());
Properties props = new Properties();
try {
props.load(new ByteArrayInputStream(password.getBytes()));
} catch (IOException ex) {
// Can not happen we are reading from a byte array
log.log(Level.FINE, "login failed, loading password properties failed", ex);
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
String messageStr = props.getProperty("message");
if(messageStr == null || messageStr.length() == 0) {
log.log(Level.FINE, "login failed, message is empty");
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
String signatureStr = props.getProperty("signature");
if(signatureStr == null || signatureStr.length() == 0) {
log.log(Level.FINE, "login failed, signature is empty");
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
String algorithm = props.getProperty("algorithm");
if(algorithm == null || algorithm.length() == 0) {
log.log(Level.FINE, "login failed, algorithm is empty");
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
byte[] message = Base64.decode(messageStr);
if(message == null) {
log.log(Level.FINE, "login failed, message is not base 64 encoded");
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
byte[] signature = Base64.decode(signatureStr);
if(signature == null) {
log.log(Level.FINE, "login failed, signature is not base 64 encoded");
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;
}
if (trustManager.isValidMessage(usernameCallback.getName(), message, signature, algorithm)) {
log.log(Level.FINE, "login succeeded, message has a valid signature");
loginSucceeded = true;
username = usernameCallback.getName();
} else {
log.log(Level.FINE, "login failed, message has an invalid signature");
}
log.exiting("GECATrustManagerLoginModule", "login", Boolean.valueOf(loginSucceeded));
return loginSucceeded;