View Javadoc

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.opensaml.samlext.saml2mdui.PrivacyStatementURL;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  /** Service PrivacyURL - directly from the metadata if present.*/
31  public class ServicePrivacyURLTag extends ServiceTagSupport {
32  
33      /** checkstyle needs serial version UID. */
34      private static final long serialVersionUID = 1706444251504545781L;
35      
36      /** Class logger. */
37      private static Logger log = LoggerFactory.getLogger(ServicePrivacyURLTag.class);
38  
39      /** Bean storage for the link text attribute. */
40      private static String linkText;
41      
42      /** Bean setter  for the link text attribute.
43       * @param text the link text to put in
44       */
45      public void setLinkText(String text) {
46          linkText = text;
47      }
48      
49      /**
50       * look for the <PrivacyURL> in the <UIInfo>.
51       * @return null or an appropriate string.
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                      // Found it
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 }