1 17 18 19 20 package org.apache.lenya.ac.impl; 21 22 23 import java.util.HashSet ; 24 import java.util.Set ; 25 26 import org.apache.lenya.ac.Accreditable; 27 import org.apache.lenya.ac.Role; 28 29 30 33 public class Credential { 34 private Accreditable accreditable; 35 private Set roles = new HashSet (); 36 37 41 public Credential(Accreditable accreditable) { 42 setAccreditable(accreditable); 43 } 44 45 49 protected void setAccreditable(Accreditable accreditable) { 50 assert accreditable != null; 51 this.accreditable = accreditable; 52 } 53 54 59 public Role[] getRoles() { 60 return (Role[]) roles.toArray(new Role[roles.size()]); 61 } 62 63 67 public void addRole(Role role) { 68 assert role != null; 69 assert !roles.contains(role); 70 roles.add(role); 71 } 72 73 77 public void removeRole(Role role) { 78 assert role != null; 79 assert roles.contains(role); 80 roles.remove(role); 81 } 82 83 87 public Accreditable getAccreditable() { 88 return accreditable; 89 } 90 91 94 public String toString() { 95 return "[credential of: " + getAccreditable() + "]"; 96 } 97 98 103 public boolean contains(Role role) { 104 return roles.contains(role); 105 } 106 107 111 public boolean isEmpty() { 112 return roles.isEmpty(); 113 } 114 } 115 | Popular Tags |