Foren

how can get the Administartor user via API

Balázs Csönge, geändert vor 8 Jahren.

how can get the Administartor user via API

Regular Member Beiträge: 107 Beitrittsdatum: 10.11.14 Neueste Beiträge
Hi,

I need to know, how can I get that User object which belongs to THAT admin user who was set up during the portal creation.

I did not found any attribute (like default user) which signs, that is the "alpha admin".
I have to get this admin during the startup, in order to make predefined folders, and that requires some varibales, like companyId, groupId and userId.

I did the following:
		String admin_mail = null;
		User admin = null;
		long companyId = PortalUtil.getDefaultCompanyId();
		
		try {
			admin_mail = PrefsPropsUtil.getString(companyId,PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
		} catch (Exception e) {
			log.error("Error occured during getting the e-mail address of the administrator. Cause: " + e.getMessage() + " The hmadmin@entersoft.hu has been set as a default address.");
			admin_mail = "hmadmin@entersoft.hu";
		}
		
		try {
			admin = UserLocalServiceUtil.fetchUserByEmailAddress(companyId, admin_mail);
		} catch (Exception e) {
			log.error("Error occured during getting the administrator user attributes. Cause: " + e.getMessage());
			throw(new RuntimeException(e));
		}
		
		long userId = admin.getUserId();
		long groupId = 10181;
		
		try {
			groupId = GroupLocalServiceUtil.getGroup(companyId, "Guest").getGroupId();
		} catch (PortalException | SystemException e) {
			log.error("Error occured during getting the group ID value. Cause: " + e.getMessage() + " The 10181 value has been set as default value.");
		}


It worked on my own local liferay, but failed at our server, because in my environment the e-mail address of the alpha admin was same as the admin e-mail address used during the mailing., but this was not true on our server.

Because of the e-mail admin can be modified of the alpha admin, what kind of other way exist to get this admin user via API?
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: how can get the Administartor user via API

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
An administrator is just a user with the administrator role.

Find the role ID using a role query, then get the list of users that have the role. That list will contain the user you're looking for.
Balázs Csönge, geändert vor 8 Jahren.

RE: how can get the Administartor user via API

Regular Member Beiträge: 107 Beitrittsdatum: 10.11.14 Neueste Beiträge
I know all administartor can be retrieved via the role. But I have more than one user with Administrator role and I need that administrator who had been set during the install. That is why I called that admin as alpha admin.

But based on your reply and on the database fields of the USER_ table, I have a bad feeling, I will not able to get that admin... emoticon
thumbnail
Prakash Khanchandani, geändert vor 8 Jahren.

RE: how can get the Administartor user via API

Expert Beiträge: 329 Beitrittsdatum: 10.02.11 Neueste Beiträge
In that case, i think you can try to find a User for whom
1. the defaultUser = 0
2. and createDate is the earliest.
3. And also has the role as Administrator

Hope this helps.
thumbnail
Vishal Kumar, geändert vor 8 Jahren.

RE: how can get the Administartor user via API (Antwort)

Regular Member Beiträge: 198 Beitrittsdatum: 12.12.12 Neueste Beiträge
Yes. Prakash is right with earliest created date you can find.