1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.wayf;
18
19 import java.util.Comparator;
20 import java.util.List;
21 import java.util.Locale;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 import org.opensaml.saml2.metadata.EntityDescriptor;
26 import org.opensaml.saml2.metadata.Organization;
27 import org.opensaml.saml2.metadata.OrganizationDisplayName;
28 import org.opensaml.saml2.metadata.SingleSignOnService;
29
30
31
32
33
34
35
36 public class IdPSite {
37
38
39 private EntityDescriptor entity;
40
41
42 private String displayLanguage;
43
44
45
46
47
48 public IdPSite(EntityDescriptor entityParam) {
49 entity = entityParam;
50 }
51
52
53
54
55
56 public String getName() {
57 return entity.getEntityID();
58 }
59
60
61
62
63
64
65
66 public String getDisplayName(HttpServletRequest req) {
67
68
69
70 Locale locale = req.getLocale();
71 if (null == locale) {
72 Locale.getDefault();
73 }
74 String lang = locale.getLanguage();
75
76 return getDisplayName(lang);
77 }
78
79
80
81
82
83
84 private String getDisplayName(String lang) {
85 Organization org = entity.getOrganization();
86
87 if (org == null) {
88 return entity.getEntityID();
89 }
90
91 List<OrganizationDisplayName> list = org.getDisplayNames();
92
93
94
95
96
97 for (OrganizationDisplayName name:list) {
98 if (null !=name && lang.equals(name.getName().getLanguage())) {
99 return name.getName().getLocalString();
100 }
101 }
102
103
104
105
106
107 for (OrganizationDisplayName name:list) {
108 if (null !=name && null != name.getName().getLocalString()) {
109 return name.getName().getLocalString();
110 }
111 }
112
113
114
115
116 return entity.getEntityID();
117 }
118
119
120
121
122
123
124 public String getDisplayName() {
125 return getDisplayName(displayLanguage);
126 }
127
128
129
130
131
132
133
134 protected int compareTo(Object o, HttpServletRequest req) {
135
136
137 String myDisplayName;
138 String otherDisplayName;
139 IdPSite other;
140
141 if (equals(o)) {
142 return 0;
143 }
144
145 myDisplayName = getDisplayName(req);
146 if (null == myDisplayName) {
147 myDisplayName = "";
148 }
149
150 other = (IdPSite) o;
151 otherDisplayName = other.getDisplayName(req);
152 if (null == otherDisplayName) {
153 otherDisplayName = "";
154 }
155
156 int result = myDisplayName.toLowerCase().compareTo(otherDisplayName.toLowerCase());
157 if (result == 0) {
158 result = myDisplayName.compareTo(otherDisplayName);
159 }
160 return result;
161 }
162
163
164
165
166
167 public String getAddressForWAYF() {
168 List<SingleSignOnService> ssoList;
169
170 ssoList = entity.getIDPSSODescriptor(XMLConstants.SHIB_NS).getSingleSignOnServices();
171
172 for (SingleSignOnService signOnService: ssoList) {
173 if (XMLConstants.IDP_SSO_BINDING.equals(signOnService.getBinding())) {
174 return signOnService.getLocation();
175 }
176 }
177 return null;
178 }
179
180
181
182
183
184
185
186 public void setDisplayLanguage(String lang) {
187 this.displayLanguage = lang;
188 }
189
190 public static class Compare implements Comparator<IdPSite> {
191
192
193
194
195
196
197
198 private HttpServletRequest req = null;
199
200 private Compare() {
201
202
203 }
204
205 public Compare(HttpServletRequest req) {
206 this.req = req;
207 }
208
209 public int compare(IdPSite o1, IdPSite o2) {
210
211 return o1.compareTo(o2, req);
212 }
213
214 }
215
216 }
217