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
Initialize serviceContext without request
hi
I create Service Context object and used it in the addFolder method in the DLAppServiceUtil class and I get the Principal is null exception
my code is :
I create Service Context object and used it in the addFolder method in the DLAppServiceUtil class and I get the Principal is null exception
my code is :
long companyId = CompanyLocalServiceUtil.getCompanyByMx( PropsUtil.get( PropsKeys.COMPANY_DEFAULT_WEB_ID ) ).getCompanyId();
Group group = GroupLocalServiceUtil.fetchGroup( companyId, GroupConstants.GUEST );
long groupId = group.getGroupId();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId( groupId );
serviceContext.setCompanyId( companyId );
DLAppServiceUtil.addFolder( groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "ALI", "---", serviceContext );
Hi,
This may be because the user from which you are doing this might not have permission to add folder to the repository.
Try once setting userid also in serviceContext.setuserId( userId); and check
This may be because the user from which you are doing this might not have permission to add folder to the repository.
Try once setting userid also in serviceContext.setuserId( userId); and check
hi
I add admin user to my service context object ,But I still have this problem
User userByEmailAddress = UserLocalServiceUtil.getUserByEmailAddress( companyId, " " );
I add admin user to my service context object ,But I still have this problem
User userByEmailAddress = UserLocalServiceUtil.getUserByEmailAddress( companyId, " " );
If this code isn't initiated from a request (eg startupAction, or scheduled job), then it rightly throws a principal is null exception which means there's no user doing the action. Usually if this is the case, it probably means you don't want to check permissions anyway because you're controlling the execution of the code. So you should call the DLAppLocalService method which does not check permissions.
Hi,
You can set the permission checker and see
You can set the permission checker and see
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(adminUser);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
Amos Fong:
If this code isn't initiated from a request (eg startupAction, or scheduled job), then it rightly throws a principal is null exception which means there's no user doing the action. Usually if this is the case, it probably means you don't want to check permissions anyway because you're controlling the execution of the code. So you should call the DLAppLocalService method which does not check permissions.
Thank you very much
I answered your solution
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™