Search in sources :

Example 81 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class WriteTest method testInvalidPrincipal.

public void testInvalidPrincipal() throws Exception {
    PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
    String unknown = "unknown";
    while (pMgr.hasPrincipal(unknown)) {
        unknown = unknown + "_";
    }
    Principal principal = new PrincipalImpl(unknown);
    if (acMgr instanceof JackrabbitAccessControlManager) {
        // first try applicable policies
        try {
            AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getApplicablePolicies(principal);
            assertNotNull(policies);
            assertEquals(0, policies.length);
        } catch (AccessControlException e) {
        // success
        }
        // second existing policies
        try {
            AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getPolicies(principal);
            assertNotNull(policies);
            assertEquals(0, policies.length);
        } catch (AccessControlException e) {
        // success
        }
    } else {
        throw new NotExecutableException();
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl)

Example 82 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AdministratorTest method testAdminNodeCollidingWithAuthorizableFolder.

/**
     * Test for collisions that would prevent from recreate the admin user.
     * - an intermediate rep:AuthorizableFolder node with the same name
     */
public void testAdminNodeCollidingWithAuthorizableFolder() throws RepositoryException, NotExecutableException {
    Authorizable admin = userMgr.getAuthorizable(adminId);
    if (admin == null || !(admin instanceof AuthorizableImpl)) {
        throw new NotExecutableException();
    }
    // access the node corresponding to the admin user and remove it
    NodeImpl adminNode = ((AuthorizableImpl) admin).getNode();
    String adminPath = adminNode.getPath();
    String adminNodeName = adminNode.getName();
    Node parentNode = adminNode.getParent();
    Session s = adminNode.getSession();
    adminNode.remove();
    // use session obtained from the node as usermgr may point to a dedicated
    // system workspace different from the superusers workspace.
    s.save();
    Session s2 = null;
    String collidingPath = null;
    try {
        // now create a colliding node:
        Node n = parentNode.addNode(adminNodeName, "rep:AuthorizableFolder");
        collidingPath = n.getPath();
        s.save();
        // force recreation of admin user.
        s2 = getHelper().getSuperuserSession();
        admin = userMgr.getAuthorizable(adminId);
        assertNotNull(admin);
        assertEquals(adminNodeName, ((AuthorizableImpl) admin).getNode().getName());
        assertFalse(adminPath.equals(((AuthorizableImpl) admin).getNode().getPath()));
    } finally {
        if (s2 != null) {
            s2.logout();
        }
        // remove the extra folder and the admin user (created underneath) again.
        if (collidingPath != null) {
            s.getNode(collidingPath).remove();
            s.save();
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) NodeImpl(org.apache.jackrabbit.core.NodeImpl) Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Session(javax.jcr.Session)

Example 83 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class AuthorizableActionTest method assertAcAction.

private static void assertAcAction(Authorizable a, UserManagerImpl umgr) throws RepositoryException, NotExecutableException {
    Session s = umgr.getSession();
    AccessControlManager acMgr = s.getAccessControlManager();
    boolean hasACL = false;
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies("/");
    while (it.hasNext()) {
        if (it.nextAccessControlPolicy() instanceof AccessControlList) {
            hasACL = true;
            break;
        }
    }
    if (!hasACL) {
        for (AccessControlPolicy p : acMgr.getPolicies("/")) {
            if (p instanceof AccessControlList) {
                hasACL = true;
                break;
            }
        }
    }
    if (!hasACL) {
        throw new NotExecutableException("No ACLs in workspace containing users.");
    }
    String path = a.getPath();
    assertEquals(1, acMgr.getPolicies(path).length);
    assertTrue(acMgr.getPolicies(path)[0] instanceof AccessControlList);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Session(javax.jcr.Session)

Example 84 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException 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 85 with NotExecutableException

use of org.apache.jackrabbit.test.NotExecutableException in project jackrabbit by apache.

the class PropertyReadMethodsTest method testGetValues.

/**
     * Tests failure of Property.getValues() method for a single value
     * property.
     */
public void testGetValues() throws RepositoryException, NotExecutableException {
    Property singleProp = PropertyUtil.searchSingleValuedProperty(testRootNode);
    if (singleProp == null) {
        throw new NotExecutableException("No single valued property found.");
    }
    try {
        singleProp.getValues();
        fail("Property.getValues() called on a single property " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Aggregations

NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)381 Node (javax.jcr.Node)149 NodeType (javax.jcr.nodetype.NodeType)84 Value (javax.jcr.Value)81 RepositoryException (javax.jcr.RepositoryException)64 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)61 Session (javax.jcr.Session)59 Property (javax.jcr.Property)47 NodeDefinition (javax.jcr.nodetype.NodeDefinition)29 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)28 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)25 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)23 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)22 Test (org.junit.Test)22 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)21 User (org.apache.jackrabbit.api.security.user.User)19 Principal (java.security.Principal)18 NodeIterator (javax.jcr.NodeIterator)18 UserManager (org.apache.jackrabbit.api.security.user.UserManager)17 ItemExistsException (javax.jcr.ItemExistsException)16