View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.xml.security.credential.criteria;
18  
19  import org.opensaml.xml.security.credential.Credential;
20  import org.opensaml.xml.security.criteria.EntityIDCriteria;
21  import org.opensaml.xml.util.DatatypeHelper;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  /**
26   * Instance of evaluable credential criteria for evaluating a credential's entity ID.
27   */
28  public class EvaluableEntityIDCredentialCriteria implements EvaluableCredentialCriteria {
29  
30      /** Logger. */
31      private final Logger log = LoggerFactory.getLogger(EvaluableEntityIDCredentialCriteria.class);
32  
33      /** Base criteria. */
34      private String entityID;
35  
36      /**
37       * Constructor.
38       * 
39       * @param criteria the criteria which is the basis for evaluation
40       */
41      public EvaluableEntityIDCredentialCriteria(EntityIDCriteria criteria) {
42          if (criteria == null) {
43              throw new NullPointerException("Criteria instance may not be null");
44          }
45          entityID = criteria.getEntityID();
46      }
47  
48      /**
49       * Constructor.
50       * 
51       * @param newEntityID the criteria value which is the basis for evaluation
52       */
53      public EvaluableEntityIDCredentialCriteria(String newEntityID) {
54          if (DatatypeHelper.isEmpty(newEntityID)) {
55              throw new IllegalArgumentException("Entity ID may not be null");
56          }
57          entityID = newEntityID;
58      }
59  
60      /** {@inheritDoc} */
61      public Boolean evaluate(Credential target) {
62          if (target == null) {
63              log.error("Credential target was null");
64              return null;
65          }
66          if (DatatypeHelper.isEmpty(target.getEntityId())) {
67              log.info("Could not evaluate criteria, credential contained no entity ID");
68              return null;
69          }
70          Boolean result = entityID.equals(target.getEntityId());
71          return result;
72      }
73  
74  }