ServiceUsersConfiguration.java 4.19 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.ConfigurationPolicy
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyUnbounded
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.repository.impl;

import java.util.Arrays;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=1, name="com.adobe.granite.repository.ServiceUserConfiguration", label="Adobe Granite Repository Service User Configuration", description="Configuration values associated with Service Users.", configurationFactory=1, policy=ConfigurationPolicy.REQUIRE)
@Service(value={ServiceUsersConfiguration.class})
@Properties(value={@Property(name="service.ranking", intValue={0}, propertyPrivate=0, label="Ranking", description="Configurations are processed in order of their ranking, a configuration with a higher ranking has precedence over a configuration with a lower ranking."), @Property(name="webconsole.configurationFactory.nameHint", value={"ServiceUserConfiguration: ranking: {service.ranking} simpleSubjectPopulation: {serviceusers.simpleSubjectPopulation} for service users: {serviceusers.list}"})})
public class ServiceUsersConfiguration
implements Comparable<ServiceUsersConfiguration> {
    @Property(label="Simple Subject Population", description="Determines whether the named service users are eligible for loginService or getServiceResourceResolver to avoid group membership lookups.", boolValue={0})
    private static final String PROP_SERVICEUSER_SIMPLE_SUBJECT_POPULATION = "serviceusers.simpleSubjectPopulation";
    private static final boolean PROP_SERVICEUSER_MAPPING_DEFAULT = false;
    @Property(label="Service Users", description="A list of the service users for whom the fast path should be enabled or disabled.", unbounded=PropertyUnbounded.ARRAY)
    private static final String PROP_SERVICEUSERS = "serviceusers.list";
    private static final String[] PROP_SERVICEUSERS_DEFAULT = new String[0];
    private final Logger logger;
    private boolean simpleSubjectPopulation;
    private String[] serviceUsers;
    private int serviceRanking;

    public ServiceUsersConfiguration() {
        this.logger = LoggerFactory.getLogger(this.getClass());
    }

    @Activate
    @Modified
    void configure(Map<String, Object> config) {
        this.simpleSubjectPopulation = PropertiesUtil.toBoolean((Object)config.get("serviceusers.simpleSubjectPopulation"), (boolean)false);
        this.serviceUsers = PropertiesUtil.toStringArray((Object)config.get("serviceusers.list"), (String[])PROP_SERVICEUSERS_DEFAULT);
        this.serviceRanking = PropertiesUtil.toInteger((Object)config.get("service.ranking"), (int)0);
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Rank: {} simpleSubjectPopulation: {} serviceUsers: {}", new Object[]{this.serviceRanking, this.simpleSubjectPopulation, Arrays.asList(this.serviceUsers)});
        }
    }

    public boolean getSimpleSubjectPopulation() {
        return this.simpleSubjectPopulation;
    }

    public String[] getServiceUsers() {
        return this.serviceUsers;
    }

    @Override
    public int compareTo(ServiceUsersConfiguration o) {
        if (this.serviceRanking > o.serviceRanking) {
            return -1;
        }
        if (this.serviceRanking < o.serviceRanking) {
            return 1;
        }
        return this.hashCode() < o.hashCode() ? -1 : 1;
    }
}