diff --git a/model/build-processor/pom.xml b/model/build-processor/pom.xml index f27673ff39..496743c066 100644 --- a/model/build-processor/pom.xml +++ b/model/build-processor/pom.xml @@ -11,17 +11,10 @@ Keycloak Model Java Annotations and Processor - - - junit - junit - test - - - org.hamcrest - hamcrest - test - - + + 11 + 11 + 11 + \ No newline at end of file diff --git a/model/build-processor/src/main/java/org/keycloak/models/map/processor/AbstractGenerateEntityImplementationsProcessor.java b/model/build-processor/src/main/java/org/keycloak/models/map/processor/AbstractGenerateEntityImplementationsProcessor.java index 6a1e4eb755..4ece1811fa 100644 --- a/model/build-processor/src/main/java/org/keycloak/models/map/processor/AbstractGenerateEntityImplementationsProcessor.java +++ b/model/build-processor/src/main/java/org/keycloak/models/map/processor/AbstractGenerateEntityImplementationsProcessor.java @@ -32,6 +32,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import javax.tools.Diagnostic; import java.io.IOException; +import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; @@ -278,6 +279,10 @@ public abstract class AbstractGenerateEntityImplementationsProcessor extends Abs return res; } + protected void generatedAnnotation(final PrintWriter pw) { + pw.println("@javax.annotation.processing.Generated(\"" + getClass().getName() + "\")"); + } + protected static class NameFirstComparator implements Comparator { protected static final Comparator ID_INSTANCE = new NameFirstComparator("id").thenComparing(Comparator.naturalOrder()); protected static final Comparator GET_ID_INSTANCE = new NameFirstComparator("getId").thenComparing(Comparator.naturalOrder()); diff --git a/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java b/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java index c5f01036af..206fb21ad2 100644 --- a/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java +++ b/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateEntityImplementationsProcessor.java @@ -56,7 +56,7 @@ import javax.lang.model.type.TypeKind; * @author hmlnarik */ @SupportedAnnotationTypes("org.keycloak.models.map.annotations.GenerateEntityImplementations") -@SupportedSourceVersion(SourceVersion.RELEASE_8) +@SupportedSourceVersion(SourceVersion.RELEASE_11) public class GenerateEntityImplementationsProcessor extends AbstractGenerateEntityImplementationsProcessor { private static final Collection autogenerated = new TreeSet<>(); @@ -74,20 +74,24 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti protected void afterAnnotationProcessing() { if (! autogenerated.isEmpty()) { try { - JavaFileObject file = processingEnv.getFiler().createSourceFile("org.keycloak.models.map.common.AutogeneratedCloners"); + JavaFileObject file = processingEnv.getFiler().createSourceFile("org.keycloak.models.map.common.AutogeneratedClasses"); try (PrintWriter pw = new PrintWriterNoJavaLang(file.openWriter())) { pw.println("package org.keycloak.models.map.common;"); pw.println("import " + FQN_DEEP_CLONER + ".Cloner;"); pw.println("import " + FQN_DEEP_CLONER + ".DelegateCreator;"); + pw.println("import java.util.function.Function;"); pw.println("import " + FQN_DEEP_CLONER + ".EntityFieldDelegateCreator;"); pw.println("// DO NOT CHANGE THIS CLASS, IT IS GENERATED AUTOMATICALLY BY " + GenerateEntityImplementationsProcessor.class.getSimpleName()); - pw.println("public final class AutogeneratedCloners {"); + generatedAnnotation(pw); + pw.println("public final class AutogeneratedClasses {"); pw.println(" public static final java.util.Map, Cloner> CLONERS_WITH_ID = new java.util.HashMap<>();"); pw.println(" public static final java.util.Map, Cloner> CLONERS_WITHOUT_ID = new java.util.HashMap<>();"); pw.println(" public static final java.util.Map, DelegateCreator> DELEGATE_CREATORS = new java.util.HashMap<>();"); pw.println(" public static final java.util.Map, EntityFieldDelegateCreator> ENTITY_FIELD_DELEGATE_CREATORS = new java.util.HashMap<>();"); pw.println(" public static final java.util.Map, Object> EMPTY_INSTANCES = new java.util.HashMap<>();"); + pw.println(" public static final java.util.Map, EntityField[]> ENTITY_FIELDS = new java.util.HashMap<>();"); + pw.println(" public static final java.util.Map, Function> CONSTRUCTORS_DC = new java.util.HashMap<>();"); pw.println(" static {"); autogenerated.forEach(pw::println); pw.println(" }"); @@ -140,6 +144,7 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println("package " + packageName + ";"); } + generatedAnnotation(pw); pw.println("public enum " + mapSimpleFieldsClassName + " implements " + FQN_ENTITY_FIELD + "<" + className + "> {"); methodsPerAttribute.keySet().stream() .sorted(NameFirstComparator.ID_INSTANCE) @@ -149,6 +154,8 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println(" },"); }); pw.println("}"); + + autogenerated.add(" ENTITY_FIELDS.put(" + className + ".class, " + mapFieldsClassName + ".values());"); } } @@ -281,29 +288,13 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println("import java.util.Objects;"); pw.println("import " + FQN_DEEP_CLONER + ";"); pw.println("// DO NOT CHANGE THIS CLASS, IT IS GENERATED AUTOMATICALLY BY " + GenerateEntityImplementationsProcessor.class.getSimpleName()); + generatedAnnotation(pw); pw.println("public class " + mapSimpleClassName + (an.inherits().isEmpty() ? "" : " extends " + an.inherits()) + " implements " + className + " {"); - // Constructors - allParentMembers.stream() - .filter(ExecutableElement.class::isInstance) - .map(ExecutableElement.class::cast) - .filter((ExecutableElement ee) -> ee.getKind() == ElementKind.CONSTRUCTOR) - .forEach((ExecutableElement ee) -> { - // Create constructor and initialize cloner to DUMB_CLONER if necessary - if (usingGeneratedCloner) { - pw.println(" /**"); - pw.println(" * @deprecated This constructor uses a {@link DeepCloner#DUMB_CLONER} that does not clone anything. Use {@link #" + mapSimpleClassName + "(DeepCloner)} variant instead"); - pw.println(" */"); - } - pw.println(" " - + ee.getModifiers().stream().map(Object::toString).collect(Collectors.joining(" ")) - + " " + mapSimpleClassName + "(" + methodParameters(ee.getParameters()) + ") {" - ); - pw.println(" super(" + ee.getParameters() + ");"); - if (usingGeneratedCloner) pw.println(" this.cloner = DeepCloner.DUMB_CLONER;"); - pw.println(" }"); - }); - + pw.println(" " + + "private " + + mapSimpleClassName + "() { this(DeepCloner.DUMB_CLONER); } // Nullary constructor only for Jackson deserialization" + ); pw.println(" " + "public " + mapSimpleClassName + "(DeepCloner cloner) { super(); " + (!usingGeneratedCloner ? "" : "this.cloner = cloner;") + "}" @@ -409,6 +400,7 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println(" }"); autogenerated.add(" EMPTY_INSTANCES.put(" + className + ".class, " + mapImplClassName + ".Empty.INSTANCE);"); + autogenerated.add(" CONSTRUCTORS_DC.put(" + className + ".class, " + mapImplClassName + "::new);"); pw.println("}"); } @@ -527,6 +519,7 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println("package " + packageName + ";"); } + generatedAnnotation(pw); pw.println("public class " + mapSimpleClassName + (an.inherits().isEmpty() ? "" : " extends " + an.inherits()) + " implements " + className + ", " + FQN_HAS_ENTITY_FIELD_DELEGATE + "<" + className + ">" + " {"); pw.println(" private final " + FQN_ENTITY_FIELD_DELEGATE + "<" + className + "> entityFieldDelegate;"); pw.println(" public " + mapSimpleClassName + "(" + FQN_ENTITY_FIELD_DELEGATE + "<" + className + "> entityFieldDelegate) {"); @@ -642,11 +635,15 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti pw.println("package " + packageName + ";"); } - pw.println("public class " + mapSimpleClassName + " implements " + className + " {"); + generatedAnnotation(pw); + pw.println("public class " + mapSimpleClassName + " implements " + className + ", org.keycloak.models.map.common.delegate.HasDelegateProvider<" + className + "> {"); pw.println(" private final org.keycloak.models.map.common.delegate.DelegateProvider<" + className + "> delegateProvider;"); pw.println(" public " + mapSimpleClassName + "(org.keycloak.models.map.common.delegate.DelegateProvider<" + className + "> delegateProvider) {"); pw.println(" this.delegateProvider = delegateProvider;"); pw.println(" }"); + pw.println(" public org.keycloak.models.map.common.delegate.DelegateProvider<" + className + "> getDelegateProvider() {"); + pw.println(" return this.delegateProvider;"); + pw.println(" }"); getAllAbstractMethods(e) .forEach(ee -> { @@ -710,6 +707,7 @@ public class GenerateEntityImplementationsProcessor extends AbstractGenerateEnti } pw.println("import " + FQN_DEEP_CLONER + ";"); pw.println("// DO NOT CHANGE THIS CLASS, IT IS GENERATED AUTOMATICALLY BY " + GenerateEntityImplementationsProcessor.class.getSimpleName()); + generatedAnnotation(pw); pw.println("public class " + clonerSimpleClassName + " {"); if (methodsPerAttribute.containsKey(ID_FIELD_NAME)) { diff --git a/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateHotRodEntityImplementationsProcessor.java b/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateHotRodEntityImplementationsProcessor.java index bda50ab436..0a168636b4 100644 --- a/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateHotRodEntityImplementationsProcessor.java +++ b/model/build-processor/src/main/java/org/keycloak/models/map/processor/GenerateHotRodEntityImplementationsProcessor.java @@ -76,6 +76,7 @@ public class GenerateHotRodEntityImplementationsProcessor extends AbstractGenera pw.println("package org.keycloak.models.map.storage.hotRod.common;"); pw.println("// DO NOT CHANGE THIS CLASS, IT IS GENERATED AUTOMATICALLY BY " + GenerateHotRodEntityImplementationsProcessor.class.getSimpleName()); + generatedAnnotation(pw); pw.println("public final class AutogeneratedHotRodDescriptors {"); pw.println(" public static final java.util.Map, HotRodEntityDescriptor> ENTITY_DESCRIPTOR_MAP = new java.util.HashMap<>();"); pw.println(" static {"); @@ -156,6 +157,7 @@ public class GenerateHotRodEntityImplementationsProcessor extends AbstractGenera pw.println("import java.util.stream.Collectors;"); pw.println(); pw.println("// DO NOT CHANGE THIS CLASS, IT IS GENERATED AUTOMATICALLY BY " + GenerateHotRodEntityImplementationsProcessor.class.getSimpleName()); + generatedAnnotation(pw); pw.println("public class " + hotRodSimpleClassName + " extends " + parentClassElement.getQualifiedName().toString() + (parentClassHasGeneric ? "<" + e.getQualifiedName().toString() + ">" : "") @@ -624,6 +626,7 @@ public class GenerateHotRodEntityImplementationsProcessor extends AbstractGenera pw.println("import org.infinispan.protostream.GeneratedSchema;"); pw.println("import java.util.function.Function;"); + generatedAnnotation(pw); pw.println("public class " + descriptorSimpleClassName + " implements " + "org.keycloak.models.map.storage.hotRod.common.HotRodEntityDescriptor<" + className + ", " + className + "Delegate" + ">" diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionMetadata.java index da222c7c8d..3484863e73 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaAuthenticationSessionMetadata.java @@ -27,7 +27,7 @@ public class JpaAuthenticationSessionMetadata extends MapAuthenticationSessionEn } public JpaAuthenticationSessionMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaRootAuthenticationSessionMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaRootAuthenticationSessionMetadata.java index 4e0812d0d1..9c01e42649 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaRootAuthenticationSessionMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authSession/entity/JpaRootAuthenticationSessionMetadata.java @@ -27,7 +27,7 @@ public class JpaRootAuthenticationSessionMetadata extends MapRootAuthenticationS } public JpaRootAuthenticationSessionMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/permission/entity/JpaPermissionMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/permission/entity/JpaPermissionMetadata.java index d0e7c95cd6..c5358f2df1 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/permission/entity/JpaPermissionMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/permission/entity/JpaPermissionMetadata.java @@ -27,7 +27,7 @@ public class JpaPermissionMetadata extends MapPermissionTicketEntityImpl impleme } public JpaPermissionMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/policy/entity/JpaPolicyMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/policy/entity/JpaPolicyMetadata.java index 72fded50fa..f22b349430 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/policy/entity/JpaPolicyMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/policy/entity/JpaPolicyMetadata.java @@ -27,7 +27,7 @@ public class JpaPolicyMetadata extends MapPolicyEntityImpl implements Serializab } public JpaPolicyMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resource/entity/JpaResourceMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resource/entity/JpaResourceMetadata.java index 0bfb5805b2..24071e1961 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resource/entity/JpaResourceMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resource/entity/JpaResourceMetadata.java @@ -27,7 +27,7 @@ public class JpaResourceMetadata extends MapResourceEntityImpl implements Serial } public JpaResourceMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resourceServer/entity/JpaResourceServerMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resourceServer/entity/JpaResourceServerMetadata.java index 09e28e27cb..3b969c0cf3 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resourceServer/entity/JpaResourceServerMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/resourceServer/entity/JpaResourceServerMetadata.java @@ -27,7 +27,7 @@ public class JpaResourceServerMetadata extends MapResourceServerEntityImpl imple } public JpaResourceServerMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/scope/entity/JpaScopeMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/scope/entity/JpaScopeMetadata.java index ef6bcfc455..fbfdd976d5 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/scope/entity/JpaScopeMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/authorization/scope/entity/JpaScopeMetadata.java @@ -27,7 +27,7 @@ public class JpaScopeMetadata extends MapScopeEntityImpl implements Serializable } public JpaScopeMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientMetadata.java index e5d47e832a..07ac31dbda 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/client/entity/JpaClientMetadata.java @@ -27,7 +27,7 @@ public class JpaClientMetadata extends MapClientEntityImpl implements Serializab } public JpaClientMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientScope/entity/JpaClientScopeMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientScope/entity/JpaClientScopeMetadata.java index b8e1ccb584..2a07a55f49 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientScope/entity/JpaClientScopeMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/clientScope/entity/JpaClientScopeMetadata.java @@ -27,7 +27,7 @@ public class JpaClientScopeMetadata extends MapClientScopeEntityImpl implements } public JpaClientScopeMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/admin/entity/JpaAdminEventMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/admin/entity/JpaAdminEventMetadata.java index c8f64d69ef..8a5894eb64 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/admin/entity/JpaAdminEventMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/admin/entity/JpaAdminEventMetadata.java @@ -33,7 +33,7 @@ public class JpaAdminEventMetadata extends MapAdminEventEntityImpl implements Se } public JpaAdminEventMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/auth/entity/JpaAuthEventMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/auth/entity/JpaAuthEventMetadata.java index 7fbd7b742f..9054a8ad65 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/auth/entity/JpaAuthEventMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/event/auth/entity/JpaAuthEventMetadata.java @@ -33,7 +33,7 @@ public class JpaAuthEventMetadata extends MapAuthEventEntityImpl implements Seri } public JpaAuthEventMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/group/entity/JpaGroupMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/group/entity/JpaGroupMetadata.java index 311f49cdb6..baa8025b59 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/group/entity/JpaGroupMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/group/entity/JpaGroupMetadata.java @@ -27,7 +27,7 @@ public class JpaGroupMetadata extends MapGroupEntityImpl implements Serializable } public JpaGroupMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/loginFailure/entity/JpaUserLoginFailureMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/loginFailure/entity/JpaUserLoginFailureMetadata.java index 4c4abd618f..0aea5e2521 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/loginFailure/entity/JpaUserLoginFailureMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/loginFailure/entity/JpaUserLoginFailureMetadata.java @@ -33,7 +33,7 @@ public class JpaUserLoginFailureMetadata extends MapUserLoginFailureEntityImpl i } public JpaUserLoginFailureMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaComponentMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaComponentMetadata.java index af4b35bf5b..a314ff3961 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaComponentMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaComponentMetadata.java @@ -33,7 +33,7 @@ public class JpaComponentMetadata extends MapComponentEntityImpl implements Seri } public JpaComponentMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaRealmMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaRealmMetadata.java index 378636c9cc..3ec56f0394 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaRealmMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/realm/entity/JpaRealmMetadata.java @@ -29,7 +29,7 @@ import org.keycloak.models.map.realm.MapRealmEntityImpl; public class JpaRealmMetadata extends MapRealmEntityImpl implements Serializable { public JpaRealmMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } public JpaRealmMetadata(final DeepCloner cloner) { diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/role/entity/JpaRoleMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/role/entity/JpaRoleMetadata.java index a09b3252fd..69f06e8f97 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/role/entity/JpaRoleMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/role/entity/JpaRoleMetadata.java @@ -27,7 +27,7 @@ public class JpaRoleMetadata extends MapRoleEntityImpl implements Serializable { } public JpaRoleMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/singleUseObject/entity/JpaSingleUseObjectMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/singleUseObject/entity/JpaSingleUseObjectMetadata.java index ef15405ef3..405f06e585 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/singleUseObject/entity/JpaSingleUseObjectMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/singleUseObject/entity/JpaSingleUseObjectMetadata.java @@ -29,7 +29,7 @@ import org.keycloak.models.map.singleUseObject.MapSingleUseObjectEntityImpl; public class JpaSingleUseObjectMetadata extends MapSingleUseObjectEntityImpl implements Serializable { public JpaSingleUseObjectMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } public JpaSingleUseObjectMetadata(final DeepCloner cloner) { diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserConsentMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserConsentMetadata.java index 777212a324..f79f72607b 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserConsentMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserConsentMetadata.java @@ -29,7 +29,7 @@ import org.keycloak.models.map.user.MapUserConsentEntityImpl; public class JpaUserConsentMetadata extends MapUserConsentEntityImpl implements Serializable { public JpaUserConsentMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } public JpaUserConsentMetadata(final DeepCloner cloner) { diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserFederatedIdentityMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserFederatedIdentityMetadata.java index 551057761d..9ee907d089 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserFederatedIdentityMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserFederatedIdentityMetadata.java @@ -29,7 +29,7 @@ import org.keycloak.models.map.user.MapUserFederatedIdentityEntityImpl; public class JpaUserFederatedIdentityMetadata extends MapUserFederatedIdentityEntityImpl implements Serializable { public JpaUserFederatedIdentityMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } public JpaUserFederatedIdentityMetadata(final DeepCloner cloner) { diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserMetadata.java index 58744c7392..998a622a24 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/user/entity/JpaUserMetadata.java @@ -29,7 +29,7 @@ import org.keycloak.models.map.user.MapUserEntityImpl; public class JpaUserMetadata extends MapUserEntityImpl implements Serializable { public JpaUserMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } public JpaUserMetadata(final DeepCloner cloner) { diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaClientSessionMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaClientSessionMetadata.java index 472d5af704..4bcc03703f 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaClientSessionMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaClientSessionMetadata.java @@ -27,7 +27,7 @@ public class JpaClientSessionMetadata extends MapAuthenticatedClientSessionEntit } public JpaClientSessionMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaUserSessionMetadata.java b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaUserSessionMetadata.java index efe7b619f3..ab71041e95 100644 --- a/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaUserSessionMetadata.java +++ b/model/map-jpa/src/main/java/org/keycloak/models/map/storage/jpa/userSession/entity/JpaUserSessionMetadata.java @@ -27,7 +27,7 @@ public class JpaUserSessionMetadata extends MapUserSessionEntityImpl implements } public JpaUserSessionMetadata() { - super(); + super(DeepCloner.DUMB_CLONER); } private Integer entityVersion; diff --git a/model/map/pom.xml b/model/map/pom.xml index eb7bcb5687..acd1423077 100644 --- a/model/map/pom.xml +++ b/model/map/pom.xml @@ -11,11 +11,18 @@ Keycloak Model Map + + 11 + 11 + 11 + + org.apache.maven.plugins maven-compiler-plugin + 3.8.1-jboss-2 diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java index cfe665f870..e0ef2bd6bb 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java +++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java @@ -23,6 +23,7 @@ import org.keycloak.common.util.Time; import org.keycloak.models.ClientModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.TimeAdapter; import org.keycloak.models.utils.SessionExpiration; import org.keycloak.sessions.AuthenticationSessionModel; @@ -105,7 +106,7 @@ public class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticat } } - MapAuthenticationSessionEntity authSessionEntity = new MapAuthenticationSessionEntityImpl(); + MapAuthenticationSessionEntity authSessionEntity = DeepCloner.DUMB_CLONER.newInstance(MapAuthenticationSessionEntity.class); authSessionEntity.setClientUUID(client.getId()); long timestamp = Time.currentTimeMillis(); diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java index b76477e05a..2c51316778 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java @@ -17,12 +17,12 @@ package org.keycloak.models.map.authSession; import org.jboss.logging.Logger; -import org.keycloak.cluster.ClusterProvider; import org.keycloak.common.util.Time; import org.keycloak.models.ClientModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.TimeAdapter; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; @@ -96,7 +96,7 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi LOG.tracef("createRootAuthenticationSession(%s)%s", realm.getName(), getShortStackTrace()); // create map authentication session entity - MapRootAuthenticationSessionEntity entity = new MapRootAuthenticationSessionEntityImpl(); + MapRootAuthenticationSessionEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapRootAuthenticationSessionEntity.class); entity.setId(id); entity.setRealmId(realm.getId()); long timestamp = Time.currentTimeMillis(); diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java index ef7a85ad00..ca95690049 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java +++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java @@ -34,7 +34,7 @@ import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.map.authorization.adapter.MapPermissionTicketAdapter; import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity; -import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntityImpl; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -115,7 +115,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore { + ", Resource: " + resource + ", owner: " + owner + ", scopeId: " + scope + " already exists."); } - MapPermissionTicketEntity entity = new MapPermissionTicketEntityImpl(); + MapPermissionTicketEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapPermissionTicketEntity.class); entity.setResourceId(resource.getId()); entity.setRequester(requester); entity.setCreatedTimestamp(Time.currentTimeMillis()); diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java index 59022dd475..5376b590b0 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java +++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java @@ -30,7 +30,7 @@ import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.map.authorization.adapter.MapPolicyAdapter; import org.keycloak.models.map.authorization.entity.MapPolicyEntity; -import org.keycloak.models.map.authorization.entity.MapPolicyEntityImpl; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -89,7 +89,7 @@ public class MapPolicyStore implements PolicyStore { } String uid = representation.getId(); - MapPolicyEntity entity = new MapPolicyEntityImpl(); + MapPolicyEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapPolicyEntity.class); entity.setId(uid); entity.setType(representation.getType()); entity.setName(representation.getName()); diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java index ebe0e0de61..95c27e19ec 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java +++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java @@ -29,7 +29,7 @@ import org.keycloak.models.ModelException; import org.keycloak.models.RealmModel; import org.keycloak.models.map.authorization.adapter.MapResourceServerAdapter; import org.keycloak.models.map.authorization.entity.MapResourceServerEntity; -import org.keycloak.models.map.authorization.entity.MapResourceServerEntityImpl; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -76,7 +76,7 @@ public class MapResourceServerStore implements ResourceServerStore { throw new ModelDuplicateException("Resource server assiciated with client : " + client.getClientId() + " already exists."); } - MapResourceServerEntity entity = new MapResourceServerEntityImpl(); + MapResourceServerEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapResourceServerEntity.class); entity.setClientId(clientId); entity.setRealmId(client.getRealm().getId()); diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java index d5ed5d48ff..ab88535dca 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java +++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java @@ -29,7 +29,7 @@ import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.map.authorization.adapter.MapResourceAdapter; import org.keycloak.models.map.authorization.entity.MapResourceEntity; -import org.keycloak.models.map.authorization.entity.MapResourceEntityImpl; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -89,7 +89,7 @@ public class MapResourceStore implements ResourceStore { throw new ModelDuplicateException("Resource with name '" + name + "' for " + resourceServer.getId() + " already exists for request owner " + owner); } - MapResourceEntity entity = new MapResourceEntityImpl(); + MapResourceEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapResourceEntity.class); entity.setId(id); entity.setName(name); entity.setResourceServerId(resourceServer.getId()); diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java index a84e58da56..c1e7cc759d 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java +++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java @@ -28,7 +28,7 @@ import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.map.authorization.adapter.MapScopeAdapter; import org.keycloak.models.map.authorization.entity.MapScopeEntity; -import org.keycloak.models.map.authorization.entity.MapScopeEntityImpl; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -85,7 +85,7 @@ public class MapScopeStore implements ScopeStore { throw new ModelDuplicateException("Scope with name '" + name + "' for " + resourceServer.getId() + " already exists"); } - MapScopeEntity entity = new MapScopeEntityImpl(); + MapScopeEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapScopeEntity.class); entity.setId(id); entity.setName(name); entity.setResourceServerId(resourceServer.getId()); diff --git a/model/map/src/main/java/org/keycloak/models/map/client/MapClientProvider.java b/model/map/src/main/java/org/keycloak/models/map/client/MapClientProvider.java index 276d9f51f5..d3f24e5c7c 100644 --- a/model/map/src/main/java/org/keycloak/models/map/client/MapClientProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/client/MapClientProvider.java @@ -39,6 +39,7 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.TimeAdapter; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -154,7 +155,7 @@ public class MapClientProvider implements ClientProvider { throw new ModelDuplicateException("Client with same clientId in realm " + realm.getName() + " exists: " + clientId); } - MapClientEntity entity = new MapClientEntityImpl(); + MapClientEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapClientEntity.class); entity.setId(id); entity.setRealmId(realm.getId()); entity.setClientId(clientId); diff --git a/model/map/src/main/java/org/keycloak/models/map/client/MapProtocolMapperUtils.java b/model/map/src/main/java/org/keycloak/models/map/client/MapProtocolMapperUtils.java index 7af537bab1..03305c01bf 100644 --- a/model/map/src/main/java/org/keycloak/models/map/client/MapProtocolMapperUtils.java +++ b/model/map/src/main/java/org/keycloak/models/map/client/MapProtocolMapperUtils.java @@ -22,6 +22,7 @@ import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.keycloak.models.ProtocolMapperModel; +import org.keycloak.models.map.common.DeepCloner; public class MapProtocolMapperUtils { @@ -38,7 +39,7 @@ public class MapProtocolMapperUtils { } public static MapProtocolMapperEntity fromModel(ProtocolMapperModel model) { - MapProtocolMapperEntity res = new MapProtocolMapperEntityImpl(); + MapProtocolMapperEntity res = DeepCloner.DUMB_CLONER.newInstance(MapProtocolMapperEntity.class); res.setId(model.getId()); res.setName(model.getName()); res.setProtocolMapper(model.getProtocolMapper()); diff --git a/model/map/src/main/java/org/keycloak/models/map/clientscope/MapClientScopeProvider.java b/model/map/src/main/java/org/keycloak/models/map/clientscope/MapClientScopeProvider.java index c299837639..a3c3dd13ff 100644 --- a/model/map/src/main/java/org/keycloak/models/map/clientscope/MapClientScopeProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/clientscope/MapClientScopeProvider.java @@ -29,6 +29,7 @@ import org.keycloak.models.ClientScopeProvider; import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -93,7 +94,7 @@ public class MapClientScopeProvider implements ClientScopeProvider { LOG.tracef("addClientScope(%s, %s, %s)%s", realm, id, name, getShortStackTrace()); - MapClientScopeEntity entity = new MapClientScopeEntityImpl(); + MapClientScopeEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapClientScopeEntity.class); entity.setId(id); entity.setRealmId(realm.getId()); entity.setName(KeycloakModelUtils.convertClientScopeName(name)); diff --git a/model/map/src/main/java/org/keycloak/models/map/common/DeepCloner.java b/model/map/src/main/java/org/keycloak/models/map/common/DeepCloner.java index 6697c84627..5741918e1d 100644 --- a/model/map/src/main/java/org/keycloak/models/map/common/DeepCloner.java +++ b/model/map/src/main/java/org/keycloak/models/map/common/DeepCloner.java @@ -30,7 +30,6 @@ import java.util.Stack; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; -import java.util.function.Supplier; import org.jboss.logging.Logger; /** @@ -111,11 +110,11 @@ public class DeepCloner { * Builder for the {@code DeepCloner} helper class. */ public static class Builder { - private final Map, Function> constructors = new HashMap<>(); - private final Map, Cloner> clonersWithId = new HashMap<>(org.keycloak.models.map.common.AutogeneratedCloners.CLONERS_WITH_ID); - private final Map, Cloner> clonersWithoutId = new HashMap<>(org.keycloak.models.map.common.AutogeneratedCloners.CLONERS_WITHOUT_ID); - private final Map, DelegateCreator> delegateCreators = new HashMap<>(org.keycloak.models.map.common.AutogeneratedCloners.DELEGATE_CREATORS); - private final Map, EntityFieldDelegateCreator> entityFieldDelegateCreators = new HashMap<>(org.keycloak.models.map.common.AutogeneratedCloners.ENTITY_FIELD_DELEGATE_CREATORS); + private final Map, Function> constructors = new HashMap<>(org.keycloak.models.map.common.AutogeneratedClasses.CONSTRUCTORS_DC); + private final Map, Cloner> clonersWithId = new HashMap<>(org.keycloak.models.map.common.AutogeneratedClasses.CLONERS_WITH_ID); + private final Map, Cloner> clonersWithoutId = new HashMap<>(org.keycloak.models.map.common.AutogeneratedClasses.CLONERS_WITHOUT_ID); + private final Map, DelegateCreator> delegateCreators = new HashMap<>(org.keycloak.models.map.common.AutogeneratedClasses.DELEGATE_CREATORS); + private final Map, EntityFieldDelegateCreator> entityFieldDelegateCreators = new HashMap<>(org.keycloak.models.map.common.AutogeneratedClasses.ENTITY_FIELD_DELEGATE_CREATORS); private Cloner genericCloner = (from, to) -> { throw new IllegalStateException("Cloner not found for class " + (from == null ? "" : from.getClass())); }; /** @@ -256,7 +255,7 @@ public class DeepCloner { private final Map, DelegateCreator> delegateCreators; private final Map, EntityFieldDelegateCreator> entityFieldDelegateCreators; private final Cloner genericCloner; - private final Map, Object> emptyInstances = new HashMap<>(AutogeneratedCloners.EMPTY_INSTANCES); + private final Map, Object> emptyInstances = new HashMap<>(AutogeneratedClasses.EMPTY_INSTANCES); private DeepCloner(Map, Function> constructors, Map, DelegateCreator> delegateCreators, @@ -319,7 +318,7 @@ public class DeepCloner { } @SuppressWarnings("unchecked") - public V entityFieldDelegate(V delegate, EntityFieldDelegate delegateProvider) { + public V entityFieldDelegate(V delegate, EntityFieldDelegate delegateProvider) { return entityFieldDelegate((Class) delegate.getClass(), delegateProvider); } @@ -358,8 +357,8 @@ public class DeepCloner { Function c = (Function) getFromClassRespectingHierarchy(this.constructors, clazz); if (c == null) { try { - res = clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException ex) { + res = clazz.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException ex) { res = null; } } else { diff --git a/model/map/src/main/java/org/keycloak/models/map/common/delegate/HasDelegateProvider.java b/model/map/src/main/java/org/keycloak/models/map/common/delegate/HasDelegateProvider.java new file mode 100644 index 0000000000..fdce342189 --- /dev/null +++ b/model/map/src/main/java/org/keycloak/models/map/common/delegate/HasDelegateProvider.java @@ -0,0 +1,21 @@ +/* + * Copyright 2022 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.keycloak.models.map.common.delegate; + +public interface HasDelegateProvider { + DelegateProvider getDelegateProvider(); +} diff --git a/model/map/src/main/java/org/keycloak/models/map/events/EventUtils.java b/model/map/src/main/java/org/keycloak/models/map/events/EventUtils.java index e5fa0334a8..5128550486 100644 --- a/model/map/src/main/java/org/keycloak/models/map/events/EventUtils.java +++ b/model/map/src/main/java/org/keycloak/models/map/events/EventUtils.java @@ -21,6 +21,7 @@ import org.keycloak.events.Event; import org.keycloak.events.admin.AdminEvent; import org.keycloak.events.admin.AuthDetails; +import org.keycloak.models.map.common.DeepCloner; import java.util.Collections; import java.util.Map; @@ -62,7 +63,7 @@ public class EventUtils { } public static MapAdminEventEntity modelToEntity(AdminEvent adminEvent, boolean includeRepresentation) { - MapAdminEventEntity mapAdminEvent = new MapAdminEventEntityImpl(); + MapAdminEventEntity mapAdminEvent = DeepCloner.DUMB_CLONER.newInstance(MapAdminEventEntity.class); mapAdminEvent.setId(adminEvent.getId()); mapAdminEvent.setTimestamp(adminEvent.getTime()); mapAdminEvent.setRealmId(adminEvent.getRealmId()); @@ -79,7 +80,7 @@ public class EventUtils { } public static MapAuthEventEntity modelToEntity(Event event) { - MapAuthEventEntity eventEntity = new MapAuthEventEntityImpl(); + MapAuthEventEntity eventEntity = DeepCloner.DUMB_CLONER.newInstance(MapAuthEventEntity.class); eventEntity.setId(event.getId()); eventEntity.setTimestamp(event.getTime()); eventEntity.setType(event.getType()); diff --git a/model/map/src/main/java/org/keycloak/models/map/group/MapGroupProvider.java b/model/map/src/main/java/org/keycloak/models/map/group/MapGroupProvider.java index 6a047b9dcc..a48534da9e 100644 --- a/model/map/src/main/java/org/keycloak/models/map/group/MapGroupProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/group/MapGroupProvider.java @@ -26,6 +26,7 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; import org.keycloak.models.RoleModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; @@ -221,7 +222,7 @@ public class MapGroupProvider implements GroupProvider { throw new ModelDuplicateException("Group with name '" + name + "' in realm " + realm.getName() + " already exists for requested parent" ); } - MapGroupEntity entity = new MapGroupEntityImpl(); + MapGroupEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapGroupEntity.class); entity.setId(id); entity.setRealmId(realm.getId()); entity.setName(name); diff --git a/model/map/src/main/java/org/keycloak/models/map/loginFailure/MapUserLoginFailureProvider.java b/model/map/src/main/java/org/keycloak/models/map/loginFailure/MapUserLoginFailureProvider.java index 9faabbb966..ea02d676ac 100644 --- a/model/map/src/main/java/org/keycloak/models/map/loginFailure/MapUserLoginFailureProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/loginFailure/MapUserLoginFailureProvider.java @@ -21,6 +21,7 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.UserLoginFailureProvider; import org.keycloak.models.RealmModel; import org.keycloak.models.UserLoginFailureModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; @@ -78,7 +79,7 @@ public class MapUserLoginFailureProvider implements UserLoginFailureProvider { MapUserLoginFailureEntity userLoginFailureEntity = userLoginFailureTx.read(withCriteria(mcb)).findFirst().orElse(null); if (userLoginFailureEntity == null) { - userLoginFailureEntity = new MapUserLoginFailureEntityImpl(); + userLoginFailureEntity = DeepCloner.DUMB_CLONER.newInstance(MapUserLoginFailureEntity.class); userLoginFailureEntity.setRealmId(realm.getId()); userLoginFailureEntity.setUserId(userId); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmProvider.java b/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmProvider.java index c98f95f21a..877bd311e4 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/MapRealmProvider.java @@ -31,6 +31,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel.SearchableFields; import org.keycloak.models.RealmProvider; import org.keycloak.models.RoleModel; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; @@ -77,7 +78,7 @@ public class MapRealmProvider implements RealmProvider { LOG.tracef("createRealm(%s, %s)%s", id, name, getShortStackTrace()); - MapRealmEntity entity = new MapRealmEntityImpl(); + MapRealmEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapRealmEntity.class); entity.setId(id); entity.setName(name); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationExecutionEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationExecutionEntity.java index 9603c6c83f..1aafc7eea6 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationExecutionEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationExecutionEntity.java @@ -29,7 +29,7 @@ import org.keycloak.models.utils.KeycloakModelUtils; public interface MapAuthenticationExecutionEntity extends UpdatableEntity, AbstractEntity { static MapAuthenticationExecutionEntity fromModel(AuthenticationExecutionModel model) { if (model == null) return null; - MapAuthenticationExecutionEntity entity = new MapAuthenticationExecutionEntityImpl(); + MapAuthenticationExecutionEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapAuthenticationExecutionEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); entity.setId(id); entity.setAuthenticator(model.getAuthenticator()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationFlowEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationFlowEntity.java index 68b5519960..4b106c2c67 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationFlowEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticationFlowEntity.java @@ -28,7 +28,7 @@ import org.keycloak.models.utils.KeycloakModelUtils; @DeepCloner.Root public interface MapAuthenticationFlowEntity extends UpdatableEntity, AbstractEntity { static MapAuthenticationFlowEntity fromModel(AuthenticationFlowModel model) { - MapAuthenticationFlowEntity entity = new MapAuthenticationFlowEntityImpl(); + MapAuthenticationFlowEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapAuthenticationFlowEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); entity.setId(id); entity.setAlias(model.getAlias()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticatorConfigEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticatorConfigEntity.java index 7c351a63c1..bd606cad93 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticatorConfigEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapAuthenticatorConfigEntity.java @@ -32,7 +32,7 @@ import java.util.Map; public interface MapAuthenticatorConfigEntity extends UpdatableEntity, AbstractEntity { static MapAuthenticatorConfigEntity fromModel(AuthenticatorConfigModel model) { if (model == null) return null; - MapAuthenticatorConfigEntity entity = new MapAuthenticatorConfigEntityImpl(); + MapAuthenticatorConfigEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapAuthenticatorConfigEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); entity.setId(id); entity.setAlias(model.getAlias()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapClientInitialAccessEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapClientInitialAccessEntity.java index e05ea41e36..4dc733f0a1 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapClientInitialAccessEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapClientInitialAccessEntity.java @@ -33,7 +33,7 @@ public interface MapClientInitialAccessEntity extends UpdatableEntity, AbstractE static MapClientInitialAccessEntity createEntity(int expiration, int count) { long currentTime = Time.currentTimeMillis(); - MapClientInitialAccessEntity entity = new MapClientInitialAccessEntityImpl(); + MapClientInitialAccessEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapClientInitialAccessEntity.class); entity.setId(KeycloakModelUtils.generateId()); entity.setTimestamp(currentTime); entity.setExpiration(expiration == 0 ? null : currentTime + TimeAdapter.fromSecondsToMilliseconds(expiration)); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapComponentEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapComponentEntity.java index a20b2b53b6..8feb5d98fd 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapComponentEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapComponentEntity.java @@ -32,7 +32,7 @@ import java.util.Map; @DeepCloner.Root public interface MapComponentEntity extends UpdatableEntity, AbstractEntity { static MapComponentEntity fromModel(ComponentModel model) { - MapComponentEntity entity = new MapComponentEntityImpl(); + MapComponentEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapComponentEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); entity.setId(id); entity.setName(model.getName()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderEntity.java index befcc8a2d6..e4fd62b657 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderEntity.java @@ -32,7 +32,7 @@ import java.util.Map; public interface MapIdentityProviderEntity extends UpdatableEntity, AbstractEntity { static MapIdentityProviderEntity fromModel(IdentityProviderModel model) { if (model == null) return null; - MapIdentityProviderEntity entity = new MapIdentityProviderEntityImpl(); + MapIdentityProviderEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapIdentityProviderEntity.class); String id = model.getInternalId() == null ? KeycloakModelUtils.generateId() : model.getInternalId(); entity.setId(id); entity.setAlias(model.getAlias()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderMapperEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderMapperEntity.java index 61997c36f3..ece2b94f52 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderMapperEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapIdentityProviderMapperEntity.java @@ -32,7 +32,7 @@ import java.util.Map; public interface MapIdentityProviderMapperEntity extends UpdatableEntity, AbstractEntity { static MapIdentityProviderMapperEntity fromModel(IdentityProviderMapperModel model) { if (model == null) return null; - MapIdentityProviderMapperEntity entity = new MapIdentityProviderMapperEntityImpl(); + MapIdentityProviderMapperEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapIdentityProviderMapperEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); entity.setId(id); entity.setName(model.getName()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapOTPPolicyEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapOTPPolicyEntity.java index cf90610dba..429a9a6900 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapOTPPolicyEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapOTPPolicyEntity.java @@ -27,7 +27,7 @@ import org.keycloak.models.map.common.UpdatableEntity; public interface MapOTPPolicyEntity extends UpdatableEntity { static MapOTPPolicyEntity fromModel(OTPPolicy model) { if (model == null) return null; - MapOTPPolicyEntity entity = new MapOTPPolicyEntityImpl(); + MapOTPPolicyEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapOTPPolicyEntity.class); entity.setOtpPolicyAlgorithm(model.getAlgorithm()); entity.setOtpPolicyDigits(model.getDigits()); entity.setOtpPolicyInitialCounter(model.getInitialCounter()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredActionProviderEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredActionProviderEntity.java index 54d099d888..c9728a0c70 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredActionProviderEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredActionProviderEntity.java @@ -32,7 +32,7 @@ import java.util.Map; public interface MapRequiredActionProviderEntity extends UpdatableEntity, AbstractEntity { static MapRequiredActionProviderEntity fromModel(RequiredActionProviderModel model) { if (model == null) return null; - MapRequiredActionProviderEntity entity = new MapRequiredActionProviderEntityImpl(); + MapRequiredActionProviderEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapRequiredActionProviderEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); entity.setId(id); entity.setAlias(model.getAlias()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredCredentialEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredCredentialEntity.java index 72ac21f2ef..cfe98fbada 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredCredentialEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapRequiredCredentialEntity.java @@ -27,7 +27,7 @@ import org.keycloak.models.map.common.UpdatableEntity; public interface MapRequiredCredentialEntity extends UpdatableEntity { static MapRequiredCredentialEntity fromModel(RequiredCredentialModel model) { if (model == null) return null; - MapRequiredCredentialEntity entity = new MapRequiredCredentialEntityImpl(); + MapRequiredCredentialEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapRequiredCredentialEntity.class); entity.setFormLabel(model.getFormLabel()); entity.setType(model.getType()); entity.setInput(model.isInput()); diff --git a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapWebAuthnPolicyEntity.java b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapWebAuthnPolicyEntity.java index aa4a6fa2db..f9e06b9837 100644 --- a/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapWebAuthnPolicyEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/realm/entity/MapWebAuthnPolicyEntity.java @@ -32,7 +32,7 @@ import java.util.List; public interface MapWebAuthnPolicyEntity extends UpdatableEntity { static MapWebAuthnPolicyEntity fromModel(WebAuthnPolicy model) { if (model == null) return null; - MapWebAuthnPolicyEntity entity = new MapWebAuthnPolicyEntityImpl(); + MapWebAuthnPolicyEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapWebAuthnPolicyEntity.class); entity.setRpEntityName(model.getRpEntityName()); entity.setSignatureAlgorithms(model.getSignatureAlgorithm()); entity.setRpId(model.getRpId()); @@ -64,7 +64,7 @@ public interface MapWebAuthnPolicyEntity extends UpdatableEntity { } static MapWebAuthnPolicyEntity defaultWebAuthnPolicy() { - MapWebAuthnPolicyEntity entity = new MapWebAuthnPolicyEntityImpl(); + MapWebAuthnPolicyEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapWebAuthnPolicyEntity.class); entity.setRpEntityName(Constants.DEFAULT_WEBAUTHN_POLICY_RP_ENTITY_NAME); entity.setSignatureAlgorithms(Arrays.asList(Constants.DEFAULT_WEBAUTHN_POLICY_SIGNATURE_ALGORITHMS.split(","))); entity.setRpId(""); diff --git a/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java b/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java index 0be0e8bbce..a3171535a5 100644 --- a/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java @@ -30,6 +30,7 @@ import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.RoleModel.SearchableFields; import org.keycloak.models.RoleProvider; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator; import org.keycloak.models.map.storage.criteria.DefaultModelCriteria; @@ -65,7 +66,7 @@ public class MapRoleProvider implements RoleProvider { LOG.tracef("addRealmRole(%s, %s, %s)%s", realm, id, name, getShortStackTrace()); - MapRoleEntity entity = new MapRoleEntityImpl(); + MapRoleEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapRoleEntity.class); entity.setId(id); entity.setRealmId(realm.getId()); entity.setName(name); @@ -122,7 +123,7 @@ public class MapRoleProvider implements RoleProvider { LOG.tracef("addClientRole(%s, %s, %s)%s", client, id, name, getShortStackTrace()); - MapRoleEntity entity = new MapRoleEntityImpl(); + MapRoleEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapRoleEntity.class); entity.setId(id); entity.setRealmId(client.getRealm().getId()); entity.setName(name); diff --git a/model/map/src/main/java/org/keycloak/models/map/singleUseObject/MapSingleUseObjectProvider.java b/model/map/src/main/java/org/keycloak/models/map/singleUseObject/MapSingleUseObjectProvider.java index 8a8ae10f69..e2871f5b41 100644 --- a/model/map/src/main/java/org/keycloak/models/map/singleUseObject/MapSingleUseObjectProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/singleUseObject/MapSingleUseObjectProvider.java @@ -23,6 +23,7 @@ import org.keycloak.models.SingleUseObjectValueModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.SingleUseObjectProvider; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.TimeAdapter; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; @@ -63,7 +64,7 @@ public class MapSingleUseObjectProvider implements SingleUseObjectProvider { throw new ModelDuplicateException("Single-use object entity exists: " + singleUseEntity.getObjectKey()); } - singleUseEntity = new MapSingleUseObjectEntityImpl(); + singleUseEntity = DeepCloner.DUMB_CLONER.newInstance(MapSingleUseObjectEntity.class); singleUseEntity.setObjectKey(key); singleUseEntity.setExpiration(Time.currentTimeMillis() + TimeAdapter.fromSecondsToMilliseconds(lifespanSeconds)); singleUseEntity.setNotes(notes); @@ -121,7 +122,7 @@ public class MapSingleUseObjectProvider implements SingleUseObjectProvider { if (singleUseEntity != null) { return false; } else { - singleUseEntity = new MapSingleUseObjectEntityImpl(); + singleUseEntity = DeepCloner.DUMB_CLONER.newInstance(MapSingleUseObjectEntity.class); singleUseEntity.setObjectKey(key); singleUseEntity.setExpiration(Time.currentTimeMillis() + TimeAdapter.fromSecondsToMilliseconds(lifespanInSeconds)); diff --git a/model/map/src/main/java/org/keycloak/models/map/user/MapUserConsentEntity.java b/model/map/src/main/java/org/keycloak/models/map/user/MapUserConsentEntity.java index 46e9138b10..f92a0462a5 100644 --- a/model/map/src/main/java/org/keycloak/models/map/user/MapUserConsentEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/user/MapUserConsentEntity.java @@ -38,7 +38,7 @@ public interface MapUserConsentEntity extends UpdatableEntity { public static MapUserConsentEntity fromModel(UserConsentModel model) { long currentTime = Time.currentTimeMillis(); - MapUserConsentEntity consentEntity = new MapUserConsentEntityImpl(); + MapUserConsentEntity consentEntity = DeepCloner.DUMB_CLONER.newInstance(MapUserConsentEntity.class); consentEntity.setClientId(model.getClient().getId()); consentEntity.setCreatedDate(currentTime); consentEntity.setLastUpdatedDate(currentTime); diff --git a/model/map/src/main/java/org/keycloak/models/map/user/MapUserCredentialEntity.java b/model/map/src/main/java/org/keycloak/models/map/user/MapUserCredentialEntity.java index a23a49f679..0036e5f1d0 100644 --- a/model/map/src/main/java/org/keycloak/models/map/user/MapUserCredentialEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/user/MapUserCredentialEntity.java @@ -30,7 +30,7 @@ import java.util.Comparator; public interface MapUserCredentialEntity extends UpdatableEntity { public static MapUserCredentialEntity fromModel(CredentialModel model) { - MapUserCredentialEntity credentialEntity = new MapUserCredentialEntityImpl(); + MapUserCredentialEntity credentialEntity = DeepCloner.DUMB_CLONER.newInstance(MapUserCredentialEntity.class); String id = model.getId() == null ? KeycloakModelUtils.generateId() : model.getId(); credentialEntity.setId(id); credentialEntity.setCreatedDate(model.getCreatedDate()); diff --git a/model/map/src/main/java/org/keycloak/models/map/user/MapUserFederatedIdentityEntity.java b/model/map/src/main/java/org/keycloak/models/map/user/MapUserFederatedIdentityEntity.java index 6a148bd58a..564134a546 100644 --- a/model/map/src/main/java/org/keycloak/models/map/user/MapUserFederatedIdentityEntity.java +++ b/model/map/src/main/java/org/keycloak/models/map/user/MapUserFederatedIdentityEntity.java @@ -28,7 +28,7 @@ public interface MapUserFederatedIdentityEntity extends UpdatableEntity { public static MapUserFederatedIdentityEntity fromModel(FederatedIdentityModel model) { if (model == null) return null; - MapUserFederatedIdentityEntity entity = new MapUserFederatedIdentityEntityImpl(); + MapUserFederatedIdentityEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapUserFederatedIdentityEntity.class); entity.setIdentityProvider(model.getIdentityProvider()); entity.setUserId(model.getUserId()); entity.setUserName(model.getUserName().toLowerCase()); diff --git a/model/map/src/main/java/org/keycloak/models/map/user/MapUserProvider.java b/model/map/src/main/java/org/keycloak/models/map/user/MapUserProvider.java index 2e334f624e..c33390541f 100644 --- a/model/map/src/main/java/org/keycloak/models/map/user/MapUserProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/user/MapUserProvider.java @@ -46,6 +46,7 @@ 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.DeepCloner; import org.keycloak.models.map.common.TimeAdapter; import org.keycloak.models.map.credential.MapUserCredentialManager; import org.keycloak.models.map.storage.MapKeycloakTransactionWithAuth; @@ -343,7 +344,7 @@ public class MapUserProvider implements UserProvider { throw new ModelDuplicateException("User exists: " + id); } - MapUserEntity entity = new MapUserEntityImpl(); + MapUserEntity entity = DeepCloner.DUMB_CLONER.newInstance(MapUserEntity.class); entity.setId(id); entity.setRealmId(realm.getId()); entity.setEmailConstraint(KeycloakModelUtils.generateId()); diff --git a/model/map/src/main/java/org/keycloak/models/map/userSession/MapUserSessionProvider.java b/model/map/src/main/java/org/keycloak/models/map/userSession/MapUserSessionProvider.java index ed08bd1804..ed364cdef1 100644 --- a/model/map/src/main/java/org/keycloak/models/map/userSession/MapUserSessionProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/userSession/MapUserSessionProvider.java @@ -27,6 +27,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.keycloak.models.UserSessionModel; import org.keycloak.models.UserSessionProvider; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.common.TimeAdapter; import org.keycloak.models.map.storage.MapKeycloakTransaction; import org.keycloak.models.map.storage.MapStorage; @@ -625,7 +626,7 @@ public class MapUserSessionProvider implements UserSessionProvider { private MapUserSessionEntity createUserSessionEntityInstance(String id, String realmId, String userId, String loginUsername, String ipAddress, String authMethod, boolean rememberMe, String brokerSessionId, String brokerUserId, boolean offline) { - MapUserSessionEntityImpl userSessionEntity = new MapUserSessionEntityImpl(); + MapUserSessionEntity userSessionEntity = DeepCloner.DUMB_CLONER.newInstance(MapUserSessionEntity.class); userSessionEntity.setId(id); userSessionEntity.setRealmId(realmId); userSessionEntity.setUserId(userId); @@ -643,7 +644,7 @@ public class MapUserSessionProvider implements UserSessionProvider { private MapAuthenticatedClientSessionEntity createAuthenticatedClientSessionEntityInstance(String id, String userSessionId, String realmId, String clientId, boolean offline) { - MapAuthenticatedClientSessionEntityImpl clientSessionEntity = new MapAuthenticatedClientSessionEntityImpl(); + MapAuthenticatedClientSessionEntity clientSessionEntity = DeepCloner.DUMB_CLONER.newInstance(MapAuthenticatedClientSessionEntity.class); clientSessionEntity.setId(id == null ? KeycloakModelUtils.generateId() : id); clientSessionEntity.setRealmId(realmId); clientSessionEntity.setClientId(clientId); diff --git a/model/map/src/test/java/org/keycloak/models/map/client/MapClientEntityClonerTest.java b/model/map/src/test/java/org/keycloak/models/map/client/MapClientEntityClonerTest.java index 0b714d4e8f..ad279239b9 100644 --- a/model/map/src/test/java/org/keycloak/models/map/client/MapClientEntityClonerTest.java +++ b/model/map/src/test/java/org/keycloak/models/map/client/MapClientEntityClonerTest.java @@ -86,7 +86,7 @@ public class MapClientEntityClonerTest { newInstance.setId("my-id"); newInstance.setClientId("a-client-id"); newInstance.setAttribute("attr", Arrays.asList("aa", "bb", "cc")); - MapProtocolMapperEntity pmm = new MapProtocolMapperEntityImpl(); + MapProtocolMapperEntity pmm = DeepCloner.DUMB_CLONER.newInstance(MapProtocolMapperEntity.class); pmm.setId("pmm-id"); Map config = new HashMap<>(); config.put("key1", "value1"); @@ -121,11 +121,11 @@ public class MapClientEntityClonerTest { @Test public void testCloneToExistingInstanceDumb() { - MapClientEntity newInstance = new MapClientEntityImpl(); + MapClientEntity newInstance = DeepCloner.DUMB_CLONER.newInstance(MapClientEntity.class); newInstance.setId("my-id"); newInstance.setClientId("a-client-id"); newInstance.setAttribute("attr", Arrays.asList("aa", "bb", "cc")); - MapProtocolMapperEntity pmm = new MapProtocolMapperEntityImpl(); + MapProtocolMapperEntity pmm = DeepCloner.DUMB_CLONER.newInstance(MapProtocolMapperEntity.class); pmm.setId("pmm-id"); Map config = new HashMap<>(); config.put("key1", "value1"); diff --git a/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderCacheTest.java b/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderCacheTest.java index 9b59ba091c..24ba81e4b1 100644 --- a/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderCacheTest.java +++ b/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderCacheTest.java @@ -18,7 +18,6 @@ package org.keycloak.models.map.common.delegate; import org.keycloak.models.map.client.MapClientEntity; import org.keycloak.models.map.client.MapClientEntityFields; -import org.keycloak.models.map.client.MapClientEntityImpl; import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.tree.NodeProperties; import org.keycloak.models.map.storage.tree.TreeStorageNodeInstance; @@ -61,8 +60,8 @@ public class PerFieldDelegateProviderCacheTest { @Before public void initEntities() { - upperEnt = new MapClientEntityImpl(); - lowerEnt = new MapClientEntityImpl(); + upperEnt = DeepCloner.DUMB_CLONER.newInstance(MapClientEntity.class); + lowerEnt = DeepCloner.DUMB_CLONER.newInstance(MapClientEntity.class); upperEnt.setProtocol("upper-protocol"); upperEnt.addRedirectUri("upper-redirectUri-1"); diff --git a/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderPrimarySourceTest.java b/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderPrimarySourceTest.java index 75cf60f4bd..466581b5f3 100644 --- a/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderPrimarySourceTest.java +++ b/model/map/src/test/java/org/keycloak/models/map/common/delegate/PerFieldDelegateProviderPrimarySourceTest.java @@ -18,7 +18,6 @@ package org.keycloak.models.map.common.delegate; import org.keycloak.models.map.client.MapClientEntity; import org.keycloak.models.map.client.MapClientEntityFields; -import org.keycloak.models.map.client.MapClientEntityImpl; import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.tree.NodeProperties; import org.keycloak.models.map.storage.tree.TreeStorageNodeInstance; @@ -60,8 +59,8 @@ public class PerFieldDelegateProviderPrimarySourceTest { @Before public void initEntities() { - upperEnt = new MapClientEntityImpl(); - lowerEnt = new MapClientEntityImpl(); + upperEnt = DeepCloner.DUMB_CLONER.newInstance(MapClientEntity.class); + lowerEnt = DeepCloner.DUMB_CLONER.newInstance(MapClientEntity.class); upperEnt.setProtocol("upper-protocol"); upperEnt.addRedirectUri("upper-redirectUri-1"); diff --git a/model/map/src/test/java/org/keycloak/models/map/realm/RealmEntityUndefinedValuesTest.java b/model/map/src/test/java/org/keycloak/models/map/realm/RealmEntityUndefinedValuesTest.java index acf3b85214..84e3e850dc 100644 --- a/model/map/src/test/java/org/keycloak/models/map/realm/RealmEntityUndefinedValuesTest.java +++ b/model/map/src/test/java/org/keycloak/models/map/realm/RealmEntityUndefinedValuesTest.java @@ -17,6 +17,7 @@ package org.keycloak.models.map.realm; +import org.keycloak.models.map.common.DeepCloner; import org.junit.Test; import java.util.Arrays; @@ -39,7 +40,7 @@ import static org.hamcrest.Matchers.hasKey; public class RealmEntityUndefinedValuesTest { public MapRealmEntity newMapRealmEntity() { - return new MapRealmEntityImpl(); + return DeepCloner.DUMB_CLONER.newInstance(MapRealmEntity.class); } @Test diff --git a/model/map/src/test/java/org/keycloak/models/map/user/MapUserEntityImplCredentialsOrderTest.java b/model/map/src/test/java/org/keycloak/models/map/user/MapUserEntityImplCredentialsOrderTest.java index bff4bb72cc..ec5502fc5c 100644 --- a/model/map/src/test/java/org/keycloak/models/map/user/MapUserEntityImplCredentialsOrderTest.java +++ b/model/map/src/test/java/org/keycloak/models/map/user/MapUserEntityImplCredentialsOrderTest.java @@ -41,7 +41,7 @@ public class MapUserEntityImplCredentialsOrderTest { user = new MapUserEntityImpl(CLONER); for (int i = 1; i <= 5; i++) { - MapUserCredentialEntity credentialModel = new MapUserCredentialEntityImpl(); + MapUserCredentialEntity credentialModel = DeepCloner.DUMB_CLONER.newInstance(MapUserCredentialEntity.class); credentialModel.setId(Integer.toString(i)); user.addCredential(credentialModel); diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/ConcurrentHashMapStorageTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/ConcurrentHashMapStorageTest.java index e4b0df97d0..eec011ecd0 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/ConcurrentHashMapStorageTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/ConcurrentHashMapStorageTest.java @@ -26,6 +26,7 @@ import org.keycloak.models.RealmProvider; import org.keycloak.models.map.client.MapClientEntity; import org.keycloak.models.map.client.MapClientEntityImpl; import org.keycloak.models.map.client.MapClientProviderFactory; +import org.keycloak.models.map.common.DeepCloner; import org.keycloak.models.map.storage.MapStorage; import org.keycloak.models.map.storage.MapStorageProvider; import org.keycloak.models.map.storage.MapStorageProviderFactory; @@ -117,13 +118,13 @@ public class ConcurrentHashMapStorageTest extends KeycloakModelTest { assertClientDoesNotExist(storage2, idMain, kcMain, kc2); assertClientDoesNotExist(storage2, id1, kc1, kc2); - MapClientEntity clientMain = new MapClientEntityImpl(); + MapClientEntity clientMain = new MapClientEntityImpl(DeepCloner.DUMB_CLONER); clientMain.setId(idMain); clientMain.setRealmId(realmId); - MapClientEntity client1 = new MapClientEntityImpl(); + MapClientEntity client1 = new MapClientEntityImpl(DeepCloner.DUMB_CLONER); client1.setId(id1); client1.setRealmId(realmId); - MapClientEntity client2 = new MapClientEntityImpl(); + MapClientEntity client2 = new MapClientEntityImpl(DeepCloner.DUMB_CLONER); client2.setId(id2); client2.setRealmId(realmId);