brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #519: Add experimental CORS server support
Date Thu, 19 Jan 2017 09:06:56 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/519#discussion_r96816167
  
    --- 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<List<String>> ALLOWED_ORIGINS = ConfigKeys.newConfigKey(new
TypeToken<List<String>>() {},
    +            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.<String>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.<List<String>>elvis(
    +                mgmt.getConfig().getConfig(ALLOWED_ORIGINS), Collections.<String>emptyList()));
    --- End diff --
    
    If we start supporting all config options of the filter, then I could see this being its
own PID.


---
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.
---

Mime
View raw message