1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.saml.extraction;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.connectmgr.ConnectionManagerCache;
|
---|
8 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessEntity;
|
---|
9 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
10 | import gov.hhs.fha.nhinc.properties.PropertyAccessException;
|
---|
11 | import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
12 | import org.apache.commons.logging.Log;
|
---|
13 | import org.apache.commons.logging.LogFactory;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | *
|
---|
17 | * @author Jon Hoppesch
|
---|
18 | */
|
---|
19 | public class SamlTokenExtractorHelper {
|
---|
20 |
|
---|
21 | private static Log log = LogFactory.getLog(SamlTokenExtractorHelper.class);
|
---|
22 | public static final String INTERNAL_SUBJECT_DISCOVERY = "nhincsubjectdiscovery";
|
---|
23 | public static final String INTERNAL_DOC_QUERY = "nhincdocumentquery";
|
---|
24 | public static final String INTERNAL_DOC_RETRIEVE = "nhincdocumentretrieve";
|
---|
25 | public static final String INTERNAL_AUDIT_QUERY = "nhincauditquery";
|
---|
26 | public static final String INTERNAL_HIEM_SUBSCRIBE = "nhincnotificationproducer";
|
---|
27 | public static final String INTERNAL_HIEM_UNSUBSCRIBE = "nhincsubscriptionmanager";
|
---|
28 | public static final String INTERNAL_HIEM_NOTIFY = "nhincnotificationconsumer";
|
---|
29 |
|
---|
30 | public static String getHomeCommunityId(){
|
---|
31 | log.debug("Entering SamlTokenExtractorHelper.getHomeCommunityId");
|
---|
32 | String propFile = "gateway";
|
---|
33 | String propName = "localHomeCommunityId";
|
---|
34 | String homeCommunityId = "";
|
---|
35 | try {
|
---|
36 | homeCommunityId = PropertyAccessor.getProperty(propFile, propName);
|
---|
37 | } catch (PropertyAccessException ex) {
|
---|
38 | log.error("SamlTokenExtractorHelper.getHomeCommunityId failed to access property: " + ex.getMessage());
|
---|
39 | }
|
---|
40 |
|
---|
41 | log.debug("Exiting SamlTokenExtractorHelper.getHomeCommunityId: " + homeCommunityId);
|
---|
42 | return homeCommunityId;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public static String getEndpointURL(String homeCommunityId, String service) {
|
---|
46 | log.debug("Entering SamlTokenExtractorHelper.getEndpointURL");
|
---|
47 |
|
---|
48 | CMBusinessEntity oCMBusinessEntity = new CMBusinessEntity();
|
---|
49 | String url = null;
|
---|
50 |
|
---|
51 | if (NullChecker.isNotNullish(homeCommunityId) &&
|
---|
52 | NullChecker.isNotNullish(service)) {
|
---|
53 | try {
|
---|
54 | oCMBusinessEntity = ConnectionManagerCache.getBusinessEntityByServiceName(homeCommunityId, service);
|
---|
55 | } catch (Throwable t) {
|
---|
56 | log.error("Failed to retrieve business entity. Error: " + t.getMessage());
|
---|
57 | }
|
---|
58 |
|
---|
59 | if (oCMBusinessEntity != null &&
|
---|
60 | oCMBusinessEntity.getBusinessServices() != null &&
|
---|
61 | oCMBusinessEntity.getBusinessServices().getBusinessService() != null &&
|
---|
62 | oCMBusinessEntity.getBusinessServices().getBusinessService().size() > 0 &&
|
---|
63 | oCMBusinessEntity.getBusinessServices().getBusinessService().get(0) != null &&
|
---|
64 | oCMBusinessEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates() != null &&
|
---|
65 | oCMBusinessEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate() != null &&
|
---|
66 | oCMBusinessEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().size() > 0 &&
|
---|
67 | oCMBusinessEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0) != null &&
|
---|
68 | NullChecker.isNotNullish(oCMBusinessEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getEndpointURL())) {
|
---|
69 | url = oCMBusinessEntity.getBusinessServices().getBusinessService().get(0).getBindingTemplates().getBindingTemplate().get(0).getEndpointURL();
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (NullChecker.isNotNullish(url)) {
|
---|
73 | log.info("Returning URL: " + url);
|
---|
74 | } else {
|
---|
75 | log.error("Did not find a URL for home community id: " + homeCommunityId + " and service: " + service);
|
---|
76 | }
|
---|
77 | }
|
---|
78 | else {
|
---|
79 | log.error("A Null input parameter was passed to this method");
|
---|
80 | }
|
---|
81 |
|
---|
82 | log.debug("Exiting SamlTokenExtractorHelper.getEndpointURL");
|
---|
83 | return url;
|
---|
84 | }
|
---|
85 | }
|
---|