SlingRepositoryManager.java 25.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.license.ProductInfoService
 *  com.day.crx.CRXRepository
 *  com.google.common.collect.Lists
 *  javax.annotation.Nonnull
 *  javax.jcr.Credentials
 *  javax.jcr.Repository
 *  javax.jcr.RepositoryException
 *  javax.jcr.security.AccessControlManager
 *  javax.jcr.security.AccessControlPolicy
 *  javax.jcr.security.AccessControlPolicyIterator
 *  javax.jcr.security.Privilege
 *  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.ReferencePolicy
 *  org.apache.felix.scr.annotations.ReferencePolicyOption
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.jackrabbit.api.JackrabbitRepository
 *  org.apache.jackrabbit.api.management.RepositoryManager
 *  org.apache.jackrabbit.api.security.JackrabbitAccessControlList
 *  org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils
 *  org.apache.jackrabbit.oak.Oak
 *  org.apache.jackrabbit.oak.api.CommitFailedException
 *  org.apache.jackrabbit.oak.api.ContentRepository
 *  org.apache.jackrabbit.oak.api.ContentSession
 *  org.apache.jackrabbit.oak.api.Root
 *  org.apache.jackrabbit.oak.namepath.NamePathMapper
 *  org.apache.jackrabbit.oak.osgi.OsgiWhiteboard
 *  org.apache.jackrabbit.oak.plugins.atomic.AtomicCounterEditorProvider
 *  org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider
 *  org.apache.jackrabbit.oak.plugins.commit.JcrConflictHandler
 *  org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider
 *  org.apache.jackrabbit.oak.plugins.index.aggregate.NodeAggregator
 *  org.apache.jackrabbit.oak.plugins.index.aggregate.SimpleNodeAggregator
 *  org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider
 *  org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider
 *  org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider
 *  org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent
 *  org.apache.jackrabbit.oak.plugins.observation.CommitRateLimiter
 *  org.apache.jackrabbit.oak.plugins.version.VersionEditorProvider
 *  org.apache.jackrabbit.oak.spi.commit.CommitHook
 *  org.apache.jackrabbit.oak.spi.commit.ConflictHandler
 *  org.apache.jackrabbit.oak.spi.commit.EditorHook
 *  org.apache.jackrabbit.oak.spi.commit.EditorProvider
 *  org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer
 *  org.apache.jackrabbit.oak.spi.query.QueryIndexProvider
 *  org.apache.jackrabbit.oak.spi.security.SecurityProvider
 *  org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject
 *  org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration
 *  org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal
 *  org.apache.jackrabbit.oak.spi.state.NodeStore
 *  org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard
 *  org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardIndexEditorProvider
 *  org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardIndexProvider
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.apache.sling.commons.threads.ThreadPool
 *  org.apache.sling.commons.threads.ThreadPoolManager
 *  org.apache.sling.discovery.InstanceDescription
 *  org.apache.sling.discovery.TopologyEvent
 *  org.apache.sling.discovery.TopologyEventListener
 *  org.apache.sling.discovery.TopologyView
 *  org.apache.sling.jcr.api.NamespaceMapper
 *  org.apache.sling.jcr.api.SlingRepository
 *  org.apache.sling.jcr.base.AbstractSlingRepository2
 *  org.apache.sling.jcr.base.AbstractSlingRepositoryManager
 *  org.apache.sling.serviceusermapping.ServiceUserMapper
 *  org.apache.sling.settings.SlingSettingsService
 *  org.osgi.framework.Bundle
 *  org.osgi.framework.BundleContext
 *  org.osgi.framework.ServiceRegistration
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.repository.impl;

import com.adobe.granite.license.ProductInfoService;
import com.adobe.granite.repository.impl.CRX3RepositoryImpl;
import com.adobe.granite.repository.impl.GraniteContent;
import com.adobe.granite.repository.impl.IndexPropertyUtil;
import com.adobe.granite.repository.impl.ServiceUsersConfigurationManager;
import com.adobe.granite.repository.impl.SlingRepositoryImpl;
import com.day.crx.CRXRepository;
import com.day.crx.sling.server.impl.jmx.ProgressLogger;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
import java.security.Principal;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Dictionary;
import java.util.List;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
import javax.jcr.Credentials;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.AccessControlPolicy;
import javax.jcr.security.AccessControlPolicyIterator;
import javax.jcr.security.Privilege;
import javax.security.auth.Subject;
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.ReferencePolicy;
import org.apache.felix.scr.annotations.ReferencePolicyOption;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.JackrabbitRepository;
import org.apache.jackrabbit.api.management.RepositoryManager;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.ContentSession;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard;
import org.apache.jackrabbit.oak.plugins.atomic.AtomicCounterEditorProvider;
import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
import org.apache.jackrabbit.oak.plugins.commit.JcrConflictHandler;
import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
import org.apache.jackrabbit.oak.plugins.index.aggregate.NodeAggregator;
import org.apache.jackrabbit.oak.plugins.index.aggregate.SimpleNodeAggregator;
import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
import org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider;
import org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider;
import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
import org.apache.jackrabbit.oak.plugins.observation.CommitRateLimiter;
import org.apache.jackrabbit.oak.plugins.version.VersionEditorProvider;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
import org.apache.jackrabbit.oak.spi.commit.EditorHook;
import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject;
import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration;
import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardIndexEditorProvider;
import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardIndexProvider;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.commons.threads.ThreadPool;
import org.apache.sling.commons.threads.ThreadPoolManager;
import org.apache.sling.discovery.InstanceDescription;
import org.apache.sling.discovery.TopologyEvent;
import org.apache.sling.discovery.TopologyEventListener;
import org.apache.sling.discovery.TopologyView;
import org.apache.sling.jcr.api.NamespaceMapper;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.base.AbstractSlingRepository2;
import org.apache.sling.jcr.base.AbstractSlingRepositoryManager;
import org.apache.sling.serviceusermapping.ServiceUserMapper;
import org.apache.sling.settings.SlingSettingsService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate=1)
@Service(value={TopologyEventListener.class})
public class SlingRepositoryManager
extends AbstractSlingRepositoryManager
implements TopologyEventListener {
    public static final String FULLTEXT_ASYNC = "fulltext-async";
    private static final Logger log = LoggerFactory.getLogger(SlingRepositoryManager.class);
    private static final int DEFAULT_OBSERVATION_QUEUE_LENGTH = 1000;
    private static final boolean DEFAULT_COMMIT_RATE_LIMIT = false;
    private static final String DEFAULT_WORKSPACE_NAME = "crx.default";
    private static final boolean DEFAULT_FAST_QUERY_RESULT_SIZE = false;
    private static final boolean DEFAULT_ENABLE_ASYNC_INDEXING = true;
    @Property
    static final String REPOSITORY_HOME = "repository.home";
    @Property(intValue={1000}, label="Observation queue length", description="Maximum number of pending revisions in a observation listener queue")
    private static final String OBSERVATION_QUEUE_LENGTH = "oak.observation.queue-length";
    @Property(boolValue={0}, label="Commit rate limiter", description="Limit the commit rate once the number of pending revisions in the observation queue exceed 90% of its capacity.")
    private static final String COMMIT_RATE_LIMIT = "oak.observation.limit-commit-rate";
    @Property(boolValue={0}, name="Fast query result size", description="Whether the query result size should return an estimation (or -1 if disabled) for large queries")
    private static final String FAST_QUERY_RESULT_SIZE = "oak.query.fastResultSize";
    @Property(boolValue={1}, label="Enable async indexing", description="If true, the repository will use async indexing.")
    private static final String ENABLE_ASYNC_INDEXING = "enableAsyncIndexing";
    @Reference(policy=ReferencePolicy.STATIC, policyOption=ReferencePolicyOption.GREEDY)
    private NodeStore store = null;
    @Reference
    private ProductInfoService productInfo = null;
    @Reference
    private SlingSettingsService settingsService = null;
    @Reference(policy=ReferencePolicy.STATIC, policyOption=ReferencePolicyOption.GREEDY)
    private SecurityProvider securityProvider = null;
    @Reference
    private ServiceUserMapper serviceUserMapper = null;
    @Reference
    private ThreadPoolManager threadPoolManager = null;
    @Reference(target="(type=atomicCounter)")
    private EditorProvider atomicCounter;
    @Reference(target="(component.name=org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)")
    private IndexEditorProvider propertyIndexEditorProvider;
    @Reference
    private ServiceUsersConfigurationManager serviceUsersConfigurationManager;
    private ComponentContext componentContext;
    private ThreadPool threadPool;
    private Whiteboard whiteboard;
    private final WhiteboardIndexProvider indexProvider = new WhiteboardIndexProvider();
    private final WhiteboardIndexEditorProvider indexEditorProvider = new WhiteboardIndexEditorProvider();
    private File repositoryHome;
    private CRX3RepositoryImpl repository;
    private int observationQueueLength;
    private CommitRateLimiter commitRateLimiter;
    private boolean fastQueryResultSize;
    private ServiceRegistration nodeAggregator;
    private boolean enableAsyncIndexing;

    public SlingRepositoryManager() {
    }

    protected SlingRepositoryManager(NodeStore store, Whiteboard whiteboard, SecurityProvider securityProvider) {
        this.store = store;
        this.securityProvider = securityProvider;
        this.whiteboard = whiteboard;
        this.atomicCounter = new AtomicCounterEditorProvider();
        this.indexProvider.start(whiteboard);
        this.indexEditorProvider.start(whiteboard);
        this.repository = this.createRepository();
    }

    private String internalGetDefaultWorkspaceName() {
        String name = this.getDefaultWorkspace();
        return name == null ? "crx.default" : name;
    }

    @Activate
    public void activate(ComponentContext context) {
        this.componentContext = context;
        this.whiteboard = new OsgiWhiteboard(context.getBundleContext());
        this.repositoryHome = SlingRepositoryManager.getRepositoryHome(context);
        this.observationQueueLength = SlingRepositoryManager.getObservationQueueLength(context);
        this.commitRateLimiter = SlingRepositoryManager.getCommitRateLimiter(context);
        this.fastQueryResultSize = SlingRepositoryManager.getFastQueryResultSize(context);
        this.threadPool = this.threadPoolManager.get("oak-observation");
        this.nodeAggregator = context.getBundleContext().registerService(NodeAggregator.class.getName(), (Object)SlingRepositoryManager.getNodeAggregator(), null);
        this.enableAsyncIndexing = SlingRepositoryManager.getEnableAsyncIndexing(context);
        super.start(context.getBundleContext(), "crx.default", false);
    }

    @Deactivate
    public void deactivate() {
        super.stop();
        this.componentContext = null;
        this.threadPoolManager.release(this.threadPool);
        this.threadPool = null;
        this.whiteboard = null;
        this.nodeAggregator.unregister();
        this.tearDown();
    }

    protected Repository acquireRepository() {
        this.indexProvider.start(this.whiteboard);
        this.indexEditorProvider.start(this.whiteboard);
        this.repository = this.createRepository();
        return this.repository;
    }

    protected void disposeRepository(Repository repository) {
        assert (repository == this.repository);
        this.indexProvider.stop();
        this.indexEditorProvider.stop();
        this.repository.shutdown();
        this.repository = null;
    }

    protected ServiceUserMapper getServiceUserMapper() {
        return this.serviceUserMapper;
    }

    protected String[] getServiceRegistrationInterfaces() {
        return new String[]{SlingRepository.class.getName(), Repository.class.getName(), RepositoryManager.class.getName(), JackrabbitRepository.class.getName(), CRXRepository.class.getName()};
    }

    protected Dictionary<String, Object> getServiceRegistrationProperties() {
        return this.componentContext.getProperties();
    }

    protected AbstractSlingRepository2 create(Bundle usingBundle) {
        return new SlingRepositoryImpl(this, usingBundle, this.repository, this.serviceUsersConfigurationManager);
    }

    protected void destroy(AbstractSlingRepository2 repositoryServiceInstance) {
    }

    protected NamespaceMapper[] getNamespaceMapperServices() {
        return new NamespaceMapper[0];
    }

    public void handleTopologyEvent(TopologyEvent topologyEvent) {
        TopologyView newView = topologyEvent.getNewView();
        if (newView != null) {
            this.repository.setClusterState(newView.getLocalInstance());
        } else {
            this.repository.setClusterState(null);
        }
    }

    public ProductInfoService getProductInfo() {
        return this.productInfo;
    }

    public File getRepositoryHome() {
        return this.repositoryHome;
    }

    public SecurityProvider getSecurityProvider() {
        return this.securityProvider;
    }

    private CRX3RepositoryImpl createRepository() {
        if (Boolean.getBoolean("GRANITE-3583")) {
            ProgressLogger.startBackgroundThread();
        }
        Oak oak = new Oak(this.store).with(new Executor(){

            @Override
            public void execute(Runnable command) {
                SlingRepositoryManager.this.threadPool.execute(command);
            }
        }).with(this.whiteboard).with((RepositoryInitializer)new InitialContent().withPrePopulatedVersionStore()).with((RepositoryInitializer)new GraniteContent()).with((ConflictHandler)JcrConflictHandler.createJcrConflictHandler()).with((CommitHook)new EditorHook((EditorProvider)new VersionEditorProvider())).with(this.securityProvider).with((EditorProvider)new NameValidatorProvider()).with((EditorProvider)new NamespaceEditorProvider()).with((EditorProvider)new TypeEditorProvider()).with((EditorProvider)new ConflictValidatorProvider()).with(this.atomicCounter).with((QueryIndexProvider)this.indexProvider).with((IndexEditorProvider)this.indexEditorProvider).with(this.internalGetDefaultWorkspaceName());
        if (this.enableAsyncIndexing) {
            oak.withAsyncIndexing("async", 5);
            oak.withAsyncIndexing("fulltext-async", 5);
        }
        if (this.commitRateLimiter != null) {
            oak.with((CommitHook)this.commitRateLimiter);
        }
        ContentRepository contentRepository = oak.createContentRepository();
        SlingRepositoryManager.setupPermissions(contentRepository, this.securityProvider);
        return new CRX3RepositoryImpl(this, contentRepository, oak.getWhiteboard(), this.securityProvider, this.settingsService, this.observationQueueLength, this.commitRateLimiter, this.fastQueryResultSize);
    }

    private static NodeAggregator getNodeAggregator() {
        return new SimpleNodeAggregator().newRuleWithName("nt:file", (List)Lists.newArrayList((Object[])new String[]{"jcr:content"})).newRuleWithName("cq:Page", (List)Lists.newArrayList((Object[])new String[]{"jcr:content"})).newRuleWithName("cq:PageContent", (List)Lists.newArrayList((Object[])new String[]{"*", "*/*", "*/*/*", "*/*/*/*"})).newRuleWithName("dam:Asset", (List)Lists.newArrayList((Object[])new String[]{"jcr:content"})).newRuleWithName("dam:AssetContent", (List)Lists.newArrayList((Object[])new String[]{"metadata", "renditions", "renditions/original", "comments", "renditions/original/jcr:content"})).newRuleWithName("rep:User", (List)Lists.newArrayList((Object[])new String[]{"profile"}));
    }

    private static File getRepositoryHome(ComponentContext context) {
        Dictionary properties = context.getProperties();
        Object value = properties.get("repository.home");
        if (IndexPropertyUtil.isNullOrEmpty(value)) {
            value = context.getBundleContext().getProperty("repository.home");
        }
        if (IndexPropertyUtil.isNullOrEmpty(value)) {
            return new File("crx-quickstart", "repository");
        }
        return new File(value.toString());
    }

    private static int getObservationQueueLength(ComponentContext context) {
        Dictionary properties = context.getProperties();
        Object value = properties.get("oak.observation.queue-length");
        if (IndexPropertyUtil.isNullOrEmpty(value)) {
            value = context.getBundleContext().getProperty("oak.observation.queue-length");
        }
        try {
            return Integer.parseInt(String.valueOf(value));
        }
        catch (NumberFormatException e) {
            return 1000;
        }
    }

    private static CommitRateLimiter getCommitRateLimiter(ComponentContext context) {
        Dictionary properties = context.getProperties();
        Object value = properties.get("oak.observation.limit-commit-rate");
        if (IndexPropertyUtil.isNullOrEmpty(value)) {
            value = context.getBundleContext().getProperty("oak.observation.limit-commit-rate");
        }
        return Boolean.parseBoolean(String.valueOf(value)) ? new CommitRateLimiter() : null;
    }

    private static boolean getFastQueryResultSize(ComponentContext context) {
        Dictionary properties = context.getProperties();
        Object value = properties.get("oak.query.fastResultSize");
        if (IndexPropertyUtil.isNullOrEmpty(value)) {
            value = context.getBundleContext().getProperty("oak.query.fastResultSize");
        }
        return Boolean.parseBoolean(String.valueOf(value));
    }

    private static boolean getEnableAsyncIndexing(ComponentContext context) {
        return PropertiesUtil.toBoolean(context.getProperties().get("enableAsyncIndexing"), (boolean)true);
    }

    private static void setupPermissions(final @Nonnull ContentRepository repo, @Nonnull SecurityProvider securityProvider) {
        String errorMsg = "Failed to initialize default permissions.";
        ContentSession cs = null;
        try {
            cs = (ContentSession)Subject.doAsPrivileged(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>(){

                @Override
                public ContentSession run() throws Exception {
                    return repo.login(null, null);
                }
            }, null);
            Root root = cs.getLatestRoot();
            AuthorizationConfiguration config = (AuthorizationConfiguration)securityProvider.getConfiguration(AuthorizationConfiguration.class);
            AccessControlManager acMgr = config.getAccessControlManager(root, NamePathMapper.DEFAULT);
            SlingRepositoryManager.setupPolicy("/oak:index", acMgr);
            SlingRepositoryManager.setupPolicy("/jcr:system", acMgr);
            if (root.hasPendingChanges()) {
                root.commit();
            }
        }
        catch (RepositoryException e) {
            log.error(errorMsg, (Throwable)e);
            throw new RuntimeException((Throwable)e);
        }
        catch (CommitFailedException e) {
            log.error(errorMsg, (Throwable)e);
            throw new RuntimeException((Throwable)e);
        }
        catch (PrivilegedActionException e) {
            log.error(errorMsg, (Throwable)e);
            throw new RuntimeException(e);
        }
        finally {
            if (cs != null) {
                try {
                    cs.close();
                }
                catch (IOException e) {
                    log.error(e.getMessage(), (Throwable)e);
                }
            }
        }
    }

    private static void setupPolicy(@Nonnull String path, @Nonnull AccessControlManager acMgr) throws RepositoryException {
        AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
        while (it.hasNext()) {
            AccessControlPolicy policy = it.nextAccessControlPolicy();
            if (!(policy instanceof JackrabbitAccessControlList)) continue;
            JackrabbitAccessControlList acl = (JackrabbitAccessControlList)policy;
            Privilege[] jcrAll = AccessControlUtils.privilegesFromNames((AccessControlManager)acMgr, (String[])new String[]{"jcr:all"});
            acl.addEntry((Principal)EveryonePrincipal.getInstance(), jcrAll, false);
            acMgr.setPolicy(path, (AccessControlPolicy)acl);
            break;
        }
    }

    protected void bindStore(NodeStore nodeStore) {
        this.store = nodeStore;
    }

    protected void unbindStore(NodeStore nodeStore) {
        if (this.store == nodeStore) {
            this.store = null;
        }
    }

    protected void bindProductInfo(ProductInfoService productInfoService) {
        this.productInfo = productInfoService;
    }

    protected void unbindProductInfo(ProductInfoService productInfoService) {
        if (this.productInfo == productInfoService) {
            this.productInfo = null;
        }
    }

    protected void bindSettingsService(SlingSettingsService slingSettingsService) {
        this.settingsService = slingSettingsService;
    }

    protected void unbindSettingsService(SlingSettingsService slingSettingsService) {
        if (this.settingsService == slingSettingsService) {
            this.settingsService = null;
        }
    }

    protected void bindSecurityProvider(SecurityProvider securityProvider) {
        this.securityProvider = securityProvider;
    }

    protected void unbindSecurityProvider(SecurityProvider securityProvider) {
        if (this.securityProvider == securityProvider) {
            this.securityProvider = null;
        }
    }

    protected void bindServiceUserMapper(ServiceUserMapper serviceUserMapper) {
        this.serviceUserMapper = serviceUserMapper;
    }

    protected void unbindServiceUserMapper(ServiceUserMapper serviceUserMapper) {
        if (this.serviceUserMapper == serviceUserMapper) {
            this.serviceUserMapper = null;
        }
    }

    protected void bindThreadPoolManager(ThreadPoolManager threadPoolManager) {
        this.threadPoolManager = threadPoolManager;
    }

    protected void unbindThreadPoolManager(ThreadPoolManager threadPoolManager) {
        if (this.threadPoolManager == threadPoolManager) {
            this.threadPoolManager = null;
        }
    }

    protected void bindAtomicCounter(EditorProvider editorProvider) {
        this.atomicCounter = editorProvider;
    }

    protected void unbindAtomicCounter(EditorProvider editorProvider) {
        if (this.atomicCounter == editorProvider) {
            this.atomicCounter = null;
        }
    }

    protected void bindPropertyIndexEditorProvider(IndexEditorProvider indexEditorProvider) {
        this.propertyIndexEditorProvider = indexEditorProvider;
    }

    protected void unbindPropertyIndexEditorProvider(IndexEditorProvider indexEditorProvider) {
        if (this.propertyIndexEditorProvider == indexEditorProvider) {
            this.propertyIndexEditorProvider = null;
        }
    }

    protected void bindServiceUsersConfigurationManager(ServiceUsersConfigurationManager serviceUsersConfigurationManager) {
        this.serviceUsersConfigurationManager = serviceUsersConfigurationManager;
    }

    protected void unbindServiceUsersConfigurationManager(ServiceUsersConfigurationManager serviceUsersConfigurationManager) {
        if (this.serviceUsersConfigurationManager == serviceUsersConfigurationManager) {
            this.serviceUsersConfigurationManager = null;
        }
    }

}