Client Scopes: Ensure that parent's version ID is incremented when an attribute changes

Closes #9874
This commit is contained in:
vramik 2022-02-02 13:22:11 +01:00 committed by Hynek Mlnařík
parent 0de72105d7
commit 165791b1d7
5 changed files with 12 additions and 11 deletions

View file

@ -16,10 +16,12 @@
*/ */
package org.keycloak.models.map.storage.jpa; package org.keycloak.models.map.storage.jpa;
import java.io.Serializable;
/** /**
* Interface for all child entities for JPA map storage. * Interface for all child entities for JPA map storage.
*/ */
public interface JpaChildEntity<R> { public interface JpaChildEntity<R> extends Serializable {
/** /**
* Parent entity that should get its optimistic locking version updated upon changes in the child * Parent entity that should get its optimistic locking version updated upon changes in the child

View file

@ -16,7 +16,6 @@
*/ */
package org.keycloak.models.map.storage.jpa.client.entity; package org.keycloak.models.map.storage.jpa.client.entity;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
@ -32,7 +31,7 @@ import org.keycloak.models.map.storage.jpa.JpaChildEntity;
@Entity @Entity
@Table(name = "client_attribute") @Table(name = "client_attribute")
public class JpaClientAttributeEntity implements JpaChildEntity<JpaClientEntity>, Serializable { public class JpaClientAttributeEntity implements JpaChildEntity<JpaClientEntity> {
@Id @Id
@Column @Column

View file

@ -16,7 +16,6 @@
*/ */
package org.keycloak.models.map.storage.jpa.clientscope.entity; package org.keycloak.models.map.storage.jpa.clientscope.entity;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
@ -28,10 +27,11 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.Nationalized; import org.hibernate.annotations.Nationalized;
import org.keycloak.models.map.storage.jpa.JpaChildEntity;
@Entity @Entity
@Table(name = "client_scope_attribute") @Table(name = "client_scope_attribute")
public class JpaClientScopeAttributeEntity implements Serializable { public class JpaClientScopeAttributeEntity implements JpaChildEntity<JpaClientScopeEntity> {
@Id @Id
@Column @Column
@ -100,4 +100,9 @@ public class JpaClientScopeAttributeEntity implements Serializable {
Objects.equals(getName(), that.getName()) && Objects.equals(getName(), that.getName()) &&
Objects.equals(getValue(), that.getValue()); Objects.equals(getValue(), that.getValue());
} }
@Override
public JpaClientScopeEntity getParent() {
return getClientScope();
}
} }

View file

@ -230,7 +230,6 @@ public class JpaClientScopeEntity extends AbstractClientScopeEntity implements J
JpaClientScopeAttributeEntity attr = iterator.next(); JpaClientScopeAttributeEntity attr = iterator.next();
if (Objects.equals(attr.getName(), name)) { if (Objects.equals(attr.getName(), name)) {
iterator.remove(); iterator.remove();
attr.setClientScope(null);
} }
} }
} }
@ -268,9 +267,7 @@ public class JpaClientScopeEntity extends AbstractClientScopeEntity implements J
public void setAttributes(Map<String, List<String>> attributes) { public void setAttributes(Map<String, List<String>> attributes) {
checkEntityVersionForUpdate(); checkEntityVersionForUpdate();
for (Iterator<JpaClientScopeAttributeEntity> iterator = this.attributes.iterator(); iterator.hasNext();) { for (Iterator<JpaClientScopeAttributeEntity> iterator = this.attributes.iterator(); iterator.hasNext();) {
JpaClientScopeAttributeEntity attr = iterator.next();
iterator.remove(); iterator.remove();
attr.setClientScope(null);
} }
if (attributes != null) { if (attributes != null) {
for (Map.Entry<String, List<String>> attrEntry : attributes.entrySet()) { for (Map.Entry<String, List<String>> attrEntry : attributes.entrySet()) {

View file

@ -16,7 +16,6 @@
*/ */
package org.keycloak.models.map.storage.jpa.role.entity; package org.keycloak.models.map.storage.jpa.role.entity;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column; import javax.persistence.Column;
@ -29,11 +28,10 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.Nationalized; import org.hibernate.annotations.Nationalized;
import org.keycloak.models.map.storage.jpa.JpaChildEntity; import org.keycloak.models.map.storage.jpa.JpaChildEntity;
import org.keycloak.models.map.storage.jpa.client.entity.JpaClientEntity;
@Entity @Entity
@Table(name = "role_attribute") @Table(name = "role_attribute")
public class JpaRoleAttributeEntity implements JpaChildEntity<JpaRoleEntity>, Serializable { public class JpaRoleAttributeEntity implements JpaChildEntity<JpaRoleEntity> {
@Id @Id
@Column @Column