I need to assign roles to my Liferay users on login.
I implemented all the logic in the authenticateByScreenName method of the user class that implements the Authenticator.
Code example:
public class ESBAuthenticator implements Authenticator{ public int authenticateByScreenName(long companyId, String screenName, String password, Map<String, String[]> headerMap, Map<String, String[]> parameterMap) setProfile(companyId, screenname); return 1; } public static void setProfile(long companyId, long userId){ User user = UserLocalServiceUtil.getUser(userId); Role liferayRole = RoleLocalServiceUtil.fetchRole(companyId, "Administrator"); RoleLocalServiceUtil.addUserRole(user.getUserId(), liferayRole.getRoleId()); UserLocalServiceUtil.updateUser(user); } }
When I log into the system, apparently this works, I check the liferay database tables and they are updated, my user has the "Administrator" role assigned. However, the "Admin" option is not displayed on the portal in the interface.

But if I go to "My Account", click on the "Save" button, log out and log in. I have admin access options available.
Does anyone know why this is happening? I call "updateUser ()" after assigning the role. Is this not the same as the save button?
Possible solution: I found that if I clear the contents cached through the cluster, it works fine. I found it in this post:
https://www.liferay.com/es/web/kamesh.sampath1/blog/-/blogs/how-to-clear-liferay-cache
Add the following line:
MultiVMPoolUtil.clear();
Does anyone know if this solution is correct? I canβt find what liferay does when the "Save" button on the "my_account" page is clicked. Maybe this will clear this cache? I was looking for synchronization with the database function, but could not find anything. It seems that if the column is updated, liferay does not use it if it is cached: (.