Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-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 79E1F9245 for ; Thu, 5 Jan 2012 13:01:05 +0000 (UTC) Received: (qmail 97051 invoked by uid 500); 5 Jan 2012 13:01:05 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 96971 invoked by uid 500); 5 Jan 2012 13:01:04 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 96957 invoked by uid 99); 5 Jan 2012 13:01:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 13:01:02 +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; Thu, 05 Jan 2012 13:00:58 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 76C7E2388AA9; Thu, 5 Jan 2012 13:00:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1227578 - in /sling/whiteboard/fmeschbe/httpcontext: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/extensions/ src/main/java/org/apache/sling/ex... Date: Thu, 05 Jan 2012 13:00:36 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120105130036.76C7E2388AA9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmeschbe Date: Thu Jan 5 13:00:35 2012 New Revision: 1227578 URL: http://svn.apache.org/viewvc?rev=1227578&view=rev Log: Sample of a shared HttpContext service Added: sling/whiteboard/fmeschbe/httpcontext/ sling/whiteboard/fmeschbe/httpcontext/pom.xml sling/whiteboard/fmeschbe/httpcontext/src/ sling/whiteboard/fmeschbe/httpcontext/src/main/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/impl/ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/impl/SlingHttpContext.java Added: sling/whiteboard/fmeschbe/httpcontext/pom.xml URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/httpcontext/pom.xml?rev=1227578&view=auto ============================================================================== --- sling/whiteboard/fmeschbe/httpcontext/pom.xml (added) +++ sling/whiteboard/fmeschbe/httpcontext/pom.xml Thu Jan 5 13:00:35 2012 @@ -0,0 +1,108 @@ + + + + + 4.0.0 + + org.apache.sling + sling + 12 + + + + org.apache.sling.extensions.httpcontext + 0.0.1-SNAPSHOT + bundle + + Apache Sling shared HttpContext + + Provides an OSGi HttpContext service implementing authentication + based on Sling Authentication and MIME type resolution based + on Sling MimeTypeService. + + + + + **.impl.** + + + + scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/fmeschbe/httpcontext + scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/fmeschbe/httpcontext + http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/httpcontext + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + + + + + + + org.osgi + org.osgi.core + + + org.osgi + org.osgi.compendium + + + org.apache.sling + org.apache.sling.auth.core + 1.0.4 + provided + + + org.apache.sling + org.apache.sling.commons.mime + 2.1.2 + provided + + + + + javax.servlet + servlet-api + + + org.slf4j + slf4j-api + + + org.apache.felix + org.apache.felix.scr.annotations + + + junit + junit + + + Added: sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/impl/SlingHttpContext.java URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/impl/SlingHttpContext.java?rev=1227578&view=auto ============================================================================== --- sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/impl/SlingHttpContext.java (added) +++ sling/whiteboard/fmeschbe/httpcontext/src/main/java/org/apache/sling/extensions/httpcontext/impl/SlingHttpContext.java Thu Jan 5 13:00:35 2012 @@ -0,0 +1,91 @@ +/* + * 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.sling.extensions.httpcontext.impl; + +import java.io.IOException; +import java.net.URL; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferencePolicy; +import org.apache.felix.scr.annotations.Service; +import org.apache.sling.auth.core.AuthenticationSupport; +import org.apache.sling.commons.mime.MimeTypeService; +import org.osgi.framework.Constants; +import org.osgi.service.http.HttpContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component +@Service +@Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Apache Sling shared OSGi HttpContext"), + @Property(name = "contextId", value = "sling.httpcontext"), + @Property(name = "context.shared", boolValue = true) }) +public class SlingHttpContext implements HttpContext { + + /** default log */ + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Reference(policy = ReferencePolicy.DYNAMIC) + private AuthenticationSupport authenticator; + + @Reference(policy = ReferencePolicy.DYNAMIC) + private MimeTypeService mimeTypeService; + + public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException { + + final AuthenticationSupport localAuthenticator = this.authenticator; + if (localAuthenticator != null) { + return localAuthenticator.handleSecurity(request, response); + } + + log.error("handleSecurity: Sling AuthenticationSupport service is not available; not ready to serve requests"); + + // send 503/SERVICE UNAVAILABLE, flush to ensure delivery + response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); + response.flushBuffer(); + + // terminate this request now + return false; + } + + public URL getResource(String name) { + // we don't serve resources for now .... + return null; + } + + public String getMimeType(String name) { + MimeTypeService mts = this.mimeTypeService; + if (mts != null) { + final String type = mts.getMimeType(name); + log.debug("getMimeType({}) -> {}", name, type); + return type; + } + + // no MimeTypeService + log.debug("getMimeType({}) -> null (Sling MimeType service is not available)", name); + return null; + } + +}