private Map<String, String> setHeaders(Configuration conf) { Map<String, String> xFrameParams = new HashMap<>(); Map<String, String> headerConfigMap = conf.getValByRegex(HTTP_HEADER_REGEX); xFrameParams.putAll(getDefaultHeaders()); if(this.xFrameOptionIsEnabled) { xFrameParams.put(HTTP_HEADER_PREFIX+X_FRAME_OPTIONS, this.xFrameOption.toString()); } xFrameParams.putAll(headerConfigMap); return xFrameParams; }
/** * We cannot use valueOf since the AllowFrom enum differs from its value * Allow-From. This is a helper method that does exactly what valueof does, * but allows us to handle the AllowFrom issue gracefully. * * @param value - String must be DENY, SAMEORIGIN or ALLOW-FROM. * @return XFrameOption or throws IllegalException. */ private static XFrameOption getEnum(String value) { Preconditions.checkState(value != null && !value.isEmpty()); for (XFrameOption xoption : values()) { if (value.equals(xoption.toString())) { return xoption; } } throw new IllegalArgumentException("Unexpected value in xFrameOption."); } }
/** * We cannot use valueOf since the AllowFrom enum differs from its value * Allow-From. This is a helper method that does exactly what valueof does, * but allows us to handle the AllowFrom issue gracefully. * * @param value - String must be DENY, SAMEORIGIN or ALLOW-FROM. * @return XFrameOption or throws IllegalException. */ private static XFrameOption getEnum(String value) { Preconditions.checkState(value != null && !value.isEmpty()); for (XFrameOption xoption : values()) { if (value.equals(xoption.toString())) { return xoption; } } throw new IllegalArgumentException("Unexpected value in xFrameOption."); } }
xFrameParams.put(X_FRAME_ENABLED, String.valueOf(this.xFrameOptionIsEnabled)); xFrameParams.put(X_FRAME_VALUE, this.xFrameOption.toString()); addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams); final FilterInitializer[] initializers = getFilterInitializers(conf);