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
}
}
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);
}
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;
}
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());
}
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;
}
Aggregations