Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Managing Role using web services
Hello,
I'm trying to create roles using jsonws api called by a Java application that run on a different location from the liferay installation. I managed to create new roles using the url syntax
/api/jsonws/role/add-role?className=className&classPk=5&name=name5&titleMap{"en_US":"title"}&descriptionMap{"en_US":"description"}&type=1&subtype=sub
Whilst the role is created successfully it doesn't appear in Liferay's roles menu, but using the api I can find it with the roleId.
I've also managed to add the created role to a user using the api, but still I can't see it from Liferay's interface.
Moreover I can't figure out how to add role permissions using the jsonws api.
Do anyone know how to correctly create roles with jsonws api to let them be seen in Liferay's interface and to add permissions?
I'm trying to create roles using jsonws api called by a Java application that run on a different location from the liferay installation. I managed to create new roles using the url syntax
/api/jsonws/role/add-role?className=className&classPk=5&name=name5&titleMap{"en_US":"title"}&descriptionMap{"en_US":"description"}&type=1&subtype=sub
Whilst the role is created successfully it doesn't appear in Liferay's roles menu, but using the api I can find it with the roleId.
I've also managed to add the created role to a user using the api, but still I can't see it from Liferay's interface.
Moreover I can't figure out how to add role permissions using the jsonws api.
Do anyone know how to correctly create roles with jsonws api to let them be seen in Liferay's interface and to add permissions?
you left out some details, but my guess is that whatever values you're using for the className and classPK values do not correspond with what the UI is requesting when getting roles to display.
After all, if you inject junk into your database, you can't expect Liferay to treat it like real data.
If you're having problems figuring out the values to use, take a look at a role in the DB to see what class names and PKs are used. Note, however, that keys can be different across different Liferay environments, so don't assume that a PK value of 5 from one environment matches in every other environment.
AFAIK there is no way to enable specific permissions within roles. I think it is too dependent upon defined permissions in the environment itself and not necessarily subject to external retrieval.
After all, if you inject junk into your database, you can't expect Liferay to treat it like real data.
If you're having problems figuring out the values to use, take a look at a role in the DB to see what class names and PKs are used. Note, however, that keys can be different across different Liferay environments, so don't assume that a PK value of 5 from one environment matches in every other environment.
AFAIK there is no way to enable specific permissions within roles. I think it is too dependent upon defined permissions in the environment itself and not necessarily subject to external retrieval.
Thank you, I've checked the database and fixed the records and now Liferay is displaying the new roles.
I tried to do "rolemanagement" using the jsonws api too in Liferay 6. But our usecases could not be implemented since the remote API is to limited. It is simply impossible to set permissions on entities since some of the required parameters are not marked with the @JSON annotation and therefore not available when e.g. a journalarticle is fetched.
We implemented our own rest services and used the *LocalService methods in them. It really paid off to do that, it was easier to implement and the interface became a lot cleaner. We used the Fake Entities approach in Liferay 6 (There's a very helpful blog post about it by David describing it). With Liferay 7 we didn't need that workaround anymore and simply implemented our own rest services (there is a blade/IDE rest module template) for "everything" we needed and completely ignored the jsonws api afterwards.
We implemented our own rest services and used the *LocalService methods in them. It really paid off to do that, it was easier to implement and the interface became a lot cleaner. We used the Fake Entities approach in Liferay 6 (There's a very helpful blog post about it by David describing it). With Liferay 7 we didn't need that workaround anymore and simply implemented our own rest services (there is a blade/IDE rest module template) for "everything" we needed and completely ignored the jsonws api afterwards.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™