Search in sources :

Example 6 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class AuthorizableImplTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (superuser instanceof SessionImpl) {
        NameResolver resolver = (SessionImpl) superuser;
        protectedUserProps.add(resolver.getJCRName(UserConstants.P_PASSWORD));
        protectedUserProps.add(resolver.getJCRName(UserConstants.P_IMPERSONATORS));
        protectedUserProps.add(resolver.getJCRName(UserConstants.P_PRINCIPAL_NAME));
        protectedUserProps.add(resolver.getJCRName(UserConstants.P_DISABLED));
        protectedGroupProps.add(resolver.getJCRName(UserConstants.P_MEMBERS));
        protectedGroupProps.add(resolver.getJCRName(UserConstants.P_PRINCIPAL_NAME));
    } else {
        throw new NotExecutableException();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) NameResolver(org.apache.jackrabbit.spi.commons.conversion.NameResolver)

Example 7 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class SessionImplTest method testGetSubject.

/**
     * JCR-2895 : SessionImpl#getSubject() should return an unmodifiable subject
     *
     * @see <a href="https://issues.apache.org/jira/browse/JCR-2895">JCR-2895</a>
     */
public void testGetSubject() {
    Subject subject = ((SessionImpl) superuser).getSubject();
    assertFalse(subject.getPublicCredentials().isEmpty());
    assertFalse(subject.getPublicCredentials(Credentials.class).isEmpty());
    assertFalse(subject.getPrincipals().isEmpty());
    assertTrue(subject.isReadOnly());
    try {
        subject.getPublicCredentials().add(new SimpleCredentials("test", new char[0]));
        fail("Subject expected to be readonly");
    } catch (IllegalStateException e) {
    // success
    }
    try {
        subject.getPrincipals().add(new PrincipalImpl("test"));
        fail("Subject expected to be readonly");
    } catch (IllegalStateException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Subject(javax.security.auth.Subject) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl)

Example 8 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class TokenProviderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (superuser instanceof SessionImpl) {
        UserManager umgr = ((SessionImpl) superuser).getUserManager();
        if (!umgr.isAutoSave()) {
            umgr.autoSave(true);
        }
        String uid = "test";
        while (umgr.getAuthorizable(uid) != null) {
            uid += "_";
        }
        testuser = umgr.createUser(uid, uid);
        userId = testuser.getID();
    } else {
        throw new NotExecutableException();
    }
    if (superuser.nodeExists(((ItemBasedPrincipal) testuser.getPrincipal()).getPath())) {
        session = (SessionImpl) superuser;
    } else {
        session = (SessionImpl) getHelper().getSuperuserSession("security");
    }
    tokenProvider = new TokenProvider((SessionImpl) session, TokenBasedAuthentication.TOKEN_EXPIRATION);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 9 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GarbageCollector method mark.

public void mark() throws RepositoryException {
    if (store == null) {
        throw new RepositoryException("No DataStore configured.");
    }
    long now = System.currentTimeMillis();
    if (startScanTimestamp == 0) {
        startScanTimestamp = now;
        store.updateModifiedDateOnAccess(startScanTimestamp);
    }
    if (pmList == null || !persistenceManagerScan) {
        for (SessionImpl s : sessionList) {
            scanNodes(s);
        }
    } else {
        try {
            if (!NODE_ID_SCAN) {
                scanPersistenceManagersByNodeInfos();
            } else {
                scanPersistenceManagersByNodeIds();
            }
        } catch (ItemStateException e) {
            throw new RepositoryException(e);
        }
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 10 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class LockManagerImpl method internalUnlock.

/**
     * Unlock a node (internal implementation)
     * @param node node to unlock
     * @throws LockException       if the node can not be unlocked
     * @throws RepositoryException if another error occurs
     */
boolean internalUnlock(NodeImpl node) throws LockException, RepositoryException {
    ClusterOperation operation = null;
    boolean successful = false;
    if (eventChannel != null) {
        operation = eventChannel.create(node.getNodeId());
    }
    acquire();
    try {
        SessionImpl session = (SessionImpl) node.getSession();
        // check whether node is locked by this session
        PathMap.Element<LockInfo> element = lockMap.map(getPath(session, node.getId()), true);
        if (element == null) {
            throw new LockException("Node not locked: " + node);
        }
        LockInfo info = element.get();
        if (info == null) {
            throw new LockException("Node not locked: " + node);
        }
        checkUnlock(info, session);
        getSessionLockManager(session).lockTokenRemoved(info.getLockToken());
        element.set(null);
        info.setLive(false);
        if (!info.isSessionScoped()) {
            save();
            successful = true;
        }
        return true;
    } finally {
        release();
        if (operation != null) {
            operation.ended(successful);
        }
    }
}
Also used : LockException(javax.jcr.lock.LockException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) ClusterOperation(org.apache.jackrabbit.core.cluster.ClusterOperation) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)63 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)12 Value (javax.jcr.Value)11 Name (org.apache.jackrabbit.spi.Name)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)9 NodeImpl (org.apache.jackrabbit.core.NodeImpl)8 NodeId (org.apache.jackrabbit.core.id.NodeId)8 Principal (java.security.Principal)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 NodeIterator (javax.jcr.NodeIterator)6 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 Path (org.apache.jackrabbit.spi.Path)6 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 LockException (javax.jcr.lock.LockException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4