001/** 002 * Copyright 2011-2013 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016package org.kuali.mobility.security.authz.expression; 017 018import java.util.Iterator; 019import java.util.Set; 020 021import org.kuali.mobility.security.authn.entity.User; 022 023public class PersonAttributeExpression implements Expression { 024 025 private static final long serialVersionUID = 4461424607920854636L; 026 027 private String key; 028 029 private String value; 030 031 public PersonAttributeExpression(String key, String value) { 032 this.key = key; 033 this.value = value; 034 } 035 036 public boolean evaluate(User user) { 037 Set<String> attributes = user.getPersonAttributes().getAttribute(key); 038 if (attributes != null) { 039 for (Iterator<String> iter = attributes.iterator(); iter.hasNext();) { 040 String attribute = iter.next(); 041 if (attribute != null && attribute.equalsIgnoreCase(value)) { 042 return true; 043 } 044 } 045 } 046 return false; 047 } 048 049 public String getKey() { 050 return key; 051 } 052 053 public String getValue() { 054 return value; 055 } 056 057 @Override 058 public boolean equals(Object obj) { 059 if (obj instanceof PersonAttributeExpression) { 060 PersonAttributeExpression other = (PersonAttributeExpression)obj; 061 return key.equals(other.key) && value.equals(other.value); 062 } 063 return false; 064 } 065 066}