@Override public final boolean validate(final CredentialsObject credentialsOnRecord) { Objects.requireNonNull(credentialsOnRecord); if (!getAuthId().equals(credentialsOnRecord.getAuthId())) { return false; } else if (!getType().equals(credentialsOnRecord.getType())) { return false; } else if (!credentialsOnRecord.isEnabled()) { return false; } else { return credentialsOnRecord.getCandidateSecrets().stream().anyMatch(candidateSecret -> matchesCredentials(candidateSecret)); } }
/** * Verifies that the credentials provided by a device during the authentication * process match the credentials on record for that device. * * @param deviceCredentials The credentials provided by the device. * @param credentialsOnRecord The credentials on record. * @return A future that is succeeded with the authenticated device if the * credentials have been validated successfully. Otherwise, the * future is failed with a {@link ServiceInvocationException}. */ private Future<Device> validateCredentials( final T deviceCredentials, final CredentialsObject credentialsOnRecord) { if (!deviceCredentials.getAuthId().equals(credentialsOnRecord.getAuthId())) { return Future.failedFuture(new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR)); } else if (!deviceCredentials.getType().equals(credentialsOnRecord.getType())) { return Future.failedFuture(new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR)); } else if (!credentialsOnRecord.isEnabled()) { return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_UNAUTHORIZED)); } else { return doValidateCredentials(deviceCredentials, credentialsOnRecord); } }