AuthHttpContext.java 3.36 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Deactivate
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.auth.core.AuthenticationSupport
 *  org.apache.sling.commons.mime.MimeTypeService
 *  org.osgi.service.http.HttpContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.crx.packmgr.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.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.auth.core.AuthenticationSupport;
import org.apache.sling.commons.mime.MimeTypeService;
import org.osgi.service.http.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=1)
@Service(value={HttpContext.class})
@Property(name="contextId", value={"com.day.crx.packmgr.impl.AuthHttpContext"})
public class AuthHttpContext
implements HttpContext {
    private static final Logger log = LoggerFactory.getLogger(AuthHttpContext.class);
    public static final String CONTEXT_ID = "com.day.crx.packmgr.impl.AuthHttpContext";
    @Reference
    private AuthenticationSupport authenticator = null;
    @Reference
    private MimeTypeService mimeTypeService = null;

    @Activate
    protected void activate() {
        if (this.authenticator == null) {
            log.error("Referenced Authentication Support is NULL");
        }
    }

    @Deactivate
    protected void deactivate() {
    }

    public String getMimeType(String name) {
        if (this.mimeTypeService == null) {
            log.error("MimeTypeService is NULL");
            return null;
        }
        return this.mimeTypeService.getMimeType(name);
    }

    public URL getResource(String name) {
        return null;
    }

    public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        AuthenticationSupport localAuthenticator = this.authenticator;
        if (localAuthenticator != null) {
            return localAuthenticator.handleSecurity(request, response);
        }
        response.sendError(503);
        response.flushBuffer();
        return false;
    }

    protected void bindAuthenticator(AuthenticationSupport authenticationSupport) {
        this.authenticator = authenticationSupport;
    }

    protected void unbindAuthenticator(AuthenticationSupport authenticationSupport) {
        if (this.authenticator == authenticationSupport) {
            this.authenticator = null;
        }
    }

    protected void bindMimeTypeService(MimeTypeService mimeTypeService) {
        this.mimeTypeService = mimeTypeService;
    }

    protected void unbindMimeTypeService(MimeTypeService mimeTypeService) {
        if (this.mimeTypeService == mimeTypeService) {
            this.mimeTypeService = null;
        }
    }
}