"PermissionChecker not initialised" in scheduler job

Posted on 20/05/2014 by Charalampos Chrysikopoulos

When writing a scheduler job in liferay, you don't have access to the the themeDisplay life in portlet methods. So you miss a lot of handy data.

If you like to call in your job code some of the local utility classes, you could become the following exception:


com.liferay.portal.security.auth.PrincipalException: PermissionChecker not initialized

This is because you don't have the permission to make that call. Just use the following code before your code and everything will be fine.


Company companyqq = CompanyLocalServiceUtil.getCompanyByWebId("myCompanyWebId");
Role adminRole = RoleLocalServiceUtil.getRole(companyqq.getCompanyId(),"Administrator");
List adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());

PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
PermissionChecker permissionChecker =PermissionCheckerFactoryUtil.create(adminUsers.get(0), true);
PermissionThreadLocal.setPermissionChecker(permissionChecker);

myMethod();

source: here

This entry was posted in Liferay and tagged 6.1, Liferay, permission, scheduler by Charalampos Chrysikopoulos