modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java | 15 ++++++++-- modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java | 5 +++ 2 files changed, 18 insertions(+), 2 deletions(-)
New commits: commit e4eac1f96a14ff4197583b284078bd95a59e0eac Author: Lukas Krejci lkrejci@redhat.com Date: Thu Nov 24 12:56:28 2011 +0100
[BZ 755653] - Make sure role membership is not updated through the updateResourceGroup() methods.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java index 564cef3..156253c 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java @@ -409,6 +409,10 @@ public class ResourceGroup extends Group { @ManyToMany private Set<Resource> implicitResources;
+ //TODO ResourceGroup probably isn't the right owning side of this relationship + //this means that any update of a group can update the role membership, + //which is not something one normally does. Maybe the more logical owner of this + //relationship would be the Role. @JoinTable(name = "RHQ_ROLE_RESOURCE_GROUP_MAP", joinColumns = { @JoinColumn(name = "RESOURCE_GROUP_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) @ManyToMany private Set<Role> roles = new HashSet<Role>(); @@ -562,15 +566,22 @@ public class ResourceGroup extends Group { }
public Set<Role> getRoles() { + //even though the field has an initializer, it can end up + //being null after deserialization. Because there is no + //setter and there are some other public methods depending + //on this not being null, let's make it lazy init. + if (roles == null) { + roles = new HashSet<Role>(); + } return roles; }
public void addRole(Role role) { - this.roles.add(role); + getRoles().add(role); }
public void removeRole(Role role) { - this.roles.remove(role); + getRoles().remove(role); }
@NotNull diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java index b8e52c4..82a91dc 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java @@ -206,6 +206,11 @@ public class ResourceGroupManagerBean implements ResourceGroupManagerLocal, Reso + "] does not have permission to modify Resource group with id [" + groupId + "]."); }
+ //roles are not to be updated by this call but the group entity + //owns the relationship. Let's make sure we don't change the assigned roles here. + group.getRoles().clear(); + group.getRoles().addAll(attachedGroup.getRoles()); + if (changeType == null) { changeType = RecursivityChangeType.None; if (attachedGroup.isRecursive() == true && group.isRecursive() == false) {