1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.idp.profile.saml1;
18
19 import java.util.List;
20
21 import org.opensaml.common.binding.BasicEndpointSelector;
22 import org.opensaml.saml2.metadata.Endpoint;
23 import org.opensaml.xml.util.DatatypeHelper;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27
28
29
30
31
32 public class ShibbolethSSOEndpointSelector extends BasicEndpointSelector {
33
34
35 private final Logger log = LoggerFactory.getLogger(ShibbolethSSOEndpointSelector.class);
36
37
38 private String spAssertionConsumerService;
39
40
41
42
43
44
45 public String getSpAssertionConsumerService() {
46 return spAssertionConsumerService;
47 }
48
49
50
51
52
53
54 public void setSpAssertionConsumerService(String acs) {
55 spAssertionConsumerService = DatatypeHelper.safeTrimOrNullString(acs);
56 }
57
58
59 public Endpoint selectEndpoint() {
60 if (getEntityRoleMetadata() == null) {
61 log.debug("Unable to select endpoint, no entity role metadata available.");
62 return null;
63 }
64
65 if (spAssertionConsumerService != null) {
66 return selectEndpointByACS();
67 } else {
68 return super.selectEndpoint();
69 }
70 }
71
72
73
74
75
76
77 protected Endpoint selectEndpointByACS() {
78 log.debug("Selecting endpoint from metadata corresponding to provided ACS URL: '{}'",
79 getSpAssertionConsumerService());
80
81 List<Endpoint> endpoints = getEntityRoleMetadata().getEndpoints();
82 log.debug("Relying party role contains '{}' endpoints", endpoints.size());
83
84 if (endpoints != null && endpoints.size() > 0) {
85 for (Endpoint endpoint : endpoints) {
86 if (endpoint == null || !getSupportedIssuerBindings().contains(endpoint.getBinding())) {
87 continue;
88 }
89
90 if (endpoint.getLocation().equalsIgnoreCase(spAssertionConsumerService)) {
91 return endpoint;
92 }
93
94 if (!DatatypeHelper.isEmpty(endpoint.getResponseLocation())
95 && endpoint.getResponseLocation().equalsIgnoreCase(spAssertionConsumerService)) {
96 return endpoint;
97 }
98 }
99 }
100
101 log.debug("No endpoint meets selection criteria for SAML entity '{}'", getEntityMetadata().getEntityID());
102 return null;
103 }
104 }