1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.xml.security.credential.criteria;
18
19 import java.security.PublicKey;
20
21 import org.opensaml.xml.security.credential.Credential;
22 import org.opensaml.xml.security.criteria.PublicKeyCriteria;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27
28
29
30 public class EvaluablePublicKeyCredentialCriteria implements EvaluableCredentialCriteria {
31
32
33 private final Logger log = LoggerFactory.getLogger(EvaluablePublicKeyCredentialCriteria.class);
34
35
36 private PublicKey publicKey;
37
38
39
40
41
42
43 public EvaluablePublicKeyCredentialCriteria(PublicKeyCriteria criteria) {
44 if (criteria == null) {
45 throw new NullPointerException("Criteria instance may not be null");
46 }
47 publicKey = criteria.getPublicKey();
48 }
49
50
51
52
53
54
55 public EvaluablePublicKeyCredentialCriteria(PublicKey newPublicKey) {
56 if (newPublicKey == null) {
57 throw new IllegalArgumentException("Public key may not be null");
58 }
59 publicKey = newPublicKey;
60 }
61
62
63 public Boolean evaluate(Credential target) {
64 if (target == null) {
65 log.error("Credential target was null");
66 return null;
67 }
68 PublicKey key = target.getPublicKey();
69 if (key == null) {
70 log.info("Credential contained no public key, does not satisfy public key criteria");
71 return Boolean.FALSE;
72 }
73
74 Boolean result = publicKey.equals(key);
75 return result;
76 }
77
78 }