• REST API grantUser

  • Do you want to create a native client or integrate with third party applications: webservices are the solution.
Do you want to create a native client or integrate with third party applications: webservices are the solution.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #30630  by snorky
 
Hi all,

I am trying to give permissions (READ/WRITE) to a given user on a file.
Here is the code :
Code: Select all
    
private OKMWebservices getAdminWebServiceFacade()
{
    return OKMWebservicesFactory.newInstance("http://localhost:8080/OpenKM/", "okmAdmin", "admin");
}

...
getAdminWebServiceFacade().grantUser(doc.getPath(), userToGrant, 3, recursive);
The problem is that the code execute without error, but when the user tries to check out the file, he is not granted.
Also, just after calling grantUser() method, if i call getGrantedUser(), the user i have just granted is not listed, and i can verifiy it in the admin interface.

Could someone help me using API please.
 #30636  by jllort
 
What openkm version are you using ? and what sdk4j version ?
 #30637  by snorky
 
Hi,
Thank you for answering.
Sorry, i forgot to mention what version i was using :)
I use OpenKM community edition 6.3.0 (build 8156) and i tried it with both SDK 2.1 and 2.2
Notice that since my post, i succeeded to do what i wanted with the following code :
Code: Select all
            sb.append("nodeId=" + URLEncoder.encode(docPath, "UTF-8"))
            .append("&user=" + URLEncoder.encode(userToGrant, "UTF-8"))
            .append("&permissions=" + URLEncoder.encode(Integer.toString(3), "UTF-8"))
            .append("&recursive=" + URLEncoder.encode(Boolean.toString(recursive), "UTF-8"));

            URL url = new URL(ENDPOINT + GRANT_USER_SERVICE);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("PUT");
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestProperty("Content-Length", Integer.toString(sb.toString().getBytes().length));
            Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("okmAdmin", "admin".toCharArray());
                }
            });

            conn.setDoInput(true);
            conn.setDoOutput(true);

            //Send request
            DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
            wr.writeBytes(sb.toString());
            wr.flush();
            wr.close();

            if (conn.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT) {
                System.out.println("Output ERROR from OpenKM .... \n");
                System.out.println(conn.getResponseMessage());
            } else {
                // Nothing to display, response is 'NO_CONTENT'
                System.out.println("User '" + userToGrant + "' granted.");
            }
            conn.disconnect();
 #30652  by jllort
 
OpenKM community version 6.3.0 goes with sdk4j 1.X you should not use version 2.X ( that's for professional 6.4 rest services what are in some sections quite different )

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.