From: Madhu Venugopal Date: Fri, 27 Sep 2013 17:46:25 +0000 (-0700) Subject: CORS support for ContainerManager Northbound APIs X-Git-Tag: releasepom-0.1.0~3^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c56d1b9358a17dbe9cabdbbeb446c2a70ef412fc CORS support for ContainerManager Northbound APIs Change-Id: Iec1f37a249f92e39ede1ff3796b8d88cd2f510f5 Signed-off-by: Madhu Venugopal --- diff --git a/opendaylight/northbound/containermanager/pom.xml b/opendaylight/northbound/containermanager/pom.xml index 74e4ed8cdc..493cfbab22 100644 --- a/opendaylight/northbound/containermanager/pom.xml +++ b/opendaylight/northbound/containermanager/pom.xml @@ -50,6 +50,7 @@ javax.xml.bind.annotation, javax.xml.bind, org.slf4j, + org.apache.catalina.filters, org.codehaus.jackson.jaxrs, !org.codehaus.enunciate.jaxrs @@ -96,5 +97,10 @@ com.sun.jersey.jersey-servlet 1.17-SNAPSHOT + + org.opendaylight.controller.thirdparty + org.apache.catalina.filters.CorsFilter + 7.0.42-SNAPSHOT + diff --git a/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java b/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java index e2e1a62325..77c3004c76 100644 --- a/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java +++ b/opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java @@ -72,9 +72,9 @@ public class ContainerManagerNorthbound { @Context public void setSecurityContext(SecurityContext context) { - Principal principal; - principal = context.getUserPrincipal(); - username = principal.getName(); + if (context != null && context.getUserPrincipal() != null) { + username = context.getUserPrincipal().getName(); + } } protected String getUserName() { diff --git a/opendaylight/northbound/containermanager/src/main/resources/WEB-INF/web.xml b/opendaylight/northbound/containermanager/src/main/resources/WEB-INF/web.xml index 6ace7ecaed..5e4ad4ea1a 100644 --- a/opendaylight/northbound/containermanager/src/main/resources/WEB-INF/web.xml +++ b/opendaylight/northbound/containermanager/src/main/resources/WEB-INF/web.xml @@ -16,10 +16,49 @@ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" JAXRSContainerManager /* + + CorsFilter + org.apache.catalina.filters.CorsFilter + + cors.allowed.origins + * + + + cors.allowed.methods + GET,POST,HEAD,OPTIONS,PUT + + + cors.allowed.headers + Content-Type,X-Requested-With,accept,authorization, origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers + + + cors.exposed.headers + Access-Control-Allow-Origin,Access-Control-Allow-Credentials + + + cors.support.credentials + true + + + cors.preflight.maxage + 10 + + + + CorsFilter + /* + + NB api /* + POST + GET + PUT + PATCH + DELETE + HEAD System-Admin