use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method createSourceContent.
@Override
@SuppressWarnings("unchecked")
protected void createSourceContent(Session session) throws Exception {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace("test", "http://www.example.org/");
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate();
template.setName("test:unstructured");
template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured" });
PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate();
pDef1.setName("defaultString");
pDef1.setRequiredType(PropertyType.STRING);
Value stringValue = session.getValueFactory().createValue("stringValue");
pDef1.setDefaultValues(new Value[] { stringValue });
template.getPropertyDefinitionTemplates().add(pDef1);
PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate();
pDef2.setName("defaultPath");
pDef2.setRequiredType(PropertyType.PATH);
Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH);
pDef2.setDefaultValues(new Value[] { pathValue });
template.getPropertyDefinitionTemplates().add(pDef2);
nodeTypeManager.registerNodeType(template, false);
template = nodeTypeManager.createNodeTypeTemplate();
template.setName("test:referenceable");
template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured", "mix:referenceable" });
nodeTypeManager.registerNodeType(template, false);
Node root = session.getRootNode();
Node referenceable = root.addNode("referenceable", "test:unstructured");
referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
Node versionable = root.addNode("versionable", NT_UNSTRUCTURED);
versionable.addMixin(MIX_VERSIONABLE);
Node child = versionable.addNode("child", "test:referenceable");
child.addNode("child2", NT_UNSTRUCTURED);
session.save();
Node sns = root.addNode("sns");
sns.addNode("sibling");
sns.addNode("sibling");
sns.addNode("sibling");
session.getWorkspace().getVersionManager().checkin("/versionable");
Node properties = root.addNode("properties", "test:unstructured");
properties.setProperty("boolean", true);
Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY));
try {
properties.setProperty("binary", binary);
} finally {
binary.dispose();
}
properties.setProperty("date", DATE);
properties.setProperty("decimal", new BigDecimal(123));
properties.setProperty("double", Math.PI);
properties.setProperty("long", 9876543210L);
properties.setProperty("reference", referenceable);
properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true));
properties.setProperty("mv_reference", new Value[] { session.getValueFactory().createValue(versionable, false) });
properties.setProperty("mv_weak_reference", new Value[] { session.getValueFactory().createValue(versionable, true) });
properties.setProperty("string", "test");
properties.setProperty("multiple", "a,b,c".split(","));
session.save();
binary = properties.getProperty("binary").getBinary();
try {
InputStream stream = binary.getStream();
try {
for (byte aBINARY : BINARY) {
assertEquals(aBINARY, (byte) stream.read());
}
assertEquals(-1, stream.read());
} finally {
stream.close();
}
} finally {
binary.dispose();
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class RepeatedRepositoryUpgradeTest method registerCustomPrivileges.
private void registerCustomPrivileges(Session session) throws RepositoryException {
final JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
final NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace("test", "http://www.example.org/");
final PrivilegeManager privilegeManager = workspace.getPrivilegeManager();
privilegeManager.registerPrivilege("test:privilege", false, null);
privilegeManager.registerPrivilege("test:aggregate", false, new String[] { "jcr:read", "test:privilege" });
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class PrivilegeUpgradeTest method verifyCustomPrivileges.
@Test
public void verifyCustomPrivileges() throws Exception {
JackrabbitSession session = createAdminSession();
try {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
PrivilegeManager manager = workspace.getPrivilegeManager();
Privilege privilege = manager.getPrivilege("test:privilege");
assertNotNull(privilege);
assertFalse(privilege.isAbstract());
assertFalse(privilege.isAggregate());
assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
Privilege privilege2 = manager.getPrivilege("test:privilege2");
assertNotNull(privilege2);
assertTrue(privilege2.isAbstract());
assertFalse(privilege2.isAggregate());
assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
Privilege aggregate = manager.getPrivilege("test:aggregate");
assertNotNull(aggregate);
assertFalse(aggregate.isAbstract());
assertTrue(aggregate.isAggregate());
List<Privilege> agg = ImmutableList.copyOf(aggregate.getDeclaredAggregatePrivileges());
assertEquals(2, agg.size());
assertTrue(agg.contains(privilege));
assertTrue(agg.contains(manager.getPrivilege(JCR_READ)));
Privilege aggregate2 = manager.getPrivilege("test:aggregate2");
assertNotNull(aggregate2);
assertTrue(aggregate2.isAbstract());
assertTrue(aggregate2.isAggregate());
List<Privilege> agg2 = ImmutableList.copyOf(aggregate2.getDeclaredAggregatePrivileges());
assertEquals(2, agg2.size());
assertTrue(agg2.contains(aggregate));
assertTrue(agg2.contains(privilege2));
Privilege jcrAll = manager.getPrivilege("jcr:all");
List<Privilege> privileges = asList(jcrAll.getAggregatePrivileges());
assertTrue(privileges.contains(privilege));
assertTrue(privileges.contains(privilege2));
assertTrue(privileges.contains(aggregate));
assertTrue(privileges.contains(aggregate2));
} finally {
session.logout();
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class PrivilegeManagementTest method testRegisterPrivilegeWithPrivilege.
@Test
public void testRegisterPrivilegeWithPrivilege() throws Exception {
modify(null, PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT, true);
try {
Workspace testWsp = testSession.getWorkspace();
((JackrabbitWorkspace) testWsp).getPrivilegeManager().registerPrivilege(getNewPrivilegeName(testWsp), false, new String[0]);
} finally {
modify(null, PrivilegeConstants.REP_PRIVILEGE_MANAGEMENT, false);
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class WriteWithCustomPrivilege method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
PrivilegeManager privilegeManager = ((JackrabbitWorkspace) superuser.getWorkspace()).getPrivilegeManager();
try {
privilegeManager.getPrivilege("replicate");
} catch (AccessControlException e) {
privilegeManager.registerPrivilege("replicate", false, null);
}
}
Aggregations