List Info

Thread: Programmatically set user permissions




Programmatically set user permissions
user name
2006-04-04 02:22:22
Hi Sven,

Cool, thanks!  I normally
don't do this but due to the fact that we're
sooo pressed for time to finish
this project, I would be extremely grateful if you could
post a code snippet
for this.

Thank you!

--
Cheers,
Kai Rivera

"Get things done."

On 4/3/06, Sven Pfeiffer <sven.pfeifferinnoface.de> wrote:
>
> Hi,
>
> you can use the WebdavResources
aclMethod(java.lang.String path,Ace[]
> aces)
> - method.
>
> Thats what I am working with to let the users change
the ACLs using a gui.
>
> hth
> SVen
>
>
> >-----Original Message-----
> >From: Kai Rivera [mailto:kai.riveragmail.com]
> >Sent: Monday, April 03, 2006 12:28 PM
> >To: slide-userjakarta.apache.org
> >Subject: Programmatically set user permissions
> >
> >Hi,
> >
> >I'm a jakarta slide newbie and am working on a
project where we have to
> >synchronize a file repository in jahia with a
proprietary file
> >repository.
> >In the source directory, all the user permissions
have been set and our
> >client would like us not only to synchronize the
files, but to keep the
> >user permissions too.
> >
> >How do we programmatically set user permissions
with slide?
> >
> >Thanks in advance!
> >
> >--
> >Cheers,
> >Kai Rivera
> >
> >"Get things done."
> >
>
>
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: slide-user-unsubscribejakarta.apache.org
> For additional commands, e-mail: slide-user-helpjakarta.apache.org
>
>
Programmatically set user permissions
user name
2006-04-04 07:36:38
Hi Sven,

Thanks for the tip. Here's the sample program I did that
might help someone
encountering the same issue.

Kai

-----------------------------
package JavaSource;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Enumeration;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpURL;
import org.apache.commons.lang.StringUtils;
import org.apache.webdav.lib.Ace;
import org.apache.webdav.lib.Privilege;
import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.WebdavResources;
import org.apache.webdav.lib.properties.AclProperty;
import org.apache.webdav.lib.util.QName;

public class Permissions {

    static final String URL = "
http://localhost:8080/jahia/webdav/site/myjahia
site/shared/files/";

     static final String USR = "root";
    //static final String USR = "iml";
    //static final String USR = "intranet";

    static final String PATH =
"/jahia/webdav/site/myjahiasite/shared/files/IML/&quo
t;;
    static final String PRINCIPAL =
"/jahia/webdav/site/myjahiasite+/groups/intranetauthor
/members";
    static final String RESOURCE_NAME = "IML";
    static final String PAS = "password";
    static final String NAMESPACE = "DAV:";
    static final String READ = "read";
    static final String WRITE = "write";
    static final String MANAGE = "manage";

    /**
     * param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebdavResource wdr = null;

        try {
            // Print connection info
            System.out.println("URL = " + URL);
            System.out.println("USERNAME = " +
USR);
            System.out.println("PASSWORD = " +
PAS);

            // HttpURL hrl = new HttpURL(USR, PAS, URL);
            HttpURL hrl = new HttpURL(URL);
            hrl.setUserinfo(USR, PAS);

            // Initialize connection to webdav resource
using the define
HttpURL
            // above.
            wdr = new WebdavResource(hrl);
            System.out.println("Path = " +
wdr.getPath());
            System.out.println("WebdavResource Name =
" + wdr.getName());

            // Get the child resources (folder/s or file/s)
of the
            // retrieved web dave resource.
            WebdavResources resources =
wdr.getChildResources();
            WebdavResource[] resourceList =
resources.listResources();
            int counter = resourceList.length;
            System.out.println("No. of Child Resouces
= " + counter);

            // Check if the resource RESOURCE_NAME is one of
the child
resources
            boolean hasResource =
resources.isThereResourceName
(RESOURCE_NAME);
            System.out.println("Has child resource
" + RESOURCE_NAME + "? "
                    + hasResource);

            // Get all the child resources
            for (int i = 0; i < counter; i++) {
                WebdavResource resource = resourceList[i];
                String resourceName = resource.getName();
                System.out.println
("========================================");
                System.out.println("Resource Name =
" + resourceName);
                System.out.println
("========================================");
                AclProperty acl =
resource.aclfindMethod(PATH);
                Ace[] aces = acl.getAces();
                int length = aces.length;
                for (int j = 0; j < length; j++) {
                    Ace ace = aces[j];
                    showAceProperties(ace);
                   
showAcePrivileges(ace.enumeratePrivileges());
                    System.out.println
("****************************************************
****");

                }

                // Adding the new Ace for the group
IMLAUTHOR
                if (StringUtils.equals(resourceName,
RESOURCE_NAME)){
                    Ace ace = new
Ace("/jahia/webdav/site/myjahiasite+/groups/imlauthor/
members");
                    // Do not deny access
                    ace.setNegative(false);
                    // Not Protected
                    ace.setProtected(false);
                    // Not Inherited
                    ace.setInherited(false);
                    ace.setInheritedFrom(null);

                    // Read, Write and Manage privileges
                    Privilege readPrivilege = new
Privilege(NAMESPACE, READ,
null);
                    Privilege writePrivilege = new
Privilege(NAMESPACE,
WRITE, null);
                    Privilege managePrivilege = new
Privilege(NAMESPACE,
MANAGE, null);
                    ace.addPrivilege(readPrivilege);
                    ace.addPrivilege(writePrivilege);
                    ace.addPrivilege(managePrivilege);

                    // Display new Ace properties and
privileges to be added
to the web dav resource
                    System.out.println("These are the
new ace properties and
privileges: ");
                    showAceProperties(ace);
                   
showAcePrivileges(ace.enumeratePrivileges());


                    // Update the web dav resource's aces
                    Ace[] oldAces=aces;
                    aces=new Ace[oldAces.length+1];
                    System.arraycopy(oldAces, 0, aces, 0,
oldAces.length);

                    // Add new Ace
                    aces[oldAces.length] = ace;

                    System.out.println("Performing
aclMethod(" + PATH + ",
aces) method...");
                    boolean updateAces = wdr.aclMethod(PATH,
aces);
                    System.out.println("Update Aces
successful? " +
updateAces);
                }


            }

        } catch (MalformedURLException mue) {
           
System.out.println("MalformedURLException");
            mue.printStackTrace();
        } catch (HttpException he) {
            System.out.println("HttpException");
            he.printStackTrace();
        } catch (IOException ioe) {
            System.out.println("IOException");
            ioe.printStackTrace();
        } catch (Exception e) {
            System.out.println("Exception");
            e.printStackTrace();
        } finally {
            try {
            // It is important to close the webdav resource
connection
            wdr.close();
            } catch (IOException ioe){
               
System.out.println("IOException");
                ioe.printStackTrace();
            }
        }
    }

    /**
     * Display properties of the AclMethod's ace object
     *
     * param ace
     */
    private static void showAceProperties(Ace ace) {
        System.out.println("Principal = " +
ace.getPrincipal());
        System.out.println("Property = " +
ace.getProperty());
        System.out.println("Is Negative? = " +
ace.isNegative());
        System.out.println("Is Protected? = " +
ace.isProtected());
        System.out.println("Is Inherited? = " +
ace.isInherited());
        if (ace.isInherited())
            System.out.println("Inherited From  =
" + ace.getInheritedFrom
());

    }

    /**
     * param privileges
     */
    private static void showAcePrivileges(Enumeration
privileges) {
        System.out.println("Privileges: ");
        while (privileges != null &&
privileges.hasMoreElements()) {
            Privilege privilege = (Privilege)
privileges.nextElement();
            System.out.println("Name = " +
privilege.getName());
            System.out.println("Namespace = " +
privilege.getNamespace());
            System.out.println("Parameter = " +
privilege.getParameter());
        }
    }

}


On 4/4/06, Kai Rivera <kai.riveragmail.com> wrote:
>
> Hi Sven,
>
> Cool, thanks!  I normally
don't do this but due to the fact that we're
> sooo pressed for time to finish
> this project, I would be extremely grateful if you
could post a code
> snippet for this.
>
> Thank you!
>
> --
>
> Cheers,
> Kai Rivera
>
> "Get things done."
>
> On 4/3/06, Sven Pfeiffer <sven.pfeifferinnoface.de> wrote:
> >
> > Hi,
> >
> > you can use the WebdavResources
aclMethod(java.lang.String path,Ace[]
> > aces)
> > - method.
> >
> > Thats what I am working with to let the users
change the ACLs using a
> > gui.
> >
> > hth
> > SVen
> >
> >
> > >-----Original Message-----
> > >From: Kai Rivera [mailto:kai.riveragmail.com]
> > >Sent: Monday, April 03, 2006 12:28 PM
> > >To: slide-userjakarta.apache.org
> > >Subject: Programmatically set user permissions
> > >
> > >Hi,
> > >
> > >I'm a jakarta slide newbie and am working on
a project where we have to
> > >synchronize a file repository in jahia with a
proprietary file
> > >repository.
> > >In the source directory, all the user
permissions have been set and our
> > >client would like us not only to synchronize
the files, but to keep the
> > >user permissions too.
> > >
> > >How do we programmatically set user
permissions with slide?
> > >
> > >Thanks in advance!
> > >
> > >--
> > >Cheers,
> > >Kai Rivera
> > >
> > >"Get things done."
> > >
> >
> >
> >
------------------------------------------------------------
---------
> > To unsubscribe, e-mail: slide-user-unsubscribejakarta.apache.org
> > For additional commands, e-mail:
slide-user-helpjakarta.apache.org
> >
> >
>
>
>
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )