List of usage examples for com.liferay.portal.kernel.service RoleLocalServiceUtil getRole
public static com.liferay.portal.kernel.model.Role getRole(long companyId, String name) throws com.liferay.portal.kernel.exception.PortalException
From source file:com.liferay.application.list.my.account.permissions.test.PanelAppMyAccountPermissionsTest.java
License:Open Source License
private boolean _hasMyAccountPermission(long companyId, String portletId) throws Exception { Role userRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER); return ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, portletId, ResourceConstants.SCOPE_COMPANY, String.valueOf(companyId), userRole.getRoleId(), ActionKeys.ACCESS_IN_CONTROL_PANEL); }
From source file:com.liferay.calendar.internal.upgrade.v1_0_5.UpgradeCalendarResource.java
License:Open Source License
protected long getCompanyAdminUserId(Company company) throws PortalException { Role role = RoleLocalServiceUtil.getRole(company.getCompanyId(), RoleConstants.ADMINISTRATOR); long[] userIds = UserLocalServiceUtil.getRoleUserIds(role.getRoleId()); return userIds[0]; }
From source file:com.liferay.calendar.service.test.CalendarBookingServiceTest.java
License:Open Source License
protected void deleteGuestAndUserPermission(Calendar calendar) throws Exception { Role role = RoleLocalServiceUtil.getRole(TestPropsValues.getCompanyId(), RoleConstants.GUEST); ResourcePermissionLocalServiceUtil.setResourcePermissions(TestPropsValues.getCompanyId(), Calendar.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(calendar.getPrimaryKey()), role.getRoleId(), new String[0]); role = RoleLocalServiceUtil.getRole(TestPropsValues.getCompanyId(), RoleConstants.USER); ResourcePermissionLocalServiceUtil.setResourcePermissions(TestPropsValues.getCompanyId(), Calendar.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(calendar.getPrimaryKey()), role.getRoleId(), new String[0]); }
From source file:com.liferay.calendar.upgrade.v1_0_5.test.UpgradeCalendarResourceTest.java
License:Open Source License
protected void assertUserIsAdministrator(long userId) throws PortalException { User user = UserLocalServiceUtil.getUser(userId); Assert.assertFalse(user.isDefaultUser()); Role administratorRole = RoleLocalServiceUtil.getRole(_group.getCompanyId(), RoleConstants.ADMINISTRATOR); Assert.assertTrue(RoleLocalServiceUtil.hasUserRole(user.getUserId(), administratorRole.getRoleId())); }
From source file:com.liferay.exportimport.lar.LayoutCache.java
License:Open Source License
public Role getNameRole(long companyId, String roleName) throws PortalException { Role role = nameRolesMap.get(roleName); if (role == null) { try {//from w w w . j ava 2s . c om role = RoleLocalServiceUtil.getRole(companyId, roleName); nameRolesMap.put(roleName, role); } catch (NoSuchRoleException nsre) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsre, nsre); } } } return role; }
From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java
License:Open Source License
@Override public void importPermissions(String resourceName, long resourcePK, long newResourcePK) throws PortalException { if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { return;/* w ww . ja v a 2s . co m*/ } List<KeyValuePair> permissions = _permissionsMap.get(getPrimaryKeyString(resourceName, resourcePK)); if (permissions == null) { return; } Map<Long, Set<String>> existingRoleIdsToActionIds = ExportImportPermissionUtil .getRoleIdsToActionIds(_companyId, resourceName, newResourcePK); Map<Long, String[]> importedRoleIdsToActionIds = new HashMap<>(); for (KeyValuePair permission : permissions) { String roleName = permission.getKey(); Role role = null; Team team = null; if (ExportImportPermissionUtil.isTeamRoleName(roleName)) { roleName = roleName.substring(ExportImportPermissionUtil.ROLE_TEAM_PREFIX.length()); try { team = TeamLocalServiceUtil.getTeam(_groupId, roleName); } catch (NoSuchTeamException nste) { if (_log.isWarnEnabled()) { _log.warn("Team " + roleName + " does not exist", nste); } continue; } } try { if (team != null) { role = RoleLocalServiceUtil.getTeamRole(_companyId, team.getTeamId()); } else { role = RoleLocalServiceUtil.getRole(_companyId, roleName); } } catch (NoSuchRoleException nsre) { if (_log.isWarnEnabled()) { _log.warn("Role " + roleName + " does not exist", nsre); } continue; } if (isPrivateLayout() && resourceName.equals(Layout.class.getName()) && roleName.equals(RoleConstants.GUEST)) { continue; } String[] actionIds = StringUtil.split(permission.getValue()); importedRoleIdsToActionIds.put(role.getRoleId(), actionIds); } Map<Long, String[]> roleIdsToActionIds = ExportImportPermissionUtil .mergeImportedPermissionsWithExistingPermissions(existingRoleIdsToActionIds, importedRoleIdsToActionIds); ExportImportPermissionUtil.updateResourcePermissions(_companyId, _groupId, resourceName, newResourcePK, roleIdsToActionIds); }
From source file:com.liferay.exportimport.test.LayoutSetPrototypePropagationTest.java
License:Open Source License
@Ignore @Test//from w ww . j av a 2s .c o m public void testLayoutPermissionPropagationWithLinkEnabled() throws Exception { setLinkEnabled(true); Role role = RoleLocalServiceUtil.getRole(TestPropsValues.getCompanyId(), RoleConstants.POWER_USER); ResourcePermissionServiceUtil.setIndividualResourcePermissions(prototypeLayout.getGroupId(), prototypeLayout.getCompanyId(), Layout.class.getName(), String.valueOf(prototypeLayout.getPrimaryKey()), role.getRoleId(), new String[] { ActionKeys.CUSTOMIZE }); prototypeLayout = updateModifiedDate(prototypeLayout, new Date(System.currentTimeMillis() + Time.MINUTE)); CacheUtil.clearCache(prototypeLayout.getCompanyId()); propagateChanges(group); Assert.assertTrue(ResourcePermissionLocalServiceUtil.hasResourcePermission(layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPrimaryKey()), role.getRoleId(), ActionKeys.CUSTOMIZE)); }
From source file:com.liferay.exportimport.test.PermissionExportImportTest.java
License:Open Source License
@Test public void testPortletGuestPermissionsExportImport() throws Exception { // Export//from ww w .j a v a 2 s .c om LayoutSetPrototype exportLayoutSetPrototype = LayoutTestUtil .addLayoutSetPrototype(RandomTestUtil.randomString()); Group exportGroup = exportLayoutSetPrototype.getGroup(); Layout exportLayout = LayoutTestUtil.addLayout(exportGroup, true); String exportResourcePrimKey = PortletPermissionUtil.getPrimaryKey(exportLayout.getPlid(), _PORTLET_ID); Role role = RoleLocalServiceUtil.getRole(TestPropsValues.getCompanyId(), RoleConstants.GUEST); addPortletPermissions(exportGroup, role, exportResourcePrimKey); Element portletElement = exportPortletPermissions(exportGroup, exportLayout); // Import LayoutSetPrototype importLayoutSetPrototype = LayoutTestUtil .addLayoutSetPrototype(RandomTestUtil.randomString()); Group importGroup = importLayoutSetPrototype.getGroup(); Layout importLayout = LayoutTestUtil.addLayout(importGroup, true); String importResourcePrimKey = PortletPermissionUtil.getPrimaryKey(importLayout.getPlid(), _PORTLET_ID); importPortletPermissions(importGroup, importLayout, portletElement); validateImportedPortletPermissions(importGroup, role, importResourcePrimKey); LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(exportLayoutSetPrototype); LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(importLayoutSetPrototype); }
From source file:com.liferay.iframe.web.internal.util.IFrameUtil.java
License:Open Source License
public static boolean isPasswordTokenEnabled(PortletRequest portletRequest) throws PortalException { if (!PropsValues.SESSION_STORE_PASSWORD) { return false; }/* w ww . j av a 2 s. co m*/ ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); String roleName = PropsValues.IFRAME_PASSWORD_PASSWORD_TOKEN_ROLE; if (layout.isPrivateLayout() && layout.getGroup().isUser() && (themeDisplay.getRealUserId() == layout.getGroup().getClassPK())) { return true; } if (Validator.isNull(roleName)) { return false; } try { Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), roleName); if (UserLocalServiceUtil.hasRoleUser(role.getRoleId(), themeDisplay.getUserId())) { return true; } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Error getting role " + roleName + ". The password token " + "will be disabled."); } } return false; }
From source file:com.liferay.message.boards.web.internal.util.MBUserRankUtil.java
License:Open Source License
private static boolean _isEntityRank(long companyId, MBStatsUser statsUser, String entityType, String entityValue) throws Exception { long groupId = statsUser.getGroupId(); long userId = statsUser.getUserId(); if (entityType.equals("organization-role") || entityType.equals("site-role")) { Role role = RoleLocalServiceUtil.getRole(companyId, entityValue); if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(userId, groupId, role.getRoleId(), true)) { return true; }/*from w w w .j a v a 2s . co m*/ } else if (entityType.equals("organization")) { Organization organization = OrganizationLocalServiceUtil.getOrganization(companyId, entityValue); if (OrganizationLocalServiceUtil.hasUserOrganization(userId, organization.getOrganizationId(), false, false)) { return true; } } else if (entityType.equals("regular-role")) { if (RoleLocalServiceUtil.hasUserRole(userId, companyId, entityValue, true)) { return true; } } else if (entityType.equals("user-group")) { UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, entityValue); if (UserLocalServiceUtil.hasUserGroupUser(userGroup.getUserGroupId(), userId)) { return true; } } return false; }