Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 22AF8DFE5 for ; Fri, 14 Dec 2012 17:17:28 +0000 (UTC) Received: (qmail 81133 invoked by uid 500); 14 Dec 2012 17:17:27 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 81031 invoked by uid 500); 14 Dec 2012 17:17:27 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 81024 invoked by uid 99); 14 Dec 2012 17:17:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Dec 2012 17:17:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Dec 2012 17:17:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5A6DC23889B8; Fri, 14 Dec 2012 17:17:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121214171705.5A6DC23889B8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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(); + } } 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"; + } }