1 package info.magnolia.jaas.principal; 2 3 import info.magnolia.cms.security.auth.PrincipalCollection; 4 5 import java.security.Principal ; 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 import java.util.Iterator ; 9 10 import org.apache.commons.lang.StringUtils; 11 import org.apache.commons.lang.builder.ToStringBuilder; 12 import org.apache.commons.lang.builder.ToStringStyle; 13 14 15 19 public class PrincipalCollectionImpl implements PrincipalCollection { 20 21 24 private static final long serialVersionUID = 222L; 25 26 private static final String NAME = "PrincipalCollection"; 27 28 31 private Collection collection = new ArrayList (); 32 33 private String name; 34 35 39 public String getName() { 40 if (StringUtils.isEmpty(this.name)) { 41 return NAME; 42 } 43 return this.name; 44 } 45 46 49 public void setName(String name) { 50 this.name = name; 51 } 52 53 57 public void set(Collection collection) { 58 this.collection = collection; 59 } 60 61 65 public void add(Principal principal) { 66 this.collection.add(principal); 67 } 68 69 73 public void remove(Principal principal) { 74 this.collection.remove(principal); 75 } 76 77 80 public void clearAll() { 81 this.collection.clear(); 82 } 83 84 89 public boolean contains(Principal principal) { 90 return this.collection.contains(principal); 91 } 92 93 98 public boolean contains(String name) { 99 return this.get(name) != null; 100 } 101 102 107 public Principal get(String name) { 108 Iterator principalIterator = this.collection.iterator(); 109 while (principalIterator.hasNext()) { 110 Principal principal = (Principal ) principalIterator.next(); 111 if (StringUtils.equalsIgnoreCase(name, principal.getName())) { 112 return principal; 113 } 114 } 115 return null; 116 } 117 118 121 public String toString() { 122 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("name", this.name).toString(); 123 } 124 } 125 | Popular Tags |