TSK-1521: regenerated equals() and hashcode() for our JAAS principles
+ removed the field `member` from GroupPrincipal since it was not used anymore.
This commit is contained in:
parent
e87de29761
commit
c4ee9901f9
|
|
@ -1,20 +1,15 @@
|
||||||
package pro.taskana.common.api.security;
|
package pro.taskana.common.api.security;
|
||||||
|
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.Collections;
|
import java.util.Objects;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/** Represents a group with a name and a set of members. */
|
/** Represents a group with a name. */
|
||||||
public class GroupPrincipal implements Principal {
|
public class GroupPrincipal implements Principal {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Set<Principal> members;
|
|
||||||
|
|
||||||
public GroupPrincipal(String name) {
|
public GroupPrincipal(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
members = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -22,24 +17,25 @@ public class GroupPrincipal implements Principal {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addMember(Principal user) {
|
@Override
|
||||||
return members.add(user);
|
public int hashCode() {
|
||||||
|
return Objects.hash(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeMember(Principal user) {
|
@Override
|
||||||
return members.remove(user);
|
public boolean equals(Object obj) {
|
||||||
}
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
public boolean isMember(Principal member) {
|
}
|
||||||
return members.contains(member);
|
if (!(obj instanceof GroupPrincipal)) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
public Enumeration<Principal> members() {
|
GroupPrincipal other = (GroupPrincipal) obj;
|
||||||
return Collections.enumeration(members);
|
return Objects.equals(name, other.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "GroupPrincipal [name=" + name + ", members=" + members + "]";
|
return "GroupPrincipal [name=" + name + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package pro.taskana.common.api.security;
|
package pro.taskana.common.api.security;
|
||||||
|
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents a user principal with a name. */
|
/** Represents a user with a name. */
|
||||||
public class UserPrincipal implements Principal {
|
public class UserPrincipal implements Principal {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
@ -16,8 +17,25 @@ public class UserPrincipal implements Principal {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof UserPrincipal)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UserPrincipal other = (UserPrincipal) obj;
|
||||||
|
return Objects.equals(name, other.name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "UserPrincipal [name= " + this.getName() + "]";
|
return "UserPrincipal [name=" + name + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue