Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1FD75200C00 for ; Wed, 18 Jan 2017 16:40:32 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1E546160B34; Wed, 18 Jan 2017 15:40:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 66539160B3A for ; Wed, 18 Jan 2017 16:40:31 +0100 (CET) Received: (qmail 23144 invoked by uid 500); 18 Jan 2017 15:40:30 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 23071 invoked by uid 99); 18 Jan 2017 15:40:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2017 15:40:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3FB3DDFA70; Wed, 18 Jan 2017 15:40:30 +0000 (UTC) From: m4rkmckenna To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #519: Add experimental CORS server support Content-Type: text/plain Message-Id: <20170118154030.3FB3DDFA70@git1-us-west.apache.org> Date: Wed, 18 Jan 2017 15:40:30 +0000 (UTC) archived-at: Wed, 18 Jan 2017 15:40:32 -0000 Github user m4rkmckenna commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/519#discussion_r96662638 --- Diff: rest/rest-resources/src/main/java/org/apache/brooklyn/rest/filter/CorsImplSupplierFilter.java --- @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.rest.filter; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.reflect.TypeToken; +import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.BrooklynFeatureEnablement; +import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.util.JavaGroovyEquivalents; +import org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.ext.Provider; +import java.util.Collections; +import java.util.List; + +/** + * @see BrooklynFeatureEnablement#FEATURE_CORS_CXF_PROPERTY + */ +@Provider +public class CorsImplSupplierFilter extends CrossOriginResourceSharingFilter { + public static final ConfigKey> ALLOWED_ORIGINS = ConfigKeys.newConfigKey(new TypeToken>() {}, + BrooklynFeatureEnablement.FEATURE_CORS_CXF_PROPERTY + ".allowedOrigins", + "List of allowed origins. Access-Control-Allow-Origin header will be returned to client if Origin header in request is matching exactly a value among the list allowed origins. " + + "If AllowedOrigins is empty or not specified then all origins are allowed. " + + "No wildcard allowed origins are supported.", + Collections.emptyList()); + private static final Logger LOGGER = LoggerFactory.getLogger(CorsImplSupplierFilter.class); + + private static final boolean brooklynFeatureEnabled = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_CORS_CXF_PROPERTY); + static { + if (brooklynFeatureEnabled) { + LOGGER.info("CORS brooklyn feature enabled."); + } + } + + @VisibleForTesting + public CorsImplSupplierFilter(@Nullable ManagementContext mgmt) { + setFindResourceMethod(false); + Preconditions.checkNotNull(mgmt,"ManagementContext should be suppplied to CORS filter."); + setAllowOrigins(JavaGroovyEquivalents.>elvis( + mgmt.getConfig().getConfig(ALLOWED_ORIGINS), Collections.emptyList())); --- End diff -- @bostko Please expose all configuration the filter provides as it is all needed See https://cxf.apache.org/javadoc/latest/org/apache/cxf/rs/security/cors/CrossOriginResourceSharingFilter.html --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---