Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.engine.impl;
 
 import java.net.URL;
 import java.util.Map;
 
 
 import  org.osgi.service.http.HttpContext;
The SlingHttpContext implements the OSGi HttpContext used to register the SlingMainServlet with the OSGi HttpService.
 
 class SlingHttpContext implements HttpContext {

    
default log
 
     private static final Logger log = LoggerFactory.getLogger(SlingHttpContext.class);

    
Resolves MIME types

See also:
getMimeType(String)
 
     private MimeTypeService mimeTypeService;

    
Handles security

See also:
handleSecurity(HttpServletRequest, HttpServletResponse)
 
 
     public void setMimeTypeService(MimeTypeService mimeTypeService) {
         this. = mimeTypeService;
     }
 
     public void unsetMimeTypeService(MimeTypeService mimeTypeService) {
         if (this. == mimeTypeService) {
             this. = null;
         }
     }
 
     public void setAuthenticationSupport(
             AuthenticationSupport authenticationSupport) {
         this. = authenticationSupport;
     }
 
     public void unsetAuthenticationSupport(
             AuthenticationSupport authenticationSupport) {
         if (this. == authenticationSupport) {
             this. = null;
         }
     }
 
     // ---------- HttpContext interface ----------------------------------------
 
    
Returns the MIME type as resolved by the MimeTypeService or null if the service is not available.
 
     public String getMimeType(String name) {
         MimeTypeService mtservice = ;
         if (mtservice != null) {
             return mtservice.getMimeType(name);
         }
 
         .debug(
             "getMimeType: MimeTypeService not available, cannot resolve mime type for {}",
             name);
         return null;
     }

    
Always returns null because resources are all provided through the SlingMainServlet.
    public URL getResource(String name) {
        return null;
    }

    
Tries to authenticate the request using the SlingAuthenticator. If the authenticator or the Repository is missing this method returns false and sends a 503/SERVICE UNAVAILABLE status back to the client.
    public boolean handleSecurity(HttpServletRequest request,
            HttpServletResponse responsethrows IOException {
        final AuthenticationSupport authenticator = this.;
        if (authenticator != null) {
            // SLING-559: ensure correct parameter handling according to
            // ParameterSupport
            request = new HttpServletRequestWrapper(request) {
                @Override
                public String getParameter(String name) {
                    return getParameterSupport().getParameter(name);
                }
                @Override
                public Map<StringString[]> getParameterMap() {
                    return getParameterSupport().getParameterMap();
                }
                @Override
                public Enumeration<StringgetParameterNames() {
                    return getParameterSupport().getParameterNames();
                }
                @Override
                public String[] getParameterValues(String name) {
                    return getParameterSupport().getParameterValues(name);
                }
                private ParameterSupport getParameterSupport() {
                    return ParameterSupport.getInstance(getRequest());
                }
            };
            return authenticator.handleSecurity(requestresponse);
        }
        .error("handleSecurity: AuthenticationSupport service missing. Cannot authenticate request.");
        .error("handleSecurity: Possible reason is missing Repository service. Check AuthenticationSupport dependencies.");
        // send 503/SERVICE UNAVAILABLE, flush to ensure delivery
            "AuthenticationSupport service missing. Cannot authenticate request.");
        response.flushBuffer();
        // terminate this request now
        return false;
    }
New to GrepCode? Check out our FAQ X