Search in sources :

Example 31 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 32 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 33 with SessionImpl

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

the class Entry method readEntries.

static List<Entry> readEntries(NodeImpl aclNode, String path) throws RepositoryException {
    if (aclNode == null || !NT_REP_ACL.equals(aclNode.getPrimaryNodeTypeName())) {
        throw new IllegalArgumentException("Node must be of type 'rep:ACL'");
    }
    SessionImpl sImpl = (SessionImpl) aclNode.getSession();
    PrincipalManager principalMgr = sImpl.getPrincipalManager();
    PrivilegeManagerImpl privilegeMgr = (PrivilegeManagerImpl) ((JackrabbitWorkspace) sImpl.getWorkspace()).getPrivilegeManager();
    NodeId nodeId = aclNode.getParentId();
    List<Entry> entries = new ArrayList<Entry>();
    // load the entries:
    NodeIterator itr = aclNode.getNodes();
    while (itr.hasNext()) {
        NodeImpl aceNode = (NodeImpl) itr.nextNode();
        try {
            String principalName = aceNode.getProperty(P_PRINCIPAL_NAME).getString();
            boolean isGroupEntry = false;
            Principal princ = principalMgr.getPrincipal(principalName);
            if (princ != null) {
                isGroupEntry = (princ instanceof Group);
            }
            InternalValue[] privValues = aceNode.getProperty(P_PRIVILEGES).internalGetValues();
            Name[] privNames = new Name[privValues.length];
            for (int i = 0; i < privValues.length; i++) {
                privNames[i] = privValues[i].getName();
            }
            Value globValue = null;
            if (aceNode.hasProperty(P_GLOB)) {
                globValue = aceNode.getProperty(P_GLOB).getValue();
            }
            boolean isAllow = NT_REP_GRANT_ACE.equals(aceNode.getPrimaryNodeTypeName());
            Entry ace = new Entry(nodeId, principalName, isGroupEntry, privilegeMgr.getBits(privNames), isAllow, path, globValue);
            entries.add(ace);
        } catch (RepositoryException e) {
            log.debug("Failed to build ACE from content. {}", e.getMessage());
        }
    }
    return entries;
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) NodeIterator(javax.jcr.NodeIterator) Group(java.security.acl.Group) NodeImpl(org.apache.jackrabbit.core.NodeImpl) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Value(javax.jcr.Value) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Principal(java.security.Principal) PrivilegeManagerImpl(org.apache.jackrabbit.core.security.authorization.PrivilegeManagerImpl)

Example 34 with SessionImpl

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

the class VersionImpl method getLinearSuccessor.

/**
     * {@inheritDoc}
     */
public Version getLinearSuccessor() throws RepositoryException {
    // get base version. this can certainly be optimized
    SessionImpl session = sessionContext.getSessionImpl();
    InternalVersionHistory vh = ((VersionHistoryImpl) getContainingHistory()).getInternalVersionHistory();
    Node vn = session.getNodeById(vh.getVersionableId());
    InternalVersion base = ((VersionImpl) vn.getBaseVersion()).getInternalVersion();
    InternalVersion suc = getInternalVersion().getLinearSuccessor(base);
    return suc == null ? null : (Version) session.getNodeById(suc.getId());
}
Also used : Node(javax.jcr.Node) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 35 with SessionImpl

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

the class VersionHistoryImpl method getInternalVersionHistory.

/**
     * Returns the internal version history. Subclass responsibility.
     *
     * @return internal version history
     * @throws RepositoryException if the internal version history is not available
     */
protected InternalVersionHistory getInternalVersionHistory() throws RepositoryException {
    SessionImpl session = sessionContext.getSessionImpl();
    InternalVersionHistory history = session.getInternalVersionManager().getVersionHistory((NodeId) id);
    if (history == null) {
        throw new InvalidItemStateException(id + ": the item does not exist anymore");
    }
    return history;
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

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