Page 1 of 1

REST API grantUser

PostPosted:Wed Dec 03, 2014 10:44 am
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.

Re: REST API grantUser

PostPosted:Thu Dec 04, 2014 9:03 am
by jllort
What openkm version are you using ? and what sdk4j version ?

Re: REST API grantUser

PostPosted:Thu Dec 04, 2014 3:43 pm
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();

Re: REST API grantUser

PostPosted:Mon Dec 08, 2014 10:02 am
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 )