rename SingleEntityCredentialManager to SubjectCredentialManager

This commit is contained in:
Alexander Schwartz 2022-06-14 13:58:43 +02:00 committed by Hynek Mlnařík
parent 84d21f0230
commit cb0c881821
19 changed files with 64 additions and 72 deletions

View file

@ -24,7 +24,7 @@ import org.keycloak.credential.CredentialAuthentication;
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.federation.kerberos.impl.KerberosUsernamePasswordAuthenticator;
import org.keycloak.federation.kerberos.impl.SPNEGOAuthenticator;
import org.keycloak.models.CredentialValidationOutput;
@ -169,7 +169,7 @@ public class KerberosFederationProvider implements UserStorageProvider,
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
if (!(input instanceof UserCredentialModel)) return false;
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((LegacySingleUserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((LegacyUserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
return validPassword(user.getUsername(), input.getChallengeResponse());
} else {
return false; // invalid cred type

View file

@ -36,7 +36,7 @@ import org.keycloak.credential.CredentialAuthentication;
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.federation.kerberos.impl.KerberosUsernamePasswordAuthenticator;
import org.keycloak.federation.kerberos.impl.SPNEGOAuthenticator;
import org.keycloak.models.CredentialValidationOutput;
@ -715,7 +715,7 @@ public class LDAPStorageProvider implements UserStorageProvider,
@Override
public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) {
if (!(input instanceof UserCredentialModel)) return false;
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((LegacySingleUserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
if (input.getType().equals(PasswordCredentialModel.TYPE) && !((LegacyUserCredentialManager) user.credentialManager()).isConfiguredLocally(PasswordCredentialModel.TYPE)) {
return validPassword(realm, user, input.getChallengeResponse());
} else {
return false; // invalid cred type

View file

@ -19,7 +19,7 @@ package org.keycloak.models.cache.infinispan;
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import java.util.List;
import java.util.stream.Stream;
@ -27,12 +27,12 @@ import java.util.stream.Stream;
/**
* @author Alexander Schwartz
*/
public abstract class SingleEntityCredentialManagerCacheAdapter implements SingleEntityCredentialManager {
public abstract class SubjectCredentialManagerCacheAdapter implements SubjectCredentialManager {
private final SingleEntityCredentialManager singleEntityCredentialManager;
private final SubjectCredentialManager subjectCredentialManager;
protected SingleEntityCredentialManagerCacheAdapter(SingleEntityCredentialManager singleEntityCredentialManager) {
this.singleEntityCredentialManager = singleEntityCredentialManager;
protected SubjectCredentialManagerCacheAdapter(SubjectCredentialManager subjectCredentialManager) {
this.subjectCredentialManager = subjectCredentialManager;
}
public abstract void invalidateCacheForEntity();
@ -42,95 +42,95 @@ public abstract class SingleEntityCredentialManagerCacheAdapter implements Singl
// validating a password might still update its hashes, similar logic might apply to OTP logic
// instead of having each
invalidateCacheForEntity();
return singleEntityCredentialManager.isValid(inputs);
return subjectCredentialManager.isValid(inputs);
}
@Override
public boolean updateCredential(CredentialInput input) {
invalidateCacheForEntity();
return singleEntityCredentialManager.updateCredential(input);
return subjectCredentialManager.updateCredential(input);
}
@Override
public void updateStoredCredential(CredentialModel cred) {
invalidateCacheForEntity();
singleEntityCredentialManager.updateStoredCredential(cred);
subjectCredentialManager.updateStoredCredential(cred);
}
@Override
public CredentialModel createStoredCredential(CredentialModel cred) {
invalidateCacheForEntity();
return singleEntityCredentialManager.createStoredCredential(cred);
return subjectCredentialManager.createStoredCredential(cred);
}
@Override
public boolean removeStoredCredentialById(String id) {
invalidateCacheForEntity();
return singleEntityCredentialManager.removeStoredCredentialById(id);
return subjectCredentialManager.removeStoredCredentialById(id);
}
@Override
public CredentialModel getStoredCredentialById(String id) {
return singleEntityCredentialManager.getStoredCredentialById(id);
return subjectCredentialManager.getStoredCredentialById(id);
}
@Override
public Stream<CredentialModel> getStoredCredentialsStream() {
return singleEntityCredentialManager.getStoredCredentialsStream();
return subjectCredentialManager.getStoredCredentialsStream();
}
@Override
public Stream<CredentialModel> getStoredCredentialsByTypeStream(String type) {
return singleEntityCredentialManager.getStoredCredentialsByTypeStream(type);
return subjectCredentialManager.getStoredCredentialsByTypeStream(type);
}
@Override
public CredentialModel getStoredCredentialByNameAndType(String name, String type) {
return singleEntityCredentialManager.getStoredCredentialByNameAndType(name, type);
return subjectCredentialManager.getStoredCredentialByNameAndType(name, type);
}
@Override
public boolean moveStoredCredentialTo(String id, String newPreviousCredentialId) {
invalidateCacheForEntity();
return singleEntityCredentialManager.moveStoredCredentialTo(id, newPreviousCredentialId);
return subjectCredentialManager.moveStoredCredentialTo(id, newPreviousCredentialId);
}
@Override
public void updateCredentialLabel(String credentialId, String userLabel) {
invalidateCacheForEntity();
singleEntityCredentialManager.updateCredentialLabel(credentialId, userLabel);
subjectCredentialManager.updateCredentialLabel(credentialId, userLabel);
}
@Override
public void disableCredentialType(String credentialType) {
invalidateCacheForEntity();
singleEntityCredentialManager.disableCredentialType(credentialType);
subjectCredentialManager.disableCredentialType(credentialType);
}
@Override
public Stream<String> getDisableableCredentialTypesStream() {
return singleEntityCredentialManager.getDisableableCredentialTypesStream();
return subjectCredentialManager.getDisableableCredentialTypesStream();
}
@Override
public boolean isConfiguredFor(String type) {
return singleEntityCredentialManager.isConfiguredFor(type);
return subjectCredentialManager.isConfiguredFor(type);
}
@Override
public boolean isConfiguredLocally(String type) {
return singleEntityCredentialManager.isConfiguredLocally(type);
return subjectCredentialManager.isConfiguredLocally(type);
}
@Override
public Stream<String> getConfiguredUserStorageCredentialTypesStream() {
return singleEntityCredentialManager.getConfiguredUserStorageCredentialTypesStream();
return subjectCredentialManager.getConfiguredUserStorageCredentialTypesStream();
}
@Override
public CredentialModel createCredentialThroughProvider(CredentialModel model) {
invalidateCacheForEntity();
return singleEntityCredentialManager.createCredentialThroughProvider(model);
return subjectCredentialManager.createCredentialThroughProvider(model);
}
}

View file

@ -23,7 +23,7 @@ import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.models.cache.CachedUserModel;
import org.keycloak.models.cache.infinispan.entities.CachedUser;
@ -287,12 +287,12 @@ public class UserAdapter implements CachedUserModel.Streams {
}
@Override
public SingleEntityCredentialManager credentialManager() {
public SubjectCredentialManager credentialManager() {
if (updated == null) {
updated = modelSupplier.get();
if (updated == null) throw new IllegalStateException("Not found in database");
}
return new SingleEntityCredentialManagerCacheAdapter(updated.credentialManager()) {
return new SubjectCredentialManagerCacheAdapter(updated.credentialManager()) {
@Override
public CredentialModel getStoredCredentialById(String id) {
if (!userRegisteredForInvalidation) {

View file

@ -19,13 +19,13 @@ package org.keycloak.models.jpa;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.common.util.ObjectUtil;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.ClientModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.models.jpa.entities.UserAttributeEntity;
import org.keycloak.models.jpa.entities.UserEntity;
@ -518,8 +518,8 @@ public class UserAdapter implements UserModel.Streams, JpaModel<UserEntity> {
}
@Override
public SingleEntityCredentialManager credentialManager() {
return new LegacySingleUserCredentialManager(session, realm, this);
public SubjectCredentialManager credentialManager() {
return new LegacyUserCredentialManager(session, realm, this);
}

View file

@ -18,13 +18,13 @@ package org.keycloak.storage.adapter;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.common.util.Time;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.ClientModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserModelDefaultMethods;
import org.keycloak.models.utils.KeycloakModelUtils;
@ -257,8 +257,8 @@ public class InMemoryUserAdapter extends UserModelDefaultMethods.Streams {
}
@Override
public SingleEntityCredentialManager credentialManager() {
return new LegacySingleUserCredentialManager(session, realm, this);
public SubjectCredentialManager credentialManager() {
return new LegacyUserCredentialManager(session, realm, this);
}
@Override

View file

@ -20,7 +20,7 @@ package org.keycloak.credential;
import org.keycloak.common.util.reflections.Types;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.storage.AbstractStorageManager;
import org.keycloak.storage.DatastoreProvider;
@ -38,17 +38,15 @@ import java.util.stream.Stream;
/**
* Handling credentials for a given user for the legacy store.
*
* Its companion is the MapSingleUserCredentialManagerStrategy that doesn't contain storage related elements.
*
* @author Alexander Schwartz
*/
public class LegacySingleUserCredentialManager extends AbstractStorageManager<UserStorageProvider, UserStorageProviderModel> implements SingleEntityCredentialManager {
public class LegacyUserCredentialManager extends AbstractStorageManager<UserStorageProvider, UserStorageProviderModel> implements SubjectCredentialManager {
private final UserModel user;
private final KeycloakSession session;
private final RealmModel realm;
public LegacySingleUserCredentialManager(KeycloakSession session, RealmModel realm, UserModel user) {
public LegacyUserCredentialManager(KeycloakSession session, RealmModel realm, UserModel user) {
super(session, UserStorageProviderFactory.class, UserStorageProvider.class, UserStorageProviderModel::new, "user");
this.user = user;
this.session = session;

View file

@ -18,13 +18,13 @@ package org.keycloak.storage.adapter;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.component.ComponentModel;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.ClientModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserModelDefaultMethods;
import org.keycloak.models.utils.RoleUtils;
@ -404,8 +404,8 @@ public abstract class AbstractUserAdapterFederatedStorage extends UserModelDefau
}
@Override
public SingleEntityCredentialManager credentialManager() {
return new LegacySingleUserCredentialManager(session, realm, this);
public SubjectCredentialManager credentialManager() {
return new LegacyUserCredentialManager(session, realm, this);
}
@Override

View file

@ -27,7 +27,7 @@ import org.keycloak.credential.CredentialProviderFactory;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.models.map.user.MapUserCredentialEntity;
import org.keycloak.models.map.user.MapUserEntity;
@ -47,14 +47,14 @@ import java.util.stream.Stream;
*
* @author Alexander Schwartz
*/
public class MapSingleUserCredentialManager implements SingleEntityCredentialManager {
public class MapUserCredentialManager implements SubjectCredentialManager {
private final UserModel user;
private final KeycloakSession session;
private final RealmModel realm;
private final MapUserEntity entity;
public MapSingleUserCredentialManager(KeycloakSession session, RealmModel realm, UserModel user, MapUserEntity entity) {
public MapUserCredentialManager(KeycloakSession session, RealmModel realm, UserModel user, MapUserEntity entity) {
this.user = user;
this.session = session;
this.realm = realm;

View file

@ -41,13 +41,13 @@ import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RequiredActionProviderModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserConsentModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserModel.SearchableFields;
import org.keycloak.models.UserProvider;
import org.keycloak.models.map.common.TimeAdapter;
import org.keycloak.models.map.credential.MapSingleUserCredentialManager;
import org.keycloak.models.map.credential.MapUserCredentialManager;
import org.keycloak.models.map.storage.MapKeycloakTransactionWithAuth;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
import org.keycloak.models.map.storage.MapStorage;
@ -110,8 +110,8 @@ public class MapUserProvider implements UserProvider.Streams {
}
@Override
public SingleEntityCredentialManager credentialManager() {
return new MapSingleUserCredentialManager(session, realm, this, entity);
public SubjectCredentialManager credentialManager() {
return new MapUserCredentialManager(session, realm, this, entity);
}
};
}

View file

@ -17,7 +17,7 @@
package org.keycloak.credential;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.provider.Provider;
@ -47,7 +47,7 @@ public interface UserCredentialStore extends Provider {
CredentialModel getStoredCredentialById(RealmModel realm, UserModel user, String id);
/**
* @deprecated Use {@link SingleEntityCredentialManager#getStoredCredentialsStream()} instead.
* @deprecated Use {@link SubjectCredentialManager#getStoredCredentialsStream()} instead.
*/
@Deprecated
List<CredentialModel> getStoredCredentials(RealmModel realm, UserModel user);
@ -65,7 +65,7 @@ public interface UserCredentialStore extends Provider {
}
/**
* @deprecated Use {@link SingleEntityCredentialManager#getStoredCredentialsByTypeStream(String)}
* @deprecated Use {@link SubjectCredentialManager#getStoredCredentialsByTypeStream(String)}
* instead.
*/
@Deprecated

View file

@ -27,7 +27,7 @@ import java.util.stream.Stream;
/**
* Validates and manages the credentials of a known entity (for example, a user).
*/
public interface SingleEntityCredentialManager {
public interface SubjectCredentialManager {
/**
* Validate a list of credentials.

View file

@ -101,7 +101,7 @@ public interface UserCredentialManager extends UserCredentialStore {
* @param realm
* @param user
* @return
* @deprecated Use {@link UserModel#credentialManager()} and {@link SingleEntityCredentialManager#getDisableableCredentialTypesStream()} instead.
* @deprecated Use {@link UserModel#credentialManager()} and {@link SubjectCredentialManager#getDisableableCredentialTypesStream()} instead.
*/
@Deprecated
Set<String> getDisableableCredentialTypes(RealmModel realm, UserModel user);
@ -158,7 +158,7 @@ public interface UserCredentialManager extends UserCredentialStore {
* Return credential types, which are provided by the user storage where user is stored. Returned values can contain for example "password", "otp" etc.
* This will always return empty list for "local" users, which are not backed by any user storage
*
* @deprecated Use {@link UserModel#credentialManager()} and then call {@link SingleEntityCredentialManager#getConfiguredUserStorageCredentialTypesStream()}
* @deprecated Use {@link UserModel#credentialManager()} and then call {@link SubjectCredentialManager#getConfiguredUserStorageCredentialTypesStream()}
* instead.
*/
@Deprecated

View file

@ -301,7 +301,7 @@ public interface UserModel extends RoleMapperModel {
/**
* Instance of a user credential manager to validate and update the credentials of this user.
*/
SingleEntityCredentialManager credentialManager();
SubjectCredentialManager credentialManager();
enum RequiredAction {
VERIFY_EMAIL,

View file

@ -20,7 +20,7 @@ package org.keycloak.models.utils;
import org.keycloak.models.ClientModel;
import org.keycloak.models.GroupModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserModel;
import java.util.List;
@ -211,7 +211,7 @@ public class UserModelDelegate implements UserModel.Streams {
}
@Override
public SingleEntityCredentialManager credentialManager() {
public SubjectCredentialManager credentialManager() {
return delegate.credentialManager();
}

View file

@ -33,14 +33,12 @@ import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.CredentialModel;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.hash.PasswordHashProvider;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.OTPPolicy;
import org.keycloak.models.PasswordPolicy;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.cache.UserCache;

View file

@ -21,10 +21,8 @@ import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.CredentialModel;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.UserModel;
import org.keycloak.models.credential.PasswordCredentialModel;
import org.keycloak.storage.StorageId;

View file

@ -21,13 +21,11 @@ import org.keycloak.component.ComponentModel;
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputUpdater;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.LDAPConstants;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.credential.PasswordCredentialModel;

View file

@ -19,12 +19,12 @@ package org.keycloak.testsuite.federation;
import org.keycloak.component.ComponentModel;
import org.keycloak.credential.CredentialInput;
import org.keycloak.credential.CredentialInputValidator;
import org.keycloak.credential.LegacySingleUserCredentialManager;
import org.keycloak.credential.LegacyUserCredentialManager;
import org.keycloak.models.GroupModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
import org.keycloak.models.SingleEntityCredentialManager;
import org.keycloak.models.SubjectCredentialManager;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.credential.PasswordCredentialModel;
@ -143,8 +143,8 @@ public class UserPropertyFileStorage implements UserLookupProvider.Streams, User
}
@Override
public SingleEntityCredentialManager credentialManager() {
return new LegacySingleUserCredentialManager(session, realm, this);
public SubjectCredentialManager credentialManager() {
return new LegacyUserCredentialManager(session, realm, this);
}
};
}