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