// Authenticate internal call from another Carbon component
if (password.equals(AuthenticationServiceDataHolder.getInstance().getAccessKey())) {
isAuthenticated = true;
} else { // External call
UserRealm userRealm = getUserRealm(username);
// Can not find the user realm
if (null == userRealm) {
throw new AccountNotFoundException("Invalid User : " + principal);
}
// Get username from tenant username
int domainNameSeparatorIndex = username.indexOf(DOMAIN_NAME_SEPARATOR);
if (-1 != domainNameSeparatorIndex) {
username = username.substring(0, domainNameSeparatorIndex);
}
// User not found in the UM
if (!userRealm.getUserStoreManager().isExistingUser(username)) {
throw new AccountNotFoundException("Invalid User : " + principal);
}
// Check if the user is authenticated
isAuthenticated = userRealm.getUserStoreManager().authenticate(username, password);
}
// Let the engine know if the user is authenticated or not
((PlainPasswordCallback)passwordCallback).setAuthenticated(isAuthenticated);
} catch (UserStoreException e) {