Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Jose Manuel del Aguila
DLFileEntry permissions
20 ottobre 2010 1.34
Risposta

Jose Manuel del Aguila

Punteggio: New Member

Messaggi: 21

Data di Iscrizione: 31 maggio 2010

Messaggi recenti

Hi,

I need some help, I have a DLFileEntry (document) and I need know if user Guest have permission to view this document.

Thanks.
Corné Aussems
RE: DLFileEntry permissions
20 ottobre 2010 3.09
Risposta

Corné Aussems

Punteggio: Liferay Legend

Messaggi: 1271

Data di Iscrizione: 3 ottobre 2006

Messaggi recenti

For any Role you could check permissions on any ResourceId like this

1                List<Permission> permissions = PermissionLocalServiceUtil.getRolePermissions(role.getRoleId(),
2                        resourceId);


how to get the resourceid ?
1ResourceLocalServiceUtil.getResource(fileEntry.getCompanyId(),
2                    DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(fileEntry.getFileEntryId()))
3                    .getResourceId();
Filippo Boatto
RE: DLFileEntry permissions
15 novembre 2010 8.54
Risposta

Filippo Boatto

Punteggio: Junior Member

Messaggi: 99

Data di Iscrizione: 1 febbraio 2007

Messaggi recenti

but in liferay 6.0.5 if PERMISSIONS_USER_CHECK_ALGORITHM = 6
it doesn't return the resourceid and returns 0.


why?
Corné Aussems
RE: DLFileEntry permissions
15 novembre 2010 10.20
Risposta

Corné Aussems

Punteggio: Liferay Legend

Messaggi: 1271

Data di Iscrizione: 3 ottobre 2006

Messaggi recenti

You mean that ResourceLocalServiceUtil.getResource
1ResourceLocalServiceUtil.getResource(fileEntry.getCompanyId(),                    DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(fileEntry.getFileEntryId()))                    .getResourceId();

does not return a resource ?
How about PERMISSIONS_USER_CHECK_ALGORITHM 5 ?
Filippo Boatto
RE: DLFileEntry permissions
16 novembre 2010 0.02
Risposta

Filippo Boatto

Punteggio: Junior Member

Messaggi: 99

Data di Iscrizione: 1 febbraio 2007

Messaggi recenti

yes
1
2Resource res = ResourceLocalServiceUtil.getResource(companyId, DLFolder.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.ValueOf(folder.getPrimaryKey()));


res.getResourceId() returns 0 because:
getResource(...) in ResourceLocalServiceImpl is
 1
 2    public Resource getResource(
 3            long companyId, String name, int scope, String primKey)
 4        throws PortalException, SystemException {
 5
 6        if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
 7            return getResource_6(companyId, name, scope, primKey);
 8        }
 9        else {
10            return getResource_1to5(companyId, name, scope, primKey);
11        }
12    }

and getResource_6(...) make this:
 1
 2    protected Resource getResource_6(
 3        long companyId, String name, int scope, String primKey) {
 4
 5        Resource resource = new ResourceImpl();
 6
 7        resource.setCompanyId(companyId);
 8        resource.setName(name);
 9        resource.setScope(scope);
10        resource.setPrimKey(primKey);
11
12        return resource;
13    }

it doesn't set the resourceid.


if i use algo 5 :
 1
 2    protected Resource getResource_1to5(
 3            long companyId, String name, int scope, String primKey)
 4        throws PortalException, SystemException {
 5
 6        ResourceCode resourceCode = resourceCodeLocalService.getResourceCode(
 7            companyId, name, scope);
 8
 9        return resourcePersistence.findByC_P(resourceCode.getCodeId(), primKey);
10    }

it returns the resourceId but when i set the user permissions on the folder:
1
2PermissionServiceUtil.setUserPermissions(userId, group.getGroupId(), new String[] { ActionKeys.VIEW }, resourceId);

i have an error:
1
2java.lang.NullPointerException
3        at com.liferay.portlet.expando.service.permission.ExpandoColumnPermission.contains(ExpandoColumnPermission.java:66)





How could i create a folder for a user and how to set the only VIEW permission on it
with algorithm 6???
Corné Aussems
RE: DLFileEntry permissions
16 novembre 2010 0.20
Risposta

Corné Aussems

Punteggio: Liferay Legend

Messaggi: 1271

Data di Iscrizione: 3 ottobre 2006

Messaggi recenti

Sorry i can't help you out, i think it's u bug because 6 is only an improved version of 5
I suggest you contact Ray or better submit a bug.
Filippo Boatto
RE: DLFileEntry permissions
16 novembre 2010 0.42
Risposta

Filippo Boatto

Punteggio: Junior Member

Messaggi: 99

Data di Iscrizione: 1 febbraio 2007

Messaggi recenti

and how to contact Ray? :-)
Corné Aussems
RE: DLFileEntry permissions
16 novembre 2010 0.49
Risposta

Corné Aussems

Punteggio: Liferay Legend

Messaggi: 1271

Data di Iscrizione: 3 ottobre 2006

Messaggi recenti

I assume he follows his jira issues(posts/blogs)
New jira issues concerning this subject will be dispatched to him.
and you could almost guess his emailaddress ;)

Good luck
Ray Augé
RE: DLFileEntry permissions
16 novembre 2010 6.17
Risposta

Ray Augé

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 1171

Data di Iscrizione: 7 febbraio 2005

Messaggi recenti

Hey Guys,

A good example of getting Role permissions can be found in com.liferay.portal.lar.PortletDataContextImpl.

Start with the fact that when exporting any entity we begin with a call like this:

portletDataContext.addPermissions(BlogsEntry.class, entry.getEntryId());

You'll notice a method in there:

protected String getActionIds(
Role role, String className, String primKey)

which does:
 1List<String> allActionIds = ResourceActionsUtil.getModelResourceActions(
 2    className);
 3
 4List<String> actionIds = new ArrayList<String>(allActionIds.size());
 5
 6for (String actionId : allActionIds) {
 7    if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 5) {
 8        if (PermissionLocalServiceUtil.hasRolePermission(
 9                role.getRoleId(), role.getCompanyId(), className,
10                ResourceConstants.SCOPE_INDIVIDUAL, primKey,
11                actionId)) {
12
13            actionIds.add(actionId);
14        }
15    }
16    else if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
17        if (ResourcePermissionLocalServiceUtil.hasResourcePermission(
18                role.getCompanyId(), className,
19                ResourceConstants.SCOPE_INDIVIDUAL, primKey,
20                role.getRoleId(), actionId)) {
21
22            actionIds.add(actionId);
23        }
24    }
25}
26
27return StringUtil.merge(actionIds);


You could imagine there at the end another else if block to get the list in the case of algs 1-4.

With alg 5-6 we have reduced the number of tables involved with permissions such that there is no Resource table in use, as such resourceId has no real meaning. In fact with alg 6 there is only 1 table for permissions called ResourcePermission. I'm not going to go into the how's and why's because it is thoroughly discussed elsewhere.

One thing, if you want to perform low level permission operations like this you need to do a check for which algorithm is being used and then behave accordingly. There is no more transparent way.

Hope this helps!
Viktor Palai
RE: DLFileEntry permissions
18 gennaio 2011 7.10
Risposta

Viktor Palai

Punteggio: New Member

Messaggi: 20

Data di Iscrizione: 14 ottobre 2010

Messaggi recenti

Hi Filippo,

have you been able to handle your problem?

I tried this for DLFolder :

ResourcePermissionServiceUtil.setIndividualResourcePermissions(DLTermFolder.getGroupId(), DLTermFolder.getCompanyId(), DLFolder.class.getName(),
new Long(DLTermFolder.getPrimaryKey()).toString(), UserId, viewActionIds);

and it is working but same for DLFileEntry is not working for me :

ResourcePermissionServiceUtil.setIndividualResourcePermissions(DLTestFile.getGroupId(),
DLTestFile.getCompanyId(), DLFileEntry.class.getName(), String.valueOf(DLTestFile.getFileEntryId()), AdministratorId, adminActionIds);

It is throwing :

com.liferay.portal.NoSuchResourceActionException: com.liferay.portlet.documentlibrary.model.DLFileEntry#ACCESS

Dont u have any clue what can cause this problem?

Thank you