cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1421982 - in /cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security: Activator.java SampleSecurityFilter.java SecureRestEndpoint.java
Date Fri, 14 Dec 2012 17:17:04 GMT
Author: dkulp
Date: Fri Dec 14 17:17:02 2012
New Revision: 1421982

URL: http://svn.apache.org/viewvc?rev=1421982&view=rev
Log:
Cleanup security_filter sample

Modified:
    cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java
    cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java
    cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java

Modified: cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java?rev=1421982&r1=1421981&r2=1421982&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java
(original)
+++ cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java
Fri Dec 14 17:17:02 2012
@@ -1,20 +1,20 @@
-/** 
- * 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. 
+/**
+ * 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.cxf.dosgi.samples.security;
 
@@ -28,32 +28,37 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
 /**
- * Registers a REST endpoint and a servlet filter to control access to the endpoint.
+ * Registers a REST endpoint and a servlet filter to control access to the
+ * endpoint.
  */
 public class Activator implements BundleActivator {
-  private ServiceRegistration restRegistration;
-  private ServiceRegistration filterRegistration;
-  
-  @SuppressWarnings("unchecked")
-  public void start(BundleContext bundleContext) throws Exception {
-    // Register a rest endpoint
-    Dictionary restProps = new Hashtable();
-    restProps.put("service.exported.interfaces", SecureRestEndpoint.class.getName());
-    restProps.put("service.exported.configs", "org.apache.cxf.rs");
-    restProps.put("org.apache.cxf.rs.httpservice.context", "/secure");
-    restRegistration = bundleContext.registerService(SecureRestEndpoint.class.getName(),
new SecureRestEndpoint(), restProps);
-    
-    // Register a servlet filter (this could be done in another OSGi bundle, too)
-    Dictionary filterProps = new Hashtable();
-    filterProps.put("org.apache.cxf.httpservice.filter", Boolean.TRUE);
-    // Pax-Web whiteboard (if deployed) will attempt to apply this filter to servlets by
name or URL, and will complain
-    // if neither servletName or urlPatterns are specified.  The felix http service whiteboard
may do something similar.
-    filterProps.put("servletNames", "none");
-    filterRegistration = bundleContext.registerService(Filter.class.getName(), new SampleSecurityFilter(),
filterProps);
-  }
-  
-  public void stop(BundleContext bundleContext) throws Exception {
-    restRegistration.unregister();
-    filterRegistration.unregister();
-  }
+    private ServiceRegistration restRegistration;
+    private ServiceRegistration filterRegistration;
+
+    public void start(BundleContext bundleContext) throws Exception {
+        // Register a rest endpoint
+        Dictionary<String, Object> restProps = new Hashtable<String, Object>();
+        restProps.put("service.exported.interfaces", SecureRestEndpoint.class.getName());
+        restProps.put("service.exported.configs", "org.apache.cxf.rs");
+        restProps.put("org.apache.cxf.rs.httpservice.context", "/secure");
+        restRegistration = bundleContext.registerService(SecureRestEndpoint.class.getName(),
+                                                         new SecureRestEndpoint(), restProps);
+
+        // Register a servlet filter (this could be done in another OSGi bundle,
+        // too)
+        Dictionary<String, Object> filterProps = new Hashtable<String, Object>();
+        filterProps.put("org.apache.cxf.httpservice.filter", Boolean.TRUE);
+        // Pax-Web whiteboard (if deployed) will attempt to apply this filter to
+        // servlets by name or URL, and will complain
+        // if neither servletName or urlPatterns are specified. The felix http
+        // service whiteboard may do something similar.
+        filterProps.put("servletNames", "none");
+        filterRegistration = bundleContext.registerService(Filter.class.getName(),
+                                                           new SampleSecurityFilter(), filterProps);
+    }
+
+    public void stop(BundleContext bundleContext) throws Exception {
+        restRegistration.unregister();
+        filterRegistration.unregister();
+    }
 }

Modified: cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java?rev=1421982&r1=1421981&r2=1421982&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java
(original)
+++ cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java
Fri Dec 14 17:17:02 2012
@@ -1,20 +1,20 @@
-/** 
- * 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. 
+/**
+ * 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.cxf.dosgi.samples.security;
 
@@ -33,27 +33,28 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A filter that requires a query string of "secure" to invoke the protected resource.
+ * A filter that requires a query string of "secure" to invoke the protected
+ * resource.
  */
 public class SampleSecurityFilter implements Filter {
-  private static final Logger LOG = LoggerFactory.getLogger(SampleSecurityFilter.class);
+    private static final Logger LOG = LoggerFactory.getLogger(SampleSecurityFilter.class);
+
+    public void destroy() {
+        LOG.info("destroy()");
+    }
 
-  public void destroy() {
-    LOG.info("destroy()");
-  }
-
-  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException,
-          ServletException {
-    if("secure".equals(((HttpServletRequest)request).getQueryString())) {
-      LOG.info("Access granted");
-      chain.doFilter(request, response);
-    } else {
-      LOG.warn("Access denied");
-      ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN);
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws IOException, ServletException {
+        if ("secure".equals(((HttpServletRequest)request).getQueryString())) {
+            LOG.info("Access granted");
+            chain.doFilter(request, response);
+        } else {
+            LOG.warn("Access denied");
+            ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN);
+        }
     }
-  }
 
-  public void init(FilterConfig config) throws ServletException {
-    LOG.info("init()");
-  }
+    public void init(FilterConfig config) throws ServletException {
+        LOG.info("init()");
+    }
 }

Modified: cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java?rev=1421982&r1=1421981&r2=1421982&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java
(original)
+++ cxf/dosgi/trunk/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java
Fri Dec 14 17:17:02 2012
@@ -1,20 +1,20 @@
-/** 
- * 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. 
+/**
+ * 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.cxf.dosgi.samples.security;
 
@@ -26,10 +26,10 @@ import javax.ws.rs.core.MediaType;
 @Path("/")
 public class SecureRestEndpoint {
   
-  @GET
-  @Path("hello")
-  @Produces(MediaType.TEXT_PLAIN)
-  public String sayHello() {
-    return "Hello and congratulations, you made it past the security filter";
-  }
+    @GET
+    @Path("hello")
+    @Produces(MediaType.TEXT_PLAIN)
+    public String sayHello() {
+        return "Hello and congratulations, you made it past the security filter";
+    }
 }



Mime
View raw message