XSSProtectionServiceImpl.java 2.2 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 */
package com.day.cq.xss.impl;

import com.adobe.granite.xss.XSSFilter;
import com.day.cq.xss.ProtectionContext;
import com.day.cq.xss.XSSProtectionException;
import com.day.cq.xss.XSSProtectionService;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;

@Deprecated
@Component
@Service(value={XSSProtectionService.class})
public class XSSProtectionServiceImpl
implements XSSProtectionService {
    @Reference
    private XSSFilter filter;

    @Override
    public void invalidatePolicy(String policyPath) {
    }

    @Override
    public String protectFromXSS(String src) throws XSSProtectionException {
        return this.filter.filter(src);
    }

    @Override
    public String protectFromXSS(String src, String policyPath) throws XSSProtectionException {
        return this.filter.filter(XSSFilter.DEFAULT_CONTEXT, src, policyPath);
    }

    private com.adobe.granite.xss.ProtectionContext getContext(ProtectionContext context) {
        if (context == ProtectionContext.HTML_HTML_CONTENT) {
            return com.adobe.granite.xss.ProtectionContext.HTML_HTML_CONTENT;
        }
        if (context == ProtectionContext.PLAIN_HTML_CONTENT) {
            return com.adobe.granite.xss.ProtectionContext.PLAIN_HTML_CONTENT;
        }
        return null;
    }

    @Override
    public String protectForContext(ProtectionContext context, String src, String policyPath) throws XSSProtectionException {
        return this.filter.filter(this.getContext(context), src, policyPath);
    }

    @Override
    public String protectForContext(ProtectionContext context, String src) throws XSSProtectionException {
        return this.filter.filter(this.getContext(context), src, null);
    }

    protected void bindFilter(XSSFilter xSSFilter) {
        this.filter = xSSFilter;
    }

    protected void unbindFilter(XSSFilter xSSFilter) {
        if (this.filter == xSSFilter) {
            this.filter = null;
        }
    }
}