View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.config;
21  
22  import org.apache.myfaces.tobago.context.Theme;
23  import org.apache.myfaces.tobago.internal.config.ContentSecurityPolicy;
24  import org.apache.myfaces.tobago.internal.config.SecurityAnnotation;
25  import org.apache.myfaces.tobago.sanitizer.Sanitizer;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.enterprise.inject.spi.CDI;
30  import javax.faces.context.FacesContext;
31  import javax.servlet.ServletContext;
32  import java.util.List;
33  import java.util.Map;
34  
35  public abstract class TobagoConfig {
36  
37    private static final Logger LOG = LoggerFactory.getLogger(TobagoConfig.class);
38  
39    /**
40     * @deprecated Since 5.0.0. Please use CDI.
41     */
42    @Deprecated
43    public static final String TOBAGO_CONFIG = "org.apache.myfaces.tobago.config.TobagoConfig";
44  
45    /**
46     * @deprecated Since 5.0.0. Please use CDI.
47     */
48    @Deprecated
49    public static TobagoConfig getInstance(final FacesContext facesContext) {
50      TobagoConfig tobagoConfig = null;
51      try {
52        tobagoConfig = CDI.current().select(TobagoConfig.class).get();
53      } catch (Exception e) {
54        LOG.warn("No CDI!");
55      }
56      if (tobagoConfig != null) {
57        return tobagoConfig;
58      } else {
59        // XXX not nice: this happens while unit tests and whenever???
60        return (TobagoConfig) facesContext.getExternalContext().getApplicationMap().get(TOBAGO_CONFIG);
61      }
62    }
63  
64    /**
65     * @deprecated Since 5.0.0. Please use CDI.
66     */
67    @Deprecated
68    public static TobagoConfig getInstance(final ServletContext servletContext) {
69      return CDI.current().select(TobagoConfig.class).get();
70    }
71  
72    public abstract Theme getTheme(final String name);
73  
74    public abstract List<Theme> getSupportedThemes();
75  
76    public abstract Theme getDefaultTheme();
77  
78    public abstract boolean isCreateSessionSecret();
79  
80    public abstract boolean isCheckSessionSecret();
81  
82    /**
83     * @deprecated But needed to support frame security in IE11. Is replaced by CSP "frame-ancestors".
84     */
85    @Deprecated
86    public abstract boolean isPreventFrameAttacks();
87  
88    public abstract ContentSecurityPolicy getContentSecurityPolicy();
89  
90    public abstract boolean isSetNosniffHeader();
91  
92    public abstract SecurityAnnotation getSecurityAnnotation();
93  
94    public abstract Sanitizer getSanitizer();
95  
96    public abstract boolean isDecodeLineFeed();
97  
98    public abstract Map<String, String> getMimeTypes();
99  }