Package org.apache.slide.common

Examples of org.apache.slide.common.Uri


     */
    public void revokePermission(SlideToken token, NodePermission permission)
        throws ServiceAccessException, ObjectNotFoundException,
        AccessDeniedException, VetoException {
       
        Uri objectUri = namespace.getUri(token, permission.getObjectUri());
        ObjectNode object = objectUri.getStore().retrieveObject(objectUri);
       
        checkCredentials(token, object,
                         namespaceConfig.getRevokePermissionAction());
        objectUri.getStore().revokePermission(objectUri, permission);

        // Fire event
        if ( SecurityEvent.REVOKE_PERMISSION.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(SecurityEvent.REVOKE_PERMISSION, new SecurityEvent(this, token, namespace, objectUri, permission));
    }
View Full Code Here


                // check if permission has already been checked
                Boolean permission = token.checkPermissionCache(object, action);
                if (permission == null) {
                    // if not checked before, check now
                    try {
                        Uri objectUri = namespace.getUri(token, object.getUri());
                        ObjectNode realObject = objectUri.getStore()
                            .retrieveObject(objectUri);
                        checkPermission(token, realObject, action);
                        token.cachePermission(object, action, true);
                    } catch (AccessDeniedException ade) {
                        token.cachePermission(object, action, false);
View Full Code Here

        boolean denied = false;
        boolean rootObjectReached = false;
       
        ObjectNode courObject = object;
       
        Uri subjectUri = namespace.getUri(subject.getUri());
        Uri actionUri = namespace.getUri(action.getUri());
       
        // check if allready granded
       
        while (!granted && !denied && !rootObjectReached) {
           
            Uri courUri = namespace.getUri(courObject.getUri());
            Enumeration permissions = courUri.getStore()
                .enumeratePermissions(courUri);
           
            while (permissions.hasMoreElements()) {
               
                boolean oldGranted = granted;
                boolean oldDenied = denied;
               
                NodePermission permission =
                    (NodePermission) permissions.nextElement();
                String permissionSubject = permission.getSubjectUri();
               
                if (permissionSubject.equals(SubjectNode.SELF_URI)) {
                   
                    boolean check;
                    check = object.getUri().equals(subjectUri.toString());
                    if (permission.isInheritable()) {
                        String subjectUriString = subjectUri.toString();
                        if(!subjectUriString.endsWith("/"))
                            subjectUriString = subjectUriString + "/";
                       
                        check |= object.getUri().startsWith(subjectUriString);
                    }
                   
                    // Self permission
                    granted = (!permission.isNegative())
                        && (check)
                        && (actionUri.toString()
                                .startsWith(permission.getActionUri()));
                    denied = (permission.isNegative())
                        && (check)
                        && (actionUri.toString()
                                .startsWith(permission.getActionUri()));
                   
                } else if (permission.isInheritable()
                           || permission.getObjectUri().equals(object.getUri())) {
                   
                    if (permissionSubject.startsWith("/")) {
                       
                        // Node permission
                       
                        String permSubj = permission.getSubjectUri();
                        if(!permSubj.endsWith("/"))
                            permSubj = permSubj + "/";
                        boolean match = subjectUri.toString().
                            equals(permission.getSubjectUri()) ||
                            subjectUri.toString().startsWith(permSubj);
                        match &= actionUri.toString().
                            startsWith(permission.getActionUri());
                       
                        granted = (!permission.isNegative()) && match;
                        denied = permission.isNegative() && match;
                       
                    } else if (permissionSubject.startsWith("+")) {
                       
                        // Permission group which needs to be expanded
                        Uri permissionSubjectUri =
                            namespace.getUri(permissionSubject.substring(1));
                        ObjectNode group =
                            permissionSubjectUri.getStore().retrieveObject
                            (permissionSubjectUri);
                        // if the node is a GroupNode, expand it out to
                        // normal permissions
                        if (group instanceof
                            org.apache.slide.structure.GroupNode ) {
                            if (group.hasChildren()) {
                                Enumeration groupMembers =
                                    group.enumerateChildren();
                                // parse thru the children of the group and
                                // check permissions on each
                                while (groupMembers.hasMoreElements()) {
                                   
                                    oldGranted = granted;
                                    oldDenied = denied;
                                   
                                    Uri childUri =
                                        namespace.getUri
                                        ((String) groupMembers.nextElement());
                                    ObjectNode childNode =
                                        childUri.getStore().retrieveObject
                                        (childUri);
                                    String childSubjectUri = childNode
                                        instanceof LinkNode ?
                                        ((LinkNode) childNode)
                                        .getLinkedUri() :
                                        childNode.getUri() ;
                                   
                                    String testUri;
                                    if(!childSubjectUri.endsWith("/"))
                                        testUri = childSubjectUri+"/";
                                    else
                                        testUri = childSubjectUri;
                                   
                                    boolean match = subjectUri.toString().
                                        equals(childSubjectUri) ||
                                        subjectUri.toString().
                                        startsWith(testUri);
                                    match &= actionUri.toString().
                                        startsWith(permission.getActionUri());
                                   
                                    granted = (!permission.isNegative()) &&
                                        match;
                                    denied = permission.isNegative() && match;
                                   
                                    granted = granted | oldGranted;
                                    denied = denied | oldDenied;
                                   
                                }
                            }
                        }
                       
                    } else {
                       
                        // Role permission
                        granted = (!permission.isNegative())
                            && (hasRole(subject, permissionSubject))
                            && (actionUri.toString()
                                    .startsWith(permission.getActionUri()));
                        denied = (permission.isNegative())
                            && (hasRole(subject, permissionSubject))
                            && (actionUri.toString()
                                    .startsWith(permission.getActionUri()));
                       
                    }
                   
                }
               
                granted = granted | oldGranted;
                denied = denied | oldDenied;
               
            }
           
            Uri parentUri = courUri.getParentUri();
           
            if (parentUri != null) {
                courObject = parentUri.getStore()
                    .retrieveObject(parentUri);
            } else {
                rootObjectReached = true;
            }
        }
View Full Code Here

    public Enumeration enumeratePermissions(SlideToken token,
                                            String object,
                                            boolean includeInherited)
        throws ServiceAccessException, ObjectNotFoundException {
       
        Uri objectUri = namespace.getUri(token, object);
        if (!includeInherited) {
            return objectUri.getStore().enumeratePermissions(objectUri);
        }
        else {
            ObjectNode objectNode = objectUri.getStore().retrieveObject(objectUri);
            Iterator i = retrieveAclSourceNodes(token, objectNode).iterator();
            Vector permissions = new Vector();
            while (i.hasNext()) {
                ObjectNode oNode = (ObjectNode)i.next();
                Uri oUri = namespace.getUri(token, oNode.getUri());
                Enumeration permEnum = oUri.getStore().enumeratePermissions(oUri);
                while (permEnum.hasMoreElements()) {
                    NodePermission perm = (NodePermission)permEnum.nextElement();
                    if (object.equals(oNode.getUri())) {
                      // FIXME A node should not be able to inherit permissions from itself.
            // Hide this from the client when it happens.
View Full Code Here

            token.getCredentialsToken().getPublicCredentials();
        if ((user == null) || user.equals("") || user.equals("/")) {
            return SubjectNode.UNAUTHENTICATED;
        }
       
        Uri subjectUri = namespace.getUri
            (token, namespaceConfig.getUsersPath()+"/"+user);
       
        try {
            return subjectUri.getStore().retrieveObject(subjectUri);
        } catch (ObjectNotFoundException e) {
            if (!namespaceConfig.isAutoCreateUsers()) {
                throw e;
            }
            else {
                try {
                    Uri parentUri = subjectUri.getParentUri();
                    ObjectNode parent =
                        subjectUri.getStore().retrieveObject(parentUri);
                    Enumeration childrenEnum = parent.enumerateChildren();
                    Enumeration linksEnum = parent.enumerateLinks();
                    Vector children = new Vector();
                    while (childrenEnum.hasMoreElements()) {
                        children.addElement(childrenEnum.nextElement());
                    }
                    children.addElement(subjectUri.toString());
                    Vector links = new Vector();
                    while (linksEnum.hasMoreElements()) {
                        links.addElement(linksEnum.nextElement());
                    }
                   
                    // First, load the object's class
                    Class objectClass = Class.forName
                        (namespaceConfig.getAutoCreateUsersRole());
                    Class[] types = { String.class };
                    Object[] args = { subjectUri.toString() };
                    Constructor constructor =
                        objectClass.getConstructor(types);
                    ObjectNode object =
                        (ObjectNode) constructor.newInstance(args);
                    subjectUri.getStore().createObject(subjectUri, object);
                   
                    Class[] types2 =
                    { String.class, Vector.class, Vector.class };
                    Object[] args2 = { parentUri.toString(), children, links };
                    constructor = parent.getClass().getConstructor(types2);
                    object = (ObjectNode) constructor.newInstance(args2);
                    parentUri.getStore().storeObject(parentUri, object);
                   
                    NodeRevisionNumber initialRevision = new NodeRevisionNumber(1, 0); // new NodeRevisionNumber();
                    Hashtable workingRevisions = new Hashtable();
                    workingRevisions.put(NodeRevisionDescriptors.MAIN_BRANCH, initialRevision);
                    Hashtable latestRevisionNumbers = new Hashtable();
View Full Code Here

     * @throws   SlideException
     * @throws   JDOMException
     */
    private static synchronized Set getActionAggregates(SecurityImpl security, SlideToken token, ActionNode aNode) throws SlideException, JDOMException {
        Set result = new HashSet();
        Uri aNodeUri = security.namespace.getUri(token, aNode.getUri());
        NodeRevisionDescriptor aNrd = aNodeUri.getStore().retrieveRevisionDescriptor(aNodeUri, new NodeRevisionNumber());
        NodeProperty membersProp = aNrd.getProperty(PRIVILEGE_MEMBER_SET);
        if (membersProp != null && membersProp.getValue() != null) {
            XMLValue membersVal;
            if (membersProp.getValue() instanceof XMLValue) {
                membersVal = (XMLValue)membersProp.getValue();
            }
            else {
                membersVal = new XMLValue((String)membersProp.getValue());
            }
            security.logger.log(membersVal.getHrefStrings(), LOG_CHANNEL, Logger.DEBUG);
            Iterator mUris = membersVal.getHrefStrings().iterator();
            while (mUris.hasNext()) {
                String uriAsString = (String)mUris.next();
                Uri uri = security.namespace.getUri(token, uriAsString);
                NodeRevisionNumber latestRevisionNumber = aNodeUri.getStore().retrieveRevisionDescriptors(uri).getLatestRevision();
                if (latestRevisionNumber != null) {
                    NodeProperty privilegeNamespace = aNodeUri.getStore().retrieveRevisionDescriptor(uri, latestRevisionNumber).getProperty(PRIVILEGE_NAMESPACE, "DAV:");
                    org.jdom.Namespace namespace = null;
                    if (privilegeNamespace != null && privilegeNamespace.getValue() instanceof String) {
View Full Code Here

    public boolean matchPrincipal(SlideToken token, SubjectNode checkSubject, SubjectNode matchSubject, int level) throws ServiceAccessException {
        if (matchSubject.equals(checkSubject)) {
            return true;
        }
        else {
            Uri groupUri = namespace.getUri(token, matchSubject.getUri());
            try {
                NodeRevisionDescriptor nrd =
                    groupUri.getStore().retrieveRevisionDescriptor(groupUri, new NodeRevisionNumber());
                NodeProperty membersetProp = nrd.getProperty("group-member-set");
                if (membersetProp != null && membersetProp.getValue() != null) {
                    XMLValue xmlVal = new XMLValue((String)membersetProp.getValue());
                    List memberNodes = xmlVal.getHrefNodes();
                    if (memberNodes.contains(checkSubject)) {
View Full Code Here

        ActionsCache cache = getActionsCache(security);
        try {
            cache.aggregation = new HashMap();
            cache.aggregationClosure = new HashMap();
            String actionsPath = security.namespaceConfig.getActionsPath();
            Uri actionsPathUri = security.namespace.getUri(token, actionsPath);
            ObjectNode actionsPathNode = actionsPathUri.getStore().retrieveObject(actionsPathUri);
            Enumeration actions = actionsPathNode.enumerateChildren();
            addActionLeafsToActionAggregation(security, token, cache, actions);

            Iterator keys = cache.aggregationClosure.keySet().iterator();
            while (keys.hasNext()) {
View Full Code Here

     * @throws SlideException
     * @throws JDOMException
     */
    private static synchronized void addActionLeafsToActionAggregation(SecurityImpl security, SlideToken token, ActionsCache cache, Enumeration actions) throws SlideException, JDOMException {
        while (actions.hasMoreElements()) {
            Uri aNodeUri = security.namespace.getUri(token, (String)actions.nextElement());
            ObjectNode oNode = security.namespace.getStore(aNodeUri.getScope()).retrieveObject(aNodeUri);
            if (oNode.hasChildren()) {
                if (security.logger.isEnabled(Logger.DEBUG)) {
                    security.logger.log("Adding children of action " + oNode.getUri() + " to action aggregation", LOG_CHANNEL, Logger.DEBUG);
                }
                addActionLeafsToActionAggregation(security, token, cache, oNode.enumerateChildren());
            } else {
                if (security.logger.isEnabled(Logger.DEBUG)) {
                    security.logger.log("Adding action " + oNode.getUri() + " to action aggregation", LOG_CHANNEL, Logger.DEBUG);
                }
                NodeRevisionNumber latestRevisionNumber = security.namespace.getStore(aNodeUri.getScope()).retrieveRevisionDescriptors(aNodeUri).getLatestRevision();
                NodeProperty privilegeNamespace = security.namespace.getStore(aNodeUri.getScope()).retrieveRevisionDescriptor(aNodeUri, latestRevisionNumber).getProperty(PRIVILEGE_NAMESPACE, "DAV:");
                ActionNode aNode;
                org.jdom.Namespace actionNamespace;
                if (privilegeNamespace != null && privilegeNamespace.getValue() instanceof String) {
                    actionNamespace = org.jdom.Namespace.getNamespace((String) privilegeNamespace.getValue());
                } else {
View Full Code Here

        ActionsCache cache = getActionsCache(security);
        if (!cache.hasBeenLoaded()) {
            loadActionsCache(security, token);
        }
        if (cache.hasLoadingFailed()) {
            Uri u = security.namespace.getUri(token, uri);
            Store s = u.getStore();
            throw new ServiceAccessException(s, "Actions cache not loaded");
        }
        return cache.aggregationClosure;
    }
View Full Code Here

TOP

Related Classes of org.apache.slide.common.Uri

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.