Package org.jdesktop.wonderland.modules.security.common

Examples of org.jdesktop.wonderland.modules.security.common.Permission


                {
                    return Access.GRANT;
                }

                // find the permission for this principal
                Permission perm = getPermission(p, action);
                if (perm != null) {
                    // now check if the permission is a user permission.  If
                    // it is, it means it was a permission specifically for
                    // this user, and therefore should be applied directly
                    // and not combined with any other permissions.
                    if (perm.getPrincipal().getType() == Principal.Type.USER) {
                        return perm.getAccess();
                    }

                    // if the permission is a group or everybody permission,
                    // put it on the list to combine later
                    myPerms.add(perm);
                }
            }

            // now go through all the group permissions. If there are any
            // positive group permissions, this means that at least one of
            // the groups this user is a member of has access to the content,
            // so access should be granted
            boolean hasGroupPerm = false;
            for (Iterator<Permission> i = myPerms.iterator(); i.hasNext();) {
                Permission perm = i.next();

                if (perm.getPrincipal().getType() == Principal.Type.GROUP) {
                    hasGroupPerm = true;
                    i.remove();

                    if (perm.getAccess() == Access.GRANT) {
                        return Access.GRANT;
                    }
                }
            }

            // at this point, if there was a group permission defined, we know
            // that it was a DENY because otherwise we would have returned
            // above.  That means that the user wasn't part of any groups
            // that had permission, but was part of at least one group that
            // was denied permission.  In this case, we should deny access.
            if (hasGroupPerm) {
                return Access.DENY;
            }

            // last, we check for any remaining permissionm, which must
            // be everyone permissions. There is no way to combine these, so
            // just go with whatever the first one says (hopefully there is
            // only one)
            for (Permission perm : myPerms) {
                return perm.getAccess();
            }
           
            // if we get here, it means that there were no permissions for
            // this user, any of the user's groups or everybody.  In that case,
            // return undefined (null).
View Full Code Here


         * @return true if the given principal has permission for the given
         * action, or false if it is denied or undefined.
         */
        protected Permission getPermission(Principal p, Action action) {
            // construct a prototype permission to search for
            Permission search = new Permission(p, new ActionDTO(action), null);

            // use the sorted set to find the first matching permission.
            // This will correspond to the permission for this user
            // if it is defined.
            Permission perm = null;
            SortedSet<Permission> perms = permissions.tailSet(search);
            if (!perms.isEmpty() && perms.first().equals(search)) {
                perm = perms.first();
            }
           
View Full Code Here

        }

        // add view permissions for all users
        Principal p = new Principal("users", Principal.Type.EVERYBODY);
        ActionDTO view = new ActionDTO(new ViewAction());
        perms.getPermissions().add(new Permission(
                p, view, Permission.Access.GRANT));
        ActionDTO modify = new ActionDTO(new ModifyAction());
        perms.getPermissions().add(new Permission(
                p, modify, Permission.Access.DENY));

        state.setPermissions(perms);
        return (T) state;
    }
View Full Code Here

                if (node != null) {
                    i.remove();
                    actions.put(action, node);

                    // find the associated permission, if any
                    Permission search = new Permission(p, actionDTO, null);
                    SortedSet<Permission> tail = ps.tailSet(search);
                    if (!tail.isEmpty() && tail.first().equals(search)) {
                        ActionHolder ah = (ActionHolder) node.getUserObject();
                        ah.setAccess(tail.first().getAccess());
                    }
View Full Code Here

            }

            ActionHolder ah = (ActionHolder) node.getUserObject();

            if (ah.getAccess() != null) {
                res.add(new Permission(p.getPrincipal(),
                        new ActionDTO(ah.getAction()),
                        ah.getAccess()));
            }
        }
View Full Code Here

            if (equal) {
                Iterator<Permission> c = currentPermissions.iterator();
                Iterator<Permission> o = originalPermissions.iterator();

                while (c.hasNext()) {
                    Permission cp = c.next();
                    Permission op = o.next();

                    if (!cp.equals(op) || cp.getAccess() != op.getAccess()) {
                        equal = false;
                        break;
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.jdesktop.wonderland.modules.security.common.Permission

Copyright © 2018 www.massapicom. 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.