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.owasp.esapi.ESAPI;
26 import org.owasp.esapi.Encoder;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31
32
33
34
35
36
37
38
39
40 public class ServiceNameTag extends ServiceTagSupport {
41
42
43 private static final long serialVersionUID = 8883158293402992407L;
44
45 private static Logger log = LoggerFactory.getLogger(ServiceNameTag.class);
46
47
48 private static final String DEFAULT_VALUE = "Unspecified Service Provider";
49
50 @Override
51 public int doStartTag() throws JspException {
52
53 try {
54 String rawServiceName = getServiceName();
55
56 Encoder esapiEncoder = ESAPI.encoder();
57
58 String serviceName = esapiEncoder.encodeForHTML(rawServiceName);
59
60 if (null == serviceName) {
61 BodyContent bc = getBodyContent();
62 boolean written = false;
63 if (null != bc) {
64 JspWriter ew= bc.getEnclosingWriter();
65 if (ew != null) {
66 bc.writeOut(ew);
67 written = true;
68 }
69 }
70 if (!written) {
71 pageContext.getOut().print(DEFAULT_VALUE);
72 }
73 } else {
74 pageContext.getOut().print(serviceName);
75 }
76 } catch (IOException e) {
77 log.warn("Error generating name");
78 throw new JspException("StartTag", e);
79 }
80 return super.doStartTag();
81 }
82 }