diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java index b9faa5ca46..ad17a4571c 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaRealmProvider.java @@ -151,7 +151,7 @@ public class JpaRealmProvider implements RealmProvider { em.flush(); int num = em.createNamedQuery("deleteGroupRoleMappingsByRealm") - .setParameter("realm", realm).executeUpdate(); + .setParameter("realm", realm.getId()).executeUpdate(); TypedQuery query = em.createNamedQuery("getClientIdsByRealm", String.class); query.setParameter("realm", realm.getId()); @@ -407,7 +407,7 @@ public class JpaRealmProvider implements RealmProvider { public GroupModel getGroupById(String id, RealmModel realm) { GroupEntity groupEntity = em.find(GroupEntity.class, id); if (groupEntity == null) return null; - if (!groupEntity.getRealm().getId().equals(realm.getId())) return null; + if (!groupEntity.getRealm().equals(realm.getId())) return null; GroupAdapter adapter = new GroupAdapter(realm, em, groupEntity); return adapter; } @@ -543,7 +543,7 @@ public class JpaRealmProvider implements RealmProvider { session.realms().removeGroup(realm, subGroup); } GroupEntity groupEntity = em.find(GroupEntity.class, group.getId(), LockModeType.PESSIMISTIC_WRITE); - if ((groupEntity == null) || (!groupEntity.getRealm().getId().equals(realm.getId()))) { + if ((groupEntity == null) || (!groupEntity.getRealm().equals(realm.getId()))) { return false; } em.createNamedQuery("deleteGroupRoleMappingsByGroup").setParameter("group", groupEntity).executeUpdate(); @@ -569,7 +569,7 @@ public class JpaRealmProvider implements RealmProvider { groupEntity.setId(id); groupEntity.setName(name); RealmEntity realmEntity = em.getReference(RealmEntity.class, realm.getId()); - groupEntity.setRealm(realmEntity); + groupEntity.setRealm(realmEntity.getId()); groupEntity.setParentId(toParent == null? GroupEntity.TOP_PARENT_ID : toParent.getId()); em.persist(groupEntity); em.flush(); diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index c81776dd3a..f23ab2b8d8 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -1229,7 +1229,11 @@ public class RealmAdapter implements RealmModel, JpaModel { @Override public ClientModel getMasterAdminClient() { - ClientEntity masterAdminClient = realm.getMasterAdminClient(); + String masterAdminClientId = realm.getMasterAdminClient(); + if (masterAdminClientId == null) { + return null; + } + ClientEntity masterAdminClient = em.find(ClientEntity.class, masterAdminClientId); if (masterAdminClient == null) { return null; } @@ -1245,8 +1249,8 @@ public class RealmAdapter implements RealmModel, JpaModel { @Override public void setMasterAdminClient(ClientModel client) { - ClientEntity appEntity = client !=null ? em.getReference(ClientEntity.class, client.getId()) : null; - realm.setMasterAdminClient(appEntity); + String appEntityId = client !=null ? em.getReference(ClientEntity.class, client.getId()).getId() : null; + realm.setMasterAdminClient(appEntityId); em.flush(); } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationFlowEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationFlowEntity.java index 7a9afc2baa..20b7902c92 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationFlowEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationFlowEntity.java @@ -28,12 +28,10 @@ import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; /** * @author Bill Burke @@ -69,7 +67,7 @@ public class AuthenticationFlowEntity { @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "parentFlow") - Collection executions = new ArrayList(); + Collection executions; public String getId() { return id; } @@ -103,6 +101,9 @@ public class AuthenticationFlowEntity { } public Collection getExecutions() { + if (executions == null) { + executions = new LinkedList<>(); + } return executions; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java index 5c54b75666..dc910db52f 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java @@ -37,10 +37,10 @@ import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.Map; import java.util.Set; @@ -102,24 +102,24 @@ public class ClientEntity { @ElementCollection @Column(name="VALUE") @CollectionTable(name = "WEB_ORIGINS", joinColumns={ @JoinColumn(name="CLIENT_ID") }) - protected Set webOrigins = new HashSet(); + protected Set webOrigins; @ElementCollection @Column(name="VALUE") @CollectionTable(name = "REDIRECT_URIS", joinColumns={ @JoinColumn(name="CLIENT_ID") }) - protected Set redirectUris = new HashSet(); + protected Set redirectUris; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "client") - protected Collection attributes = new ArrayList<>(); + protected Collection attributes; @ElementCollection @MapKeyColumn(name="BINDING_NAME") @Column(name="FLOW_ID", length = 4000) @CollectionTable(name="CLIENT_AUTH_FLOW_BINDINGS", joinColumns={ @JoinColumn(name="CLIENT_ID") }) - protected Map authFlowBindings = new HashMap(); + protected Map authFlowBindings; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "client") - Collection protocolMappers = new ArrayList(); + Collection protocolMappers; @Column(name="SURROGATE_AUTH_REQUIRED") private boolean surrogateAuthRequired; @@ -156,17 +156,17 @@ public class ClientEntity { @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) @JoinTable(name="CLIENT_DEFAULT_ROLES", joinColumns = { @JoinColumn(name="CLIENT_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")}) - Collection defaultRoles = new ArrayList(); + Collection defaultRoles; @OneToMany(fetch = FetchType.LAZY) @JoinTable(name="SCOPE_MAPPING", joinColumns = { @JoinColumn(name="CLIENT_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")}) - protected Set scopeMapping = new HashSet<>(); + protected Set scopeMapping; @ElementCollection @MapKeyColumn(name="NAME") @Column(name="VALUE") @CollectionTable(name="CLIENT_NODE_REGISTRATIONS", joinColumns={ @JoinColumn(name="CLIENT_ID") }) - Map registeredNodes = new HashMap(); + Map registeredNodes; public RealmEntity getRealm() { return realm; @@ -225,6 +225,9 @@ public class ClientEntity { } public Set getWebOrigins() { + if (webOrigins == null) { + webOrigins = new HashSet<>(); + } return webOrigins; } @@ -233,6 +236,9 @@ public class ClientEntity { } public Set getRedirectUris() { + if (redirectUris == null) { + redirectUris = new HashSet<>(); + } return redirectUris; } @@ -289,6 +295,9 @@ public class ClientEntity { } public Collection getAttributes() { + if (attributes == null) { + attributes = new LinkedList<>(); + } return attributes; } @@ -297,6 +306,9 @@ public class ClientEntity { } public Map getAuthFlowBindings() { + if (authFlowBindings == null) { + authFlowBindings = new HashMap<>(); + } return authFlowBindings; } @@ -321,6 +333,9 @@ public class ClientEntity { } public Collection getProtocolMappers() { + if (protocolMappers == null) { + protocolMappers = new LinkedList<>(); + } return protocolMappers; } @@ -361,6 +376,9 @@ public class ClientEntity { } public Collection getDefaultRoles() { + if (defaultRoles == null) { + defaultRoles = new LinkedList<>(); + } return defaultRoles; } @@ -425,6 +443,9 @@ public class ClientEntity { } public Map getRegisteredNodes() { + if (registeredNodes == null) { + registeredNodes = new HashMap<>(); + } return registeredNodes; } @@ -433,6 +454,9 @@ public class ClientEntity { } public Set getScopeMapping() { + if (scopeMapping == null) { + scopeMapping = new HashSet<>(); + } return scopeMapping; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientScopeEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientScopeEntity.java index eddabe5e5b..a2a502995f 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientScopeEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientScopeEntity.java @@ -31,8 +31,8 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; /** * @author Bill Burke @@ -52,7 +52,7 @@ public class ClientScopeEntity { @Column(name = "DESCRIPTION") private String description; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "clientScope") - Collection protocolMappers = new ArrayList(); + Collection protocolMappers; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "REALM_ID") protected RealmEntity realm; @@ -62,7 +62,7 @@ public class ClientScopeEntity { @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "clientScope") - protected Collection attributes = new ArrayList<>(); + protected Collection attributes; public RealmEntity getRealm() { return realm; @@ -97,6 +97,9 @@ public class ClientScopeEntity { } public Collection getProtocolMappers() { + if (protocolMappers == null) { + protocolMappers = new LinkedList<>(); + } return protocolMappers; } @@ -113,6 +116,9 @@ public class ClientScopeEntity { } public Collection getAttributes() { + if (attributes == null) { + attributes = new LinkedList<>(); + } return attributes; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ComponentEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ComponentEntity.java index 857fc55c2a..8857bc96b1 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ComponentEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ComponentEntity.java @@ -64,7 +64,7 @@ public class ComponentEntity { protected String subType; @OneToMany(fetch = FetchType.LAZY, cascade ={ CascadeType.ALL}, orphanRemoval = true, mappedBy = "component") - Set componentConfigs = new HashSet<>(); + Set componentConfigs; public String getId() { return id; @@ -123,6 +123,9 @@ public class ComponentEntity { } public Set getComponentConfigs() { + if (componentConfigs == null) { + componentConfigs = new HashSet<>(); + } return componentConfigs; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/GroupEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/GroupEntity.java index 2925812799..141c5fd31d 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/GroupEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/GroupEntity.java @@ -20,8 +20,8 @@ package org.keycloak.models.jpa.entities; import org.hibernate.annotations.Nationalized; import javax.persistence.*; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; /** * @author Bill Burke @@ -29,10 +29,10 @@ import java.util.Collection; */ @NamedQueries({ @NamedQuery(name="getGroupIdsByParent", query="select u.id from GroupEntity u where u.parentId = :parent"), - @NamedQuery(name="getGroupIdsByNameContaining", query="select u.id from GroupEntity u where u.realm.id = :realm and u.name like concat('%',:search,'%') order by u.name ASC"), - @NamedQuery(name="getTopLevelGroupIds", query="select u.id from GroupEntity u where u.parentId = :parent and u.realm.id = :realm order by u.name ASC"), - @NamedQuery(name="getGroupCount", query="select count(u) from GroupEntity u where u.realm.id = :realm"), - @NamedQuery(name="getTopLevelGroupCount", query="select count(u) from GroupEntity u where u.realm.id = :realm and u.parentId = :parent") + @NamedQuery(name="getGroupIdsByNameContaining", query="select u.id from GroupEntity u where u.realm = :realm and u.name like concat('%',:search,'%') order by u.name ASC"), + @NamedQuery(name="getTopLevelGroupIds", query="select u.id from GroupEntity u where u.parentId = :parent and u.realm = :realm order by u.name ASC"), + @NamedQuery(name="getGroupCount", query="select count(u) from GroupEntity u where u.realm = :realm"), + @NamedQuery(name="getTopLevelGroupCount", query="select count(u) from GroupEntity u where u.realm = :realm and u.parentId = :parent") }) @Entity @Table(name="KEYCLOAK_GROUP", @@ -57,14 +57,13 @@ public class GroupEntity { @Column(name = "PARENT_GROUP") private String parentId; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "REALM_ID") - private RealmEntity realm; + @Column(name = "REALM_ID") + private String realm; @OneToMany( cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="group") - protected Collection attributes = new ArrayList(); + protected Collection attributes; public String getId() { return id; @@ -75,6 +74,9 @@ public class GroupEntity { } public Collection getAttributes() { + if (attributes == null) { + attributes = new LinkedList<>(); + } return attributes; } @@ -90,11 +92,11 @@ public class GroupEntity { this.name = name; } - public RealmEntity getRealm() { + public String getRealm() { return realm; } - public void setRealm(RealmEntity realm) { + public void setRealm(String realm) { this.realm = realm; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java index 332cc16eef..be5a166651 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java @@ -32,12 +32,11 @@ import javax.persistence.MapKeyColumn; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; -import javax.persistence.OneToOne; import javax.persistence.Table; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -138,36 +137,36 @@ public class RealmEntity { protected String emailTheme; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm", fetch = FetchType.EAGER) - Collection attributes = new ArrayList<>(); + Collection attributes; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection requiredCredentials = new ArrayList<>(); + Collection requiredCredentials; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - List userFederationProviders = new ArrayList<>(); + List userFederationProviders; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection userFederationMappers = new ArrayList(); + Collection userFederationMappers; @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection clientScopes = new ArrayList<>(); + Collection clientScopes; @ElementCollection @MapKeyColumn(name="NAME") @Column(name="VALUE") @CollectionTable(name="REALM_SMTP_CONFIG", joinColumns={ @JoinColumn(name="REALM_ID") }) - protected Map smtpConfig = new HashMap(); + protected Map smtpConfig; @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) @JoinTable(name="REALM_DEFAULT_ROLES", joinColumns = { @JoinColumn(name="REALM_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")}) - protected Collection defaultRoles = new ArrayList(); + protected Collection defaultRoles; @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) @JoinTable(name="REALM_DEFAULT_GROUPS", joinColumns = { @JoinColumn(name="REALM_ID")}, inverseJoinColumns = { @JoinColumn(name="GROUP_ID")}) - protected Collection defaultGroups = new ArrayList<>(); + protected Collection defaultGroups; @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - protected Collection groups = new ArrayList<>(); + protected Collection groups; @Column(name="EVENTS_ENABLED") protected boolean eventsEnabled; @@ -177,40 +176,39 @@ public class RealmEntity { @ElementCollection @Column(name="VALUE") @CollectionTable(name="REALM_EVENTS_LISTENERS", joinColumns={ @JoinColumn(name="REALM_ID") }) - protected Set eventsListeners = new HashSet(); + protected Set eventsListeners; @ElementCollection @Column(name="VALUE") @CollectionTable(name="REALM_ENABLED_EVENT_TYPES", joinColumns={ @JoinColumn(name="REALM_ID") }) - protected Set enabledEventTypes = new HashSet(); + protected Set enabledEventTypes; @Column(name="ADMIN_EVENTS_ENABLED") protected boolean adminEventsEnabled; @Column(name="ADMIN_EVENTS_DETAILS_ENABLED") protected boolean adminEventsDetailsEnabled; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name="MASTER_ADMIN_CLIENT") - protected ClientEntity masterAdminClient; + + @Column(name="MASTER_ADMIN_CLIENT") + protected String masterAdminClient; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - protected List identityProviders = new ArrayList(); + protected List identityProviders; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection identityProviderMappers = new ArrayList(); + Collection identityProviderMappers; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection authenticators = new ArrayList<>(); + Collection authenticators; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection requiredActionProviders = new ArrayList<>(); + Collection requiredActionProviders; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") - Collection authenticationFlows = new ArrayList<>(); + Collection authenticationFlows; @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.ALL}, orphanRemoval = true, mappedBy = "realm") - Set components = new HashSet<>(); + Set components; @Column(name="BROWSER_FLOW") protected String browserFlow; @@ -237,7 +235,7 @@ public class RealmEntity { @ElementCollection @Column(name="VALUE") @CollectionTable(name="REALM_SUPPORTED_LOCALES", joinColumns={ @JoinColumn(name="REALM_ID") }) - protected Set supportedLocales = new HashSet(); + protected Set supportedLocales; @Column(name="DEFAULT_LOCALE") protected String defaultLocale; @@ -438,6 +436,9 @@ public class RealmEntity { } public Collection getRequiredCredentials() { + if (requiredCredentials == null) { + requiredCredentials = new LinkedList<>(); + } return requiredCredentials; } @@ -445,6 +446,9 @@ public class RealmEntity { this.requiredCredentials = requiredCredentials; } public Map getSmtpConfig() { + if (smtpConfig == null) { + smtpConfig = new HashMap<>(); + } return smtpConfig; } @@ -453,6 +457,9 @@ public class RealmEntity { } public Collection getDefaultRoles() { + if (defaultRoles == null) { + defaultRoles = new LinkedList<>(); + } return defaultRoles; } @@ -461,6 +468,9 @@ public class RealmEntity { } public Collection getDefaultGroups() { + if (defaultGroups == null) { + defaultGroups = new LinkedList<>(); + } return defaultGroups; } @@ -469,6 +479,9 @@ public class RealmEntity { } public Collection getGroups() { + if (groups == null) { + groups = new LinkedList<>(); + } return groups; } @@ -541,6 +554,9 @@ public class RealmEntity { } public Set getEventsListeners() { + if (eventsListeners == null) { + eventsListeners = new HashSet<>(); + } return eventsListeners; } @@ -549,6 +565,9 @@ public class RealmEntity { } public Set getEnabledEventTypes() { + if (enabledEventTypes == null) { + enabledEventTypes = new HashSet<>(); + } return enabledEventTypes; } @@ -572,15 +591,18 @@ public class RealmEntity { this.adminEventsDetailsEnabled = adminEventsDetailsEnabled; } - public ClientEntity getMasterAdminClient() { + public String getMasterAdminClient() { return masterAdminClient; } - public void setMasterAdminClient(ClientEntity masterAdminClient) { + public void setMasterAdminClient(String masterAdminClient) { this.masterAdminClient = masterAdminClient; } public List getUserFederationProviders() { + if (userFederationProviders == null) { + userFederationProviders = new LinkedList<>(); + } return userFederationProviders; } @@ -589,6 +611,9 @@ public class RealmEntity { } public Collection getUserFederationMappers() { + if (userFederationMappers == null) { + userFederationMappers = new LinkedList<>(); + } return userFederationMappers; } @@ -597,6 +622,9 @@ public class RealmEntity { } public Collection getAttributes() { + if (attributes == null) { + attributes = new LinkedList<>(); + } return attributes; } @@ -605,6 +633,9 @@ public class RealmEntity { } public List getIdentityProviders() { + if (identityProviders == null) { + identityProviders = new LinkedList<>(); + } return this.identityProviders; } @@ -626,6 +657,9 @@ public class RealmEntity { } public Set getSupportedLocales() { + if (supportedLocales == null) { + supportedLocales = new HashSet<>(); + } return supportedLocales; } @@ -642,6 +676,9 @@ public class RealmEntity { } public Collection getIdentityProviderMappers() { + if (identityProviderMappers == null) { + identityProviderMappers = new LinkedList<>(); + } return identityProviderMappers; } @@ -650,14 +687,20 @@ public class RealmEntity { } public Collection getAuthenticatorConfigs() { + if (authenticators == null) { + authenticators = new LinkedList<>(); + } return authenticators; } - + public void setAuthenticatorConfigs(Collection authenticators) { this.authenticators = authenticators; } public Collection getRequiredActionProviders() { + if (requiredActionProviders == null) { + requiredActionProviders = new LinkedList<>(); + } return requiredActionProviders; } @@ -666,6 +709,9 @@ public class RealmEntity { } public Collection getAuthenticationFlows() { + if (authenticationFlows == null) { + authenticationFlows = new LinkedList<>(); + } return authenticationFlows; } @@ -674,6 +720,9 @@ public class RealmEntity { } public Set getComponents() { + if (components == null) { + components = new HashSet<>(); + } return components; } @@ -779,6 +828,9 @@ public class RealmEntity { } public Collection getClientScopes() { + if (clientScopes == null) { + clientScopes = new LinkedList<>(); + } return clientScopes; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java index 1088d523c9..71f09b9c6e 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RoleEntity.java @@ -38,9 +38,9 @@ import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -101,12 +101,12 @@ public class RoleEntity { @ManyToMany(fetch = FetchType.LAZY, cascade = {}) @JoinTable(name = "COMPOSITE_ROLE", joinColumns = @JoinColumn(name = "COMPOSITE"), inverseJoinColumns = @JoinColumn(name = "CHILD_ROLE")) - private Set compositeRoles = new HashSet<>(); + private Set compositeRoles; @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="role") @Fetch(FetchMode.SELECT) @BatchSize(size = 20) - protected List attributes = new ArrayList<>(); + protected Collection attributes; public String getId() { return id; @@ -125,10 +125,13 @@ public class RoleEntity { } public Collection getAttributes() { + if (attributes == null) { + attributes = new LinkedList<>(); + } return attributes; } - public void setAttributes(List attributes) { + public void setAttributes(Collection attributes) { this.attributes = attributes; } @@ -149,6 +152,9 @@ public class RoleEntity { } public Set getCompositeRoles() { + if (compositeRoles == null) { + compositeRoles = new HashSet<>(); + } return compositeRoles; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserConsentEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserConsentEntity.java index 88a57b21c3..1e0a0f80e9 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserConsentEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserConsentEntity.java @@ -31,8 +31,8 @@ import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; /** * @author Marek Posolda @@ -73,7 +73,7 @@ public class UserConsentEntity { protected String externalClientId; @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "userConsent") - Collection grantedClientScopes = new ArrayList<>(); + Collection grantedClientScopes; @Column(name = "CREATED_DATE") private Long createdDate; @@ -98,6 +98,9 @@ public class UserConsentEntity { } public Collection getGrantedClientScopes() { + if (grantedClientScopes == null) { + grantedClientScopes = new LinkedList<>(); + } return grantedClientScopes; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java index de739708b4..9e109aa931 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java @@ -34,8 +34,8 @@ import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedList; /** * @author Bill Burke @@ -98,17 +98,17 @@ public class UserEntity { @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user") @Fetch(FetchMode.SELECT) @BatchSize(size = 20) - protected Collection attributes = new ArrayList(); + protected Collection attributes; @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user") @Fetch(FetchMode.SELECT) @BatchSize(size = 20) - protected Collection requiredActions = new ArrayList(); + protected Collection requiredActions; @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user") @Fetch(FetchMode.SELECT) @BatchSize(size = 20) - protected Collection credentials = new ArrayList(); + protected Collection credentials; @Column(name="FEDERATION_LINK") protected String federationLink; @@ -193,6 +193,9 @@ public class UserEntity { } public Collection getAttributes() { + if (attributes == null) { + attributes = new LinkedList<>(); + } return attributes; } @@ -201,6 +204,9 @@ public class UserEntity { } public Collection getRequiredActions() { + if (requiredActions == null) { + requiredActions = new LinkedList<>(); + } return requiredActions; } @@ -217,6 +223,9 @@ public class UserEntity { } public Collection getCredentials() { + if (credentials == null) { + credentials = new LinkedList<>(); + } return credentials; }