}
}
void authenticate(String to, Object credentials, String ipAddress)
{
Authenticator auth = getAuth();
if (credentials instanceof SignedCredentials) {
SignedCredentials signedCred = (SignedCredentials) credentials;
String uid = signedCred.getUid();
String nonce = signedCred.getNonce();
String signature = signedCred.getSignature();
/*
String savedNonce = _nonceMap.get(uid);
if (savedNonce == null)
throw new NotAuthorizedException(L.l("'{0}' has invalid credentials",
uid));
*/
String serverSignature;
if (uid != null && ! uid.equals("")) {
serverSignature = _security.signSystem(uid, nonce);
}
else if (_security.isSystemAuthKey() || ! _isAuthenticationRequired)
serverSignature = _security.signSystem(uid, nonce);
else {
log.info("Authentication failed because no resin-system-auth-key");
throw new NotAuthorizedException(L.l("'{0}' has invalid credentials",
uid));
}
if (! serverSignature.equals(signature)) {
throw new NotAuthorizedException(L.l("'{0}' has invalid credentials",
uid));
}
}
else if (auth == null && ! _isAuthenticationRequired) {
}
else if (auth == null) {
log.finer("Authentication failed because no authenticator configured");
throw new NotAuthorizedException(L.l("'{0}' has missing authenticator",
credentials));
}
else if (credentials instanceof DigestCredentials) {
DigestCredentials digestCred = (DigestCredentials) credentials;
Principal user = new BasicPrincipal(digestCred.getUserName());
user = auth.authenticate(user, digestCred, null);
if (user == null) {
throw new NotAuthorizedException(L.l("'{0}' has invalid digest credentials",
digestCred.getUserName()));
}
}
else if (credentials instanceof String) {
String password = (String) credentials;
Principal user = new BasicPrincipal(to);
PasswordCredentials pwdCred = new PasswordCredentials(password);
if (auth.authenticate(user, pwdCred, null) == null) {
throw new NotAuthorizedException(L.l("'{0}' has invalid password credentials",
to));
}
}
/*