protected Session createServiceSession()

in src/main/java/org/apache/sling/jcr/oak/server/internal/OakSlingRepository.java [86:105]


    protected Session createServiceSession(Iterable<String> servicePrincipalNames, String workspaceName)
            throws RepositoryException {
        Set<SystemUserPrincipal> principals = new HashSet<>();
        for (final String pName : servicePrincipalNames)
            principals.add(() -> pName);

        // make sure to retain the first user id from the passed in servicePrincipalNames, for consistency
        AuthInfo authInfo = new AuthInfoImpl(first(servicePrincipalNames), emptyMap(), principals);
        Subject subject = new Subject(true, principals, singleton(authInfo), emptySet());
        try {
            return Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>() {
                @Override
                public Session run() throws Exception {
                    return getRepository().login(null, workspaceName);
                }
            }, null);
        } catch (PrivilegedActionException e) {
            throw new RepositoryException("failed to retrieve service session.", e);
        }
    }