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