Package org.acegisecurity

Examples of org.acegisecurity.AccessDeniedException


                }

                AclEntry[] acls = aclManager.getAcls(returnedObject, authentication);

                if ((acls == null) || (acls.length == 0)) {
                    throw new AccessDeniedException(messages.getMessage(
                            "BasicAclEntryAfterInvocationProvider.noPermission",
                            new Object[] {authentication.getName(), returnedObject},
                            "Authentication {0} has NO permissions at all to the domain object {1}", LocaleContextHolder.getLocale()));
                }

                for (int i = 0; i < acls.length; i++) {
                    // Locate processable AclEntrys
                    if (acls[i] instanceof BasicAclEntry) {
                        BasicAclEntry processableAcl = (BasicAclEntry) acls[i];

                        // See if principal has any of the required permissions
                        for (int y = 0; y < requirePermission.length; y++) {
                            if (processableAcl.isPermitted(requirePermission[y])) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("Principal DOES have permission to return object: " + returnedObject
                                        + " due to ACL: " + processableAcl.toString());
                                }

                                return returnedObject;
                            }
                        }
                    }
                }

                // No permissions match
                throw new AccessDeniedException(messages.getMessage(
                        "BasicAclEntryAfterInvocationProvider.insufficientPermission",
                        new Object[] {authentication.getName(), returnedObject},
                        "Authentication {0} has ACL permissions to the domain object, "
                        + "but not the required ACL permission to the domain object {1}", LocaleContextHolder.getLocale()));
            }
View Full Code Here


    public void securityCheck(Acl acl, int changeType) {
        if ((SecurityContextHolder.getContext() == null)
            || (SecurityContextHolder.getContext().getAuthentication() == null)
            || !SecurityContextHolder.getContext().getAuthentication().isAuthenticated()) {
            throw new AccessDeniedException("Authenticated principal required to operate with ACLs");
        }

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        // Check if authorized by virtue of ACL ownership
        Sid currentUser = new PrincipalSid(authentication);

        if (currentUser.equals(acl.getOwner())
                && ((changeType == CHANGE_GENERAL) || (changeType == CHANGE_OWNERSHIP))) {
            return;
        }

        // Not authorized by ACL ownership; try via adminstrative permissions
        GrantedAuthority requiredAuthority = null;

        if (changeType == CHANGE_AUDITING) {
            requiredAuthority = this.gaModifyAuditing;
        } else if (changeType == CHANGE_GENERAL) {
            requiredAuthority = this.gaGeneralChanges;
        } else if (changeType == CHANGE_OWNERSHIP) {
            requiredAuthority = this.gaTakeOwnership;
        } else {
            throw new IllegalArgumentException("Unknown change type");
        }

        // Iterate this principal's authorities to determine right
        GrantedAuthority[] auths = authentication.getAuthorities();

        for (int i = 0; i < auths.length; i++) {
            if (requiredAuthority.equals(auths[i])) {
                return;
            }
        }

        // Try to get permission via ACEs within the ACL
        Sid[] sids = sidRetrievalStrategy.getSids(authentication);

        if (acl.isGranted(new Permission[] {BasePermission.ADMINISTRATION}, sids, false)) {
            return;
        }

        throw new AccessDeniedException(
            "Principal does not have required ACL permissions to perform requested operation");
    }
View Full Code Here

        Assert.notNull(this.messages, "A message source must be set");
    }

    protected final void checkAllowIfAllAbstainDecisions() {
        if (!this.isAllowIfAllAbstainDecisions()) {
            throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }
    }
View Full Code Here

                break;
            }
        }

        if (deny > 0) {
            throw new AccessDeniedException(messages.getMessage("AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }

        // To get this far, every AccessDecisionVoter abstained
        checkAllowIfAllAbstainDecisions();
View Full Code Here

                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Denying access");
                    }

                    throw new AccessDeniedException(messages.getMessage(
                            "BasicAclEntryAfterInvocationProvider.noPermission",
                            new Object[] {authentication.getName(), returnedObject},
                            "Authentication {0} has NO permissions to the domain object {1}"));
                }
            }
View Full Code Here

                AclEntry[] acls = aclManager.getAcls(returnedObject,
                        authentication);

                if ((acls == null) || (acls.length == 0)) {
                    throw new AccessDeniedException(messages.getMessage(
                            "BasicAclEntryAfterInvocationProvider.noPermission",
                            new Object[] {authentication.getName(), returnedObject},
                            "Authentication {0} has NO permissions at all to the domain object {1}"));
                }

                for (int i = 0; i < acls.length; i++) {
                    // Locate processable AclEntrys
                    if (acls[i] instanceof BasicAclEntry) {
                        BasicAclEntry processableAcl = (BasicAclEntry) acls[i];

                        // See if principal has any of the required permissions
                        for (int y = 0; y < requirePermission.length; y++) {
                            if (processableAcl.isPermitted(requirePermission[y])) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug(
                                        "Principal DOES have permission to return object: "
                                        + returnedObject + " due to ACL: "
                                        + processableAcl.toString());
                                }

                                return returnedObject;
                            }
                        }
                    }
                }

                // No permissions match
                throw new AccessDeniedException(messages.getMessage(
                        "BasicAclEntryAfterInvocationProvider.insufficientPermission",
                        new Object[] {authentication.getName(), returnedObject},
                        "Authentication {0} has ACL permissions to the domain object, but not the required ACL permission to the domain object {1}"));
            }
        }
View Full Code Here

                break;
            }
        }

        if (deny > 0) {
            throw new AccessDeniedException(messages.getMessage(
                    "AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }

        // To get this far, every AccessDecisionVoter abstained
        if (this.isAllowIfAllAbstainDecisions()) {
            return;
        } else {
            throw new AccessDeniedException(messages.getMessage(
                    "AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }
    }
View Full Code Here

        if (grant > deny) {
            return;
        }

        if (deny > grant) {
            throw new AccessDeniedException(messages.getMessage(
                    "AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }

        if ((grant == deny) && (grant != 0)) {
            if (this.allowIfEqualGrantedDeniedDecisions) {
                return;
            } else {
                throw new AccessDeniedException(messages.getMessage(
                        "AbstractAccessDecisionManager.accessDenied",
                        "Access is denied"));
            }
        }

        // To get this far, every AccessDecisionVoter abstained
        if (this.isAllowIfAllAbstainDecisions()) {
            return;
        } else {
            throw new AccessDeniedException(messages.getMessage(
                    "AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }
    }
View Full Code Here

                    if (log.isDebugEnabled()) {
                        log.debug("Verifying that '" + currentUser + "' can modify '" + username + "'");
                    }
                    if (!administrator) {
                        log.warn("Access Denied: '" + currentUser + "' tried to modify '" + username + "'!");
                        throw new AccessDeniedException(ACCESS_DENIED);
                    }
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Registering new user '" + username + "'");
                    }
                }
            }

            // fix for http://issues.appfuse.org/browse/APF-96
            // don't allow users with "user" role to upgrade to "admin" role
            else if (username.equalsIgnoreCase(currentUser) && !administrator) {

                // get the list of roles the user is trying add
                Set userRoles = new HashSet();
                if (user.getRoles() != null) {
                    for (Iterator it = user.getRoles().iterator(); it.hasNext();) {
                        Role role = (Role) it.next();
                        userRoles.add(role.getName());
                    }
                }

                // get the list of roles the user currently has
                Set authorizedRoles = new HashSet();
                for (int i=0; i < roles.length; i++) {
                    authorizedRoles.add(roles[i].getauthority());
                }

                // if they don't match - access denied
                // users aren't allowed to change their roles
                if (!CollectionUtils.isEqualCollection(userRoles, authorizedRoles)) {
                    log.warn("Access Denied: '" + currentUser + "' tried to change their role(s)!");
                    throw new AccessDeniedException(ACCESS_DENIED);
                }
            }
        }
    }
View Full Code Here

                }
            }
        }

        if (deny > 0) {
            throw new AccessDeniedException(messages.getMessage(
                    "AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }

        // To get this far, there were no deny votes
        if (grant > 0) {
            return;
        }

        // To get this far, every AccessDecisionVoter abstained
        if (this.isAllowIfAllAbstainDecisions()) {
            return;
        } else {
            throw new AccessDeniedException(messages.getMessage(
                    "AbstractAccessDecisionManager.accessDenied",
                    "Access is denied"));
        }
    }
View Full Code Here

TOP

Related Classes of org.acegisecurity.AccessDeniedException

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.