modules/core/dbutils/src/main/scripts/dbsetup/authz-schema.xml | 10 modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java | 71 ++---- modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRoleEntity.java | 117 ---------- modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRolePK.java | 46 --- modules/core/domain/src/main/java/org/rhq/core/domain/authz/Role.java | 76 +++--- 5 files changed, 81 insertions(+), 239 deletions(-)
New commits: commit b9287ab8a2ff37eed95fc7883504db0a7130c7c1 Author: Partha Aji paji@redhat.com Date: Wed Feb 24 19:32:04 2010 -0500
Mapping For Solution 2 Done
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java b/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java index c7d895b..9b991cd 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java @@ -40,7 +40,6 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.QueryHint; import javax.persistence.SequenceGenerator; @@ -228,18 +227,19 @@ public class Subject implements Externalizable { @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE }) private Configuration configuration;
- @OneToMany(mappedBy = "subject") - private Set<SubjectRoleEntity> subjectRoles; + @JoinTable(name = "RHQ_SUBJECT_ROLE_MAP", joinColumns = { @JoinColumn(name = "SUBJECT_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) + @ManyToMany + private java.util.Set<Role> roles;
+ @JoinTable(name = "RHQ_SUBJECT_ROLE_LDAP_MAP", joinColumns = { @JoinColumn(name = "SUBJECT_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) @ManyToMany - @JoinTable(name = "RHQ_SUBJECT_ROLE_MAP", joinColumns = { @JoinColumn(name = "SUBJECT_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) - private Set<Role> roles = new HashSet<Role>(); + private java.util.Set<Role> ldapRoles;
@Transient private Integer sessionId = null;
private void init() { - subjectRoles = new HashSet<SubjectRoleEntity>(); + roles = new HashSet<Role>(); }
/** @@ -364,51 +364,44 @@ public class Subject implements Externalizable { this.configuration = configuration; }
- public Set<SubjectRoleEntity> getSubjectRoles() { - if (subjectRoles == null) { - subjectRoles = new HashSet<SubjectRoleEntity>(); + public java.util.Set<Role> getRoles() { + if (this.roles == null) { + this.roles = new HashSet<Role>(); } - return subjectRoles; - } - - public void setSubjectRoles(Set<SubjectRoleEntity> subjectRolesIn) { - subjectRoles = subjectRolesIn; - }
- public Set<Role> getRoles() { - if (roles == null) { - roles = new HashSet<Role>(); - } - return roles; + return this.roles; }
public void setRoles(Set<Role> roles) { this.roles = roles; }
- public void addRole(Role role, boolean ldap) { - SubjectRoleEntity s = new SubjectRoleEntity(); - s.setSubject(this); - s.setRole(role); - s.setLdap(ldap); - getSubjectRoles().add(s); - } - public void addRole(Role role) { - addRole(role, false); + getRoles().add(role); }
public void removeRole(Role role) { - SubjectRoleEntity toRemove = null; - for (SubjectRoleEntity s : getSubjectRoles()) { - if (s.getSubject().equals(this) && s.getRole().equals(role)) { - toRemove = s; - break; - } - } - if (toRemove != null) { - getSubjectRoles().remove(toRemove); + getRoles().remove(role); + } + + public java.util.Set<Role> getLdapRoles() { + if (this.ldapRoles == null) { + this.ldapRoles = new HashSet<Role>(); } + + return this.ldapRoles; + } + + public void setLdapRoles(Set<Role> roles) { + this.ldapRoles = roles; + } + + public void addLdapRole(Role role) { + getLdapRoles().add(role); + } + + public void removeLdapRole(Role role) { + getLdapRoles().remove(role); }
@Override @@ -517,7 +510,7 @@ public class Subject implements Externalizable { this.factive = in.readBoolean(); this.fsystem = in.readBoolean(); this.configuration = (Configuration) in.readObject(); - setRoles((Set<Role>) in.readObject()); + this.roles = (Set<Role>) in.readObject(); this.sessionId = in.readInt(); }
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRoleEntity.java b/modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRoleEntity.java deleted file mode 100644 index 3636fb5..0000000 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRoleEntity.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.rhq.core.domain.auth; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.Table; - -import org.rhq.core.domain.authz.Role; - -@Entity -@IdClass(SubjectRolePK.class) -@Table(name = "RHQ_SUBJECT_ROLE_MAP") -public class SubjectRoleEntity implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - @Id - private Subject subject; - - @Id - private Role role; - - @Column(name = "IS_LDAP") - private boolean isLdap; - - public Subject getSubject() { - return subject; - } - - public void setSubject(Subject subject) { - this.subject = subject; - } - - public Role getRole() { - return role; - } - - public void setRole(Role role) { - this.role = role; - } - - public boolean isLdap() { - return isLdap; - } - - public void setLdap(boolean isLdap) { - this.isLdap = isLdap; - } - - @Override - public int hashCode() { - final int PRIME = 31; - int result = 1; - result = (PRIME * result) + ((subject == null) ? 0 : subject.hashCode()); - result = (PRIME * result) + ((role == null) ? 0 : role.hashCode()); - result = (PRIME * result) + ((isLdap) ? 0 : PRIME); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if ((obj == null) || !(obj instanceof SubjectRoleEntity)) { - return false; - } - - final SubjectRoleEntity other = (SubjectRoleEntity) obj; - if (subject == null) { - if (other.subject != null) { - return false; - } - } else if (!subject.equals(other.subject)) { - return false; - } - - if (role == null) { - if (other.role != null) { - return false; - } - } else if (!role.equals(other.role)) { - return false; - } - - return isLdap == other.isLdap; - } -} diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRolePK.java b/modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRolePK.java deleted file mode 100644 index 8b6259c..0000000 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/SubjectRolePK.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2009 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -package org.rhq.core.domain.auth; - -import java.io.Serializable; - -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -import org.rhq.core.domain.authz.Role; - -/** - * @author paji - * - */ -public class SubjectRolePK implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; - - @ManyToOne - @JoinColumn(name = "USER_ID", referencedColumnName = "ID") - private Subject subject; - - @ManyToOne - @JoinColumn(name = "ROLE_ID", referencedColumnName = "ID") - private Role role; -} diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/authz/Role.java b/modules/core/domain/src/main/java/org/rhq/core/domain/authz/Role.java index 5267fca..b7004bd 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/authz/Role.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/authz/Role.java @@ -37,7 +37,6 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table;
@@ -47,7 +46,6 @@ import org.hibernate.annotations.CollectionOfElements; import org.jetbrains.annotations.NotNull;
import org.rhq.core.domain.auth.Subject; -import org.rhq.core.domain.auth.SubjectRoleEntity;
/** * A role has zero or more {@link org.rhq.core.domain.resource.group.ResourceGroup}s assigned to it. You can assign a @@ -106,11 +104,11 @@ public class Role implements Serializable { @Column(name = "FSYSTEM") private Boolean fsystem;
- @OneToMany(mappedBy = "role") - private java.util.Set<SubjectRoleEntity> roleSubjects; - @ManyToMany(mappedBy = "roles") - private Set<Subject> subjects = new HashSet<Subject>(); + private java.util.Set<Subject> subjects = new HashSet<Subject>(); + + @ManyToMany(mappedBy = "ldapRoles") + private java.util.Set<Subject> ldapSubjects = new HashSet<Subject>();
@ManyToMany(mappedBy = "roles") private java.util.Set<org.rhq.core.domain.resource.group.ResourceGroup> resourceGroups = new HashSet<org.rhq.core.domain.resource.group.ResourceGroup>(); @@ -183,52 +181,56 @@ public class Role implements Serializable { return this.permissions.remove(permission); }
- public Set<SubjectRoleEntity> getRoleSubjects() { - if (roleSubjects == null) { - roleSubjects = new HashSet<SubjectRoleEntity>(); - } - return roleSubjects; + public java.util.Set<Subject> getSubjects() { + return subjects; }
- public void setRoleSubjects(Set<SubjectRoleEntity> subjectsIn) { - roleSubjects = subjectsIn; + public void setSubjects(Set<Subject> subjects) { + this.subjects = subjects; }
- public java.util.Set<Subject> getSubjects() { - if (subjects == null) { - subjects = new HashSet<Subject>(); + public void addSubject(Subject subject) { + if (this.subjects == null) { + this.subjects = new HashSet<Subject>(); } - return subjects; + + subject.addRole(this); + this.subjects.add(subject); }
- public void setSubjects(Set<Subject> subjects) { - this.subjects = subjects; + public void removeSubject(Subject subject) { + if (this.subjects == null) { + this.subjects = new HashSet<Subject>(); + } + + subject.removeRole(this); + this.subjects.remove(subject); }
- public void addSubject(Subject subject, boolean ldap) { - SubjectRoleEntity s = new SubjectRoleEntity(); - s.setSubject(subject); - s.setRole(this); - s.setLdap(ldap); - getRoleSubjects().add(s); + public java.util.Set<Subject> getLdapSubjects() { + return ldapSubjects; }
- public void addSubject(Subject subject) { - addSubject(subject, false); + public void setLdapSubjects(Set<Subject> subjects) { + this.ldapSubjects = subjects; }
- public void removeSubject(Subject subject) { - SubjectRoleEntity toRemove = null; - for (SubjectRoleEntity s : getRoleSubjects()) { - if (s.getSubject().equals(subject) && s.getRole().equals(this)) { - toRemove = s; - break; - } + public void addLdapSubject(Subject subject) { + if (this.ldapSubjects == null) { + this.ldapSubjects = new HashSet<Subject>(); } - if (toRemove != null) { - getRoleSubjects().remove(toRemove); - subject.removeRole(this); + + subject.addLdapRole(this); + this.ldapSubjects.add(subject); + } + + public void removeLdapSubject(Subject subject) { + if (this.ldapSubjects == null) { + this.ldapSubjects = new HashSet<Subject>(); } + + subject.removeLdapRole(this); + this.ldapSubjects.remove(subject); }
public Set<org.rhq.core.domain.resource.group.ResourceGroup> getResourceGroups() {
commit 8d87c981864acc5720869f0f651c9890f8653b0b Author: Partha Aji paji@redhat.com Date: Wed Feb 24 19:05:22 2010 -0500
Initial commit for solution 2
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/authz-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/authz-schema.xml index dcb993b..1eaa6f8 100644 --- a/modules/core/dbutils/src/main/scripts/dbsetup/authz-schema.xml +++ b/modules/core/dbutils/src/main/scripts/dbsetup/authz-schema.xml @@ -82,4 +82,14 @@ </constraint> </table>
+ <table name="RHQ_SUBJECT_ROLE_LDAP_MAP"> + <column name="SUBJECT_ID" required="true" type="INTEGER" references="RHQ_SUBJECT"/> + <column name="ROLE_ID" required="true" type="INTEGER" references="RHQ_ROLE"/> + <constraint name="RHQ_SUBJECT_ROLE_LDAP_MAPPING_KEY"> + <primaryKey> + <field ref="SUBJECT_ID"/> + <field ref="ROLE_ID"/> + </primaryKey> + </constraint> + </table> </dbsetup>