1 package no.feide.mellon.jaas.principals; 2 3 import java.util.Iterator; 4 5 import javax.security.auth.Subject; 6 7 import com.sun.security.auth.PrincipalComparator; 8 9 10 /*** 11 * A special principal for the eduPersonScopedAffiliation attribute in FEIDE 12 * <br><br> 13 * Note that no subject will have any ScopedAffiliationPrincipals, only MoriaPrincipals. 14 * An ScopedAffiliationPrincipal implies a MoriaPrincipal with <code>attributeName</code> "eduPersonScopedAffiliation" 15 * and the sufficient attribute value. See the <code>implies</code> method. 16 * 17 * ScopedAffiliationPrincipals are only used in the policy file. In the policy file it cannot 18 * be replaced by the corresponding MoriaPrincipal if you want to make use of wildcards. 19 * 20 * @author Rikke Amilde Løvlid 21 */ 22 public class ScopedAffiliationPrincipal extends MoriaPrincipal implements PrincipalComparator{ 23 24 /*** 25 * @param name the attribute value of the eduPersonScopedAffiliation attribute in FEIDE. 26 * It is on the form x@y where x may be replaced by a wildcard. 27 */ 28 public ScopedAffiliationPrincipal(String name){ 29 super("eduPersonScopedAffiliation", name); 30 } 31 32 /*** 33 * ScopedAffiliationPrincipal implies the Subject subject if the subject has a MoriaPrincipal 34 * with attributeName "eduPersonScopedAffiliation" (this.attributeName is "eduPersonScopedAffiliation") 35 * and an attributeValue which is implied by the attributeValue belonging to this ScopedAffiliationPrincipal. 36 */ 37 public boolean implies(Subject subject){ 38 Iterator it = subject.getPrincipals(MoriaPrincipal.class).iterator(); 39 while(it.hasNext()){ 40 MoriaPrincipal mp = (MoriaPrincipal)it.next(); 41 if(mp.getAttributeName().equals(this.attributeName) && implies(this.attributeValue, mp.getAttributeValue())){ 42 return true; 43 } 44 } 45 return false; 46 } 47 48 /*** 49 * @param string1 this objects attribute value. It is on the form a@b 50 * @param string2 the attribute value we vant to know wether is implied by string1 or not. It is on the form c@d 51 * 52 * The "a" in string1 may be a wildcard, "*". 53 * string1 implies string2 if they are equal or "a" is a wildcard and b and d are equal. 54 * 55 * @return whether string1 implies string2 56 */ 57 public boolean implies(String string1, String string2){ 58 if(string1.indexOf("*")!=0){ 59 return string1.equals(string2); 60 } 61 if(string1.indexOf("@")==1 && 62 string1.substring(2).equals(string2.substring(string2.indexOf("@")+1))){ 63 return true; 64 } 65 return false; 66 67 } 68 }