}
}
private Object authenticate(ClientConnection connection, Credentials credentials, ClientPrincipal principal
, boolean firstConnection) throws IOException {
final SerializationService ss = getSerializationService();
AuthenticationRequest auth = new AuthenticationRequest(credentials, principal);
connection.init();
auth.setFirstConnection(firstConnection);
//contains remoteAddress and principal
SerializableCollection collectionWrapper;
try {
collectionWrapper = (SerializableCollection) sendAndReceive(auth, connection);
} catch (Exception e) {
throw new RetryableIOException(e);
}
final Iterator<Data> iter = collectionWrapper.iterator();
if (iter.hasNext()) {
final Data addressData = iter.next();
final Address address = ss.toObject(addressData);
connection.setRemoteEndpoint(address);
if (iter.hasNext()) {
final Data principalData = iter.next();
return ss.toObject(principalData);
}
}
throw new AuthenticationException();
}