Examples of Impersonation


Examples of org.apache.jackrabbit.api.security.user.Impersonation

        Authorizable child = userMgr.createUser(p.getName(), buildPassword(p));
        try {
            p = child.getPrincipal();

            Authorizable himself = uMgr.getAuthorizable(uID);
            Impersonation impers = ((User) himself).getImpersonation();

            assertFalse(impers.allows(buildSubject(p)));
            assertTrue(impers.grantImpersonation(p));
            assertTrue(impers.allows(buildSubject(p)));
            assertTrue(impers.revokeImpersonation(p));
            assertFalse(impers.allows(buildSubject(p)));

        } finally {
            // let superuser do clean up.
            child.remove();
        }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

        Principal p = getTestPrincipal();
        String childID = userMgr.createUser(p.getName(), buildPassword(p)).getID();
        try {
            Authorizable child = uMgr.getAuthorizable(childID);

            Impersonation impers = ((User) child).getImpersonation();
            Principal himselfP = uMgr.getAuthorizable(uID).getPrincipal();
            assertFalse(impers.allows(buildSubject(himselfP)));
            impers.grantImpersonation(himselfP);
            fail("A non-administrator user should not be allowed modify Impersonation of a child user.");
        } catch (AccessDeniedException e) {
            // success
        }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

        User u = null;
        try {
            Principal p = getTestPrincipal();
            u = umgr.createUser(p.getName(), buildPassword(p));

            Impersonation impers = u.getImpersonation();
            assertFalse(impers.allows(buildSubject(otherP)));
            assertTrue(impers.grantImpersonation(otherP));
            assertTrue(impers.allows(buildSubject(otherP)));
        } finally {
            // impersonation get removed while removing the user u.
            if (u != null) {
                u.remove();
            }
        }

        // modify impersonation of another user
        u = (User) umgr.getAuthorizable(uID);
        Impersonation uImpl = u.getImpersonation();
        if (!uImpl.allows(buildSubject(otherP))) {
            // ... trying to modify 'impersonators of another user must succeed
            assertTrue(uImpl.grantImpersonation(otherP));
            assertTrue(uImpl.allows(buildSubject(otherP)));
            uImpl.revokeImpersonation(otherP);
        } else {
            throw new NotExecutableException("Cannot execute test. OtherP can already impersonate UID-user.");
        }
    }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

                    Authorizable a = userManager.getAuthorizable(((Impersonators) reference).userId);
                    if (a == null || a.isGroup()) {
                        throw new RepositoryException(((Impersonators) reference).userId + " does not represent a valid user.");
                    }

                    Impersonation imp = ((User) a).getImpersonation();

                    // 1. collect principals to add and to remove.
                    Map<String, Principal> toRemove = new HashMap<String, Principal>();
                    for (PrincipalIterator pit = imp.getImpersonators(); pit.hasNext();) {
                        Principal princ = pit.nextPrincipal();
                        toRemove.put(princ.getName(), princ);
                    }

                    List<Principal> toAdd = new ArrayList<Principal>();
                    Value[] vs = ((Impersonators) reference).values;
                    for (Value v : vs) {
                        String princName = v.getString();
                        if (toRemove.remove(princName) == null) {
                            // add it to the list of new impersonators to be added.
                            toAdd.add(new PrincipalImpl(princName));
                        } // else: no need to revoke impersonation for the given principal.
                    }

                    // 2. adjust set of impersonators
                    for (Principal princ : toRemove.values()) {
                        if (!imp.revokeImpersonation(princ)) {
                            handleFailure("Failed to revoke impersonation for " + princ.getName() + " on " + a);
                        }
                    }
                    for (Principal princ : toAdd) {
                        if (!imp.grantImpersonation(princ)) {
                            handleFailure("Failed to grant impersonation for " + princ.getName() + " on " + a);
                        }
                    }
                    // NOTE: no best effort handling so far. (TODO)
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

            assertNotNull(u2);

            Subject subj = new Subject();
            subj.getPrincipals().add(u2.getPrincipal());

            Impersonation imp = ((User) newUser).getImpersonation();
            assertTrue(imp.allows(subj));

        } finally {
            sImpl.refresh(false);
        }
    }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

                doImport(target, xml, UserImporter.ImportBehavior.IGNORE);
                // no exception during import: no impersonation must be granted
                // for the invalid principal name
                Authorizable a = umgr.getAuthorizable("t");
                if (!a.isGroup()) {
                    Impersonation imp = ((User)a).getImpersonation();
                    Subject s = new Subject();
                    s.getPrincipals().add(new PrincipalImpl(principalName));
                    assertFalse(imp.allows(s));
                    for (PrincipalIterator it = imp.getImpersonators(); it.hasNext();) {
                        assertFalse(principalName.equals(it.nextPrincipal().getName()));
                    }
                } else {
                    fail("Importing 't' didn't create a User.");
                }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

                    Authorizable a = userManager.getAuthorizable(((Impersonators) reference).userId);
                    if (a == null || a.isGroup()) {
                        throw new RepositoryException(((Impersonators) reference).userId + " does not represent a valid user.");
                    }

                    Impersonation imp = ((User) a).getImpersonation();

                    // 1. collect principals to add and to remove.
                    Map<String, Principal> toRemove = new HashMap();
                    for (PrincipalIterator pit = imp.getImpersonators(); pit.hasNext();) {
                        Principal princ = pit.nextPrincipal();
                        toRemove.put(princ.getName(), princ);
                    }

                    List<Principal> toAdd = new ArrayList();
                    Value[] vs = ((Impersonators) reference).values;
                    for (Value v : vs) {
                        String princName = v.getString();
                        if (toRemove.remove(princName) == null) {
                            // add it to the list of new impersonators to be added.
                            toAdd.add(new PrincipalImpl(princName));
                        } // else: no need to revoke impersonation for the given principal.
                    }

                    // 2. adjust set of impersonators
                    for (Principal princ : toRemove.values()) {
                        if (!imp.revokeImpersonation(princ)) {
                            handleFailure("Failed to revoke impersonation for " + princ.getName() + " on " + a);
                        }
                    }
                    for (Principal princ : toAdd) {
                        if (!imp.grantImpersonation(princ)) {
                            handleFailure("Failed to grant impersonation for " + princ.getName() + " on " + a);
                        }
                    }
                    // NOTE: no best effort handling so far. (TODO)
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

            assertNotNull(u2);

            Subject subj = new Subject();
            subj.getPrincipals().add(u2.getPrincipal());

            Impersonation imp = ((User) newUser).getImpersonation();
            assertTrue(imp.allows(subj));

        } finally {
            sImpl.refresh(false);
        }
    }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

                doImport(target, xml, UserImporter.ImportBehavior.IGNORE);
                // no exception during import: no impersonation must be granted
                // for the invalid principal name
                Authorizable a = umgr.getAuthorizable("t");
                if (!a.isGroup()) {
                    Impersonation imp = ((User)a).getImpersonation();
                    Subject s = new Subject();
                    s.getPrincipals().add(new PrincipalImpl(principalName));
                    assertFalse(imp.allows(s));
                    for (PrincipalIterator it = imp.getImpersonators(); it.hasNext();) {
                        assertFalse(principalName.equals(it.nextPrincipal().getName()));
                    }
                } else {
                    fail("Importing 't' didn't create a User.");
                }
View Full Code Here

Examples of org.apache.jackrabbit.api.security.user.Impersonation

        Authorizable child = userMgr.createUser(p.getName(), buildPassword(p), p, uPath);
        try {
            p = child.getPrincipal();

            Authorizable himself = uMgr.getAuthorizable(uID);
            Impersonation impers = ((User) himself).getImpersonation();

            assertFalse(impers.allows(buildSubject(p)));
            assertTrue(impers.grantImpersonation(p));
            assertTrue(impers.allows(buildSubject(p)));
            assertTrue(impers.revokeImpersonation(p));
            assertFalse(impers.allows(buildSubject(p)));

        } finally {
            // let superuser do clean up.
            child.remove();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.