1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.principalConnector;
18
19 import java.sql.SQLException;
20
21 import org.opensaml.saml1.core.NameIdentifier;
22 import org.opensaml.saml2.core.NameID;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
27 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
28 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.StoredIDDataConnector;
29 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.StoredIDStore;
30 import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.dataConnector.StoredIDStore.PersistentIdEntry;
31 import edu.internet2.middleware.shibboleth.common.profile.provider.SAMLProfileRequestContext;
32
33
34
35
36 public class StoredIDPrincipalConnector extends BasePrincipalConnector {
37
38
39 private final Logger log = LoggerFactory.getLogger(StoredIDPrincipalConnector.class);
40
41
42 private StoredIDStore pidStore;
43
44
45
46
47
48
49 public StoredIDPrincipalConnector(StoredIDDataConnector idProducer) {
50 if (idProducer == null) {
51 throw new IllegalArgumentException("ID producing data connector may not be null");
52 }
53 pidStore = idProducer.getStoredIDStore();
54
55 }
56
57
58 public String resolve(ShibbolethResolutionContext resolutionContext) throws AttributeResolutionException {
59 SAMLProfileRequestContext requestContext = resolutionContext.getAttributeRequestContext();
60
61 String persistentId;
62 if (requestContext.getSubjectNameIdentifier() instanceof NameIdentifier) {
63 persistentId = ((NameIdentifier) requestContext.getSubjectNameIdentifier()).getNameIdentifier();
64 } else if (requestContext.getSubjectNameIdentifier() instanceof NameID) {
65 persistentId = ((NameID) requestContext.getSubjectNameIdentifier()).getValue();
66 } else {
67 throw new AttributeResolutionException("Subject name identifier is not of a supported type");
68 }
69
70 try {
71 PersistentIdEntry pidEntry = pidStore.getActivePersistentIdEntry(persistentId);
72 if(pidEntry != null){
73 return pidEntry.getPrincipalName();
74 }else{
75 return null;
76 }
77 } catch (SQLException e) {
78 log.error("Error retrieving persistent ID from database", e);
79 throw new AttributeResolutionException("Error retrieving persistent ID from database", e);
80 }
81 }
82
83
84 public void validate() throws AttributeResolutionException {
85 if(pidStore == null){
86 throw new AttributeResolutionException("Persistent ID store was null");
87 }
88
89 try{
90 pidStore.getPersistentIdEntry("test", false);
91 }catch(SQLException e){
92 throw new AttributeResolutionException("Persistent ID store can not perform persistent ID search", e);
93 }
94 }
95 }