1 /*
2 * Licensed to the University Corporation for Advanced Internet Development,
3 * Inc. (UCAID) under one or more contributor license agreements. See the
4 * NOTICE file distributed with this work for additional information regarding
5 * copyright ownership. The UCAID licenses this file to You under the Apache
6 * License, Version 2.0 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
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 * Display the serviceName.
34 *
35 * This is taken in order
36 * 1) From the mdui
37 * 2) AttributeConsumeService
38 * 3) HostName from the EntityId
39 * 4) EntityId.
40 */
41 public class ServiceNameTag extends ServiceTagSupport {
42
43 /** checkstyle requires one of these. */
44 private static final long serialVersionUID = 8883158293402992407L;
45 /** Class logger. */
46 private static Logger log = LoggerFactory.getLogger(ServiceNameTag.class);
47
48 /** what to emit if the jsp has nothing. */
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 }