How to set permanent permission with Java API?

I am trying to assign a permanent permission to a group but in nuxeo permission is not working and it is not assigning to any user. My Code is:

String url = “http://localhost:8080/nuxeo”; NuxeoClient nuxeoClient = new NuxeoClient(url, “Administrator”, “Administrator”); org.nuxeo.client.api.objects.Document pathDoc = nuxeoClient.repository().fetchDocumentById(docId); GregorianCalendar begin = new GregorianCalendar(2015, Calendar.JUNE, 20, 12, 34, 56); GregorianCalendar end = new GregorianCalendar(2015, Calendar.JULY, 14, 12, 34, 56); ACE ace = new ACE(); ace.setUsername(“user0”); ace.setPermission(“Write”); ace.setCreator(“Administrator”); ace.setBegin(begin); ace.setEnd(end); ace.setBlockInheritance(true); pathDoc.addPermission(ace);

How can I do this..? Please help me I dont have any other support. Thanks for your support. It will be really helpful for me as I m doing this task since 10 days.

0 votes

1 answers

2114 views

ANSWER



Hi,

I don't understand why you're setting a begin and end date in 2015 for a permanent permission. The added permission won't be activated because the date period is over.

You seem to use the 2.x java client, the supported version is 3.x which works with all Nuxeo version starting from LTS 2016 - 7.10.

If you can use 3.x, you'll be able to not set begin/end date to make a permanent permission.

Otherwise, there's a bug on permanent permission in 2.x, you'll need to workaround it. You can follow https://answers.nuxeo.com/general/q/3671a1cd542144219426b315a0fb71a0/How-to-set-permanent-permission-with-Java-API or set an end date in future, in 2100 for instance.

0 votes



Hello,

I tried to pass the value null in begin and end date but it is not working.

I tried using 3.x java client (Version 3.0.2)

I can not make permanent permission in nuxeo. I tried the following link you provide me, but it is not working.

Here is my code.

For begin and end date i tried to do this also.

GregorianCalendar begin = new GregorianCalendar(); GregorianCalendar end = new GregorianCalendar(9999, Calendar.DECEMBER, 31, 23, 59, 59);

String url = “http://localhost:8080/nuxeo”; NuxeoClient nuxeoClient = new NuxeoClient(url, “Administrator”, “Administrator”); org.nuxeo.client.api.objects.Document pathDoc = nuxeoClient.repository().fetchDocumentById(docId); ACE ace = new ACE(); ace.setUsername(userName); ace.setPermission(NuxeoConstants.NUXEO_PERMISSION_READ); ace.setCreator("Admin"); ace.setBlockInheritance(false); pathDoc.addPermission(ace);

How can I do this..? Please help me I dont have any other support. Thanks for your support. It will be really helpful for me.

Please help us.

Thank u so much.

01/15/2018

I just tried this test with latest nuxeo java client version (3.0.2-SNAPSHOT) and everything works:

    @Test
    public void itCanManagePermanentPermissions() {
        // Create a user
        User user = nuxeoClient.userManager().createUser(ITBase.createUser());
        // First Check
        Document folder = nuxeoClient.repository().fetchDocumentByPath("/folder_2");
        ACP acp = folder.fetchPermissions();
        assertTrue(acp.getAcls().size() != 0);
        assertEquals(1, acp.getAcls().size());
        assertEquals(2, acp.getAcls().get(0).getAces().size());
        assertEquals("inherited", acp.getAcls().get(0).getName());
        // Settings
        ACE ace = new ACE();
        ace.setUsername(user.getUserName());
        ace.setPermission("Write");
        ace.setCreator("Administrator");
        ace.setBlockInheritance(true);
        folder.addPermission(ace);
        // Final Check
        folder = nuxeoClient.repository().fetchDocumentByPath("/folder_2");
        acp = folder.fetchPermissions();
        assertTrue(acp.getAcls().size() != 0);
        assertEquals(1, acp.getAcls().size());
        assertEquals(4, acp.getAcls().get(0).getAces().size());
        assertEquals("local", acp.getAcls().get(0).getName());
        ACE permanentAce = acp.getAcls()
                              .get(0)
                              .getAces()
                              .stream()
                              .filter(a -> user.getUserName().equals(a.getUsername()))
                              .findFirst()
                              .orElseThrow(() -> new AssertionError("Created permanent permission was not found!"));
        assertEquals(ace.getPermission(), permanentAce.getPermission());
        assertNull(permanentAce.getBegin());
        assertNull(permanentAce.getEnd());
    }

Everything works as expected with client and REST API, your issue is somewhere else on server. I can't help you more with details you provided. Please describe what you mean by it is not working: ace is not added, there's a stacktrace in server.log or on client side, no errors but you can't achieve a specific action…

01/16/2018

I want to give permission in nuxeo through nuxeo api. i tried using this following code u wrote above. But I didn't work for me. In backend nuxeo Ui, I can't see the following permission which i have given to specific user.

My code is like this:

                            GregorianCalendar begin = new GregorianCalendar();
            GregorianCalendar end = new GregorianCalendar(9999, Calendar.DECEMBER, 31, 23, 59, 59);

            ACP acp1 = pathDoc.fetchPermissions();
            for(ACL acls:acp1.getAcls()){
                for(ACE aces: acls.getAces()){
                    aces.setUsername(userName);
                    aces.setPermission("Read");
                    aces.setCreator("Admin");
                    aces.setBegin(begin);
                    aces.setEnd(end);
                    pathDoc.addPermission(aces);
                }
            } 

I tried ur code, but it didn't work for me How u have done ?? Please explain and write whole code here. In backend i don't get any error in logs.

How can I do this..? Please help me I dont have any other support. Thanks for your support. It will be really helpful for me.

01/18/2018

Hi,

I just run the code I gave you, and I was able to get the created permission with REST API. What did you get exactly by calling Document#fetchPermissions before and after you add the permission ? You can find that by running my code with your debugger. Please describe 'it doesn't work' each time you need to use it. This will help us to determine where the issue came from.

01/18/2018

Okay I'll try this way. and will sent u logs regarding this. Ill will check all possible ways u told me..

I will defined here stack trace what exactly i want.

And then u help me regarding this.

Thank u for ur support

01/18/2018