Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zti;
- import java.security.Principal;
- public class MyPrincipal implements Principal {
- private final String name;
- public MyPrincipal(String name) {
- if(name == null) {
- throw new IllegalArgumentException("name cannot be null!");
- }
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public String toString() {
- return "Principal with name: "+name;
- }
- public boolean equals(Object obj) {
- if(obj == null) return false;
- if(obj == this) return true;
- if(!(obj instanceof MyPrincipal)) return false;
- MyPrincipal another = (MyPrincipal) obj;
- return name.equals(another.getName());
- }
- public int hashCode() {
- return name.hashCode();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement