1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.idp.ui;
18
19 import java.io.IOException;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.JspWriter;
23 import javax.servlet.jsp.tagext.BodyContent;
24
25 import org.opensaml.samlext.saml2mdui.PrivacyStatementURL;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30 public class ServicePrivacyURLTag extends ServiceTagSupport {
31
32
33 private static final long serialVersionUID = 1706444251504545781L;
34
35
36 private static Logger log = LoggerFactory.getLogger(ServicePrivacyURLTag.class);
37
38
39 private static String linkText;
40
41
42
43
44 public void setLinkText(String text) {
45 linkText = text;
46 }
47
48
49
50
51
52 private String getPrivacyURLFromUIIinfo() {
53 String lang = getBrowserLanguage();
54
55 if (getSPUIInfo() != null && getSPUIInfo().getPrivacyStatementURLs() != null) {
56 for (PrivacyStatementURL privacyURL:getSPUIInfo().getPrivacyStatementURLs()) {
57 if (log.isDebugEnabled()){
58 log.debug("Found PrivacyStatementURL in UIInfo, language=" + privacyURL.getXMLLang());
59 }
60 if (privacyURL.getXMLLang().equals(lang)) {
61
62
63
64 if (log.isDebugEnabled()){
65 log.debug("returning URL from UIInfo " + privacyURL.getURI().getLocalString());
66 }
67 return privacyURL.getURI().getLocalString();
68 }
69 }
70 if (log.isDebugEnabled()){
71 log.debug("No relevant PrivacyStatementURL in UIInfo");
72 }
73 }
74 return null;
75 }
76
77 @Override
78
79 public int doEndTag() throws JspException {
80
81 String privacyURL = getPrivacyURLFromUIIinfo();
82
83 try {
84 if (null == privacyURL) {
85 BodyContent bc = getBodyContent();
86 if (null != bc) {
87 JspWriter ew= bc.getEnclosingWriter();
88 if (ew != null) {
89 bc.writeOut(ew);
90 }
91 }
92 } else {
93 pageContext.getOut().print(buildHyperLink(privacyURL, linkText));
94 }
95 } catch (IOException e) {
96 log.warn("Error generating Description");
97 throw new JspException("EndTag", e);
98 }
99 return super.doEndTag();
100 }
101
102 }