List of usage examples for com.liferay.portal.kernel.model RoleConstants TYPE_SITE
int TYPE_SITE
To view the source code for com.liferay.portal.kernel.model RoleConstants TYPE_SITE.
Click Source Link
From source file:com.liferay.asset.search.test.AssetSearcherStagingTest.java
License:Open Source License
@Test public void testSiteRolePermissions() throws Exception { Role role = addRole(RoleConstants.TYPE_SITE); String className = "com.liferay.journal.model.JournalArticle"; RoleTestUtil.addResourcePermission(role, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", ActionKeys.VIEW);//from ww w .j a v a2 s. c o m User user = addUser(); ServiceTestUtil.setUser(user); addUserGroupRole(user, role); addJournalArticle(); GroupTestUtil.enableLocalStaging(_group); SearchContext searchContext = getSearchContext(); Group stagingGroup = _group.getStagingGroup(); searchContext.setGroupIds(new long[] { stagingGroup.getGroupId() }); searchContext.setUserId(user.getUserId()); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.addSelectedFieldNames(Field.GROUP_ID, Field.STAGING_GROUP); AssetEntryQuery assetEntryQuery = getAssetEntryQuery(className); Hits hits = search(assetEntryQuery, searchContext); Document[] documents = hits.getDocs(); DocumentsAssert.assertCount(hits.toString(), documents, Field.COMPANY_ID, 1); Document document = documents[0]; assertField(document, Field.GROUP_ID, String.valueOf(stagingGroup.getGroupId())); assertField(document, Field.STAGING_GROUP, StringPool.TRUE); }
From source file:com.liferay.bookmarks.service.test.BookmarksFolderLocalServiceTest.java
License:Open Source License
@Test public void testAddSubfolderPermission() throws Exception { BookmarksFolder folder = BookmarksTestUtil.addFolder(_group.getGroupId(), RandomTestUtil.randomString()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); Role role = RoleLocalServiceUtil.addRole(TestPropsValues.getUserId(), null, 0, StringUtil.randomString(), null, null, RoleConstants.TYPE_SITE, null, serviceContext); ResourceBlockServiceUtil.addCompanyScopePermission(_group.getGroupId(), _group.getCompanyId(), BookmarksFolder.class.getName(), role.getRoleId(), ActionKeys.ADD_SUBFOLDER); User user = UserTestUtil.addGroupUser(_group, role.getName()); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); Assert.assertTrue(BookmarksFolderPermissionChecker.contains(permissionChecker, _group.getGroupId(), folder.getFolderId(), ActionKeys.ADD_FOLDER)); }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.internal.functions.BelongsToRoleFunctionTest.java
License:Open Source License
protected void mockHasSiteRole() throws Exception { Mockito.when(_role.getType()).thenReturn(RoleConstants.TYPE_SITE); Mockito.when(_userGroupRoleLocalService.hasUserGroupRole(Matchers.anyLong(), Matchers.anyLong(), Matchers.eq("Role1"), Matchers.eq(true))).thenReturn(true); }
From source file:com.liferay.roles.admin.demo.data.creator.internal.SiteRoleDemoDataCreatorImpl.java
License:Open Source License
@Override public Role create(long companyId, String roleName, String permissionsXML) throws PortalException { Role role = createRole(companyId, roleName, RoleConstants.TYPE_SITE); if (Validator.isNotNull(permissionsXML)) { addPermissions(role, permissionsXML, ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID)); }/*from w ww.j a va2 s . co m*/ return role; }
From source file:com.liferay.roles.admin.web.internal.portlet.RolesAdminPortlet.java
License:Open Source License
public void updateActions(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long roleId = ParamUtil.getLong(actionRequest, "roleId"); Role role = _roleLocalService.getRole(roleId); String roleName = role.getName(); if (roleName.equals(RoleConstants.ADMINISTRATOR) || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR) || roleName.equals(RoleConstants.ORGANIZATION_OWNER) || roleName.equals(RoleConstants.OWNER) || roleName.equals(RoleConstants.SITE_ADMINISTRATOR) || roleName.equals(RoleConstants.SITE_OWNER)) { throw new RolePermissionsException(roleName); }//from www . jav a2 s . com String portletResource = ParamUtil.getString(actionRequest, "portletResource"); String[] relatedPortletResources = StringUtil .split(ParamUtil.getString(actionRequest, "relatedPortletResources")); String[] modelResources = StringUtil.split(ParamUtil.getString(actionRequest, "modelResources")); Map<String, List<String>> resourceActionsMap = new HashMap<>(); if (Validator.isNotNull(portletResource)) { resourceActionsMap.put(portletResource, ResourceActionsUtil.getResourceActions(portletResource, null)); } for (String relatedPortletResource : relatedPortletResources) { resourceActionsMap.put(relatedPortletResource, ResourceActionsUtil.getResourceActions(relatedPortletResource, null)); } for (String modelResource : modelResources) { resourceActionsMap.put(modelResource, ResourceActionsUtil.getResourceActions(null, modelResource)); } int rootResourceScope = ResourceConstants.SCOPE_COMPANY; String[] rootResourceGroupIds = null; String[] selectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets")); String[] unselectedTargets = StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets")); for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) { String selResource = entry.getKey(); List<String> actions = entry.getValue(); actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale())); for (String actionId : actions) { String target = selResource + actionId; boolean selected = ArrayUtil.contains(selectedTargets, target); if (!selected && !ArrayUtil.contains(unselectedTargets, target)) { continue; } String[] groupIds = StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target)); groupIds = ArrayUtil.distinct(groupIds); int scope = ResourceConstants.SCOPE_COMPANY; if ((role.getType() == RoleConstants.TYPE_ORGANIZATION) || (role.getType() == RoleConstants.TYPE_PROVIDER) || (role.getType() == RoleConstants.TYPE_SITE)) { scope = ResourceConstants.SCOPE_GROUP_TEMPLATE; } else { if (groupIds.length > 0) { scope = ResourceConstants.SCOPE_GROUP; } } updateAction(role, themeDisplay.getScopeGroupId(), selResource, actionId, selected, scope, groupIds); if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) { updateViewControlPanelPermission(role, themeDisplay.getScopeGroupId(), selResource, scope, groupIds); rootResourceScope = scope; rootResourceGroupIds = groupIds; } } } // LPS-38031 if (rootResourceGroupIds != null) { updateViewRootResourcePermission(role, themeDisplay.getScopeGroupId(), portletResource, rootResourceScope, rootResourceGroupIds); } // Send redirect SessionMessages.add(actionRequest, "permissionsUpdated"); String redirect = _portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); if (Validator.isNotNull(redirect)) { actionResponse.sendRedirect(redirect); } }
From source file:com.liferay.site.service.persistence.test.GroupServicePermissionTest.java
License:Open Source License
protected void givePermissionToManageSubsites(Group group) throws Exception { Role role = RoleTestUtil.addRole("Subsites Admin", RoleConstants.TYPE_SITE, Group.class.getName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID), ActionKeys.MANAGE_SUBGROUPS); long[] roleIds = { role.getRoleId() }; UserGroupRoleLocalServiceUtil.addUserGroupRoles(_user.getUserId(), group.getGroupId(), roleIds); }
From source file:com.liferay.site.service.persistence.test.GroupServiceTest.java
License:Open Source License
@Test public void testDeleteOrganizationSiteOnlyRemovesSiteRoles() throws Exception { Organization organization = OrganizationLocalServiceUtil.addOrganization(TestPropsValues.getUserId(), OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, RandomTestUtil.randomString(), true); Group organizationSite = GroupLocalServiceUtil.getOrganizationGroup(TestPropsValues.getCompanyId(), organization.getOrganizationId()); organizationSite.setManualMembership(true); User user = UserTestUtil.addOrganizationOwnerUser(organization); UserLocalServiceUtil.addGroupUser(organizationSite.getGroupId(), user.getUserId()); UserLocalServiceUtil.addOrganizationUsers(organization.getOrganizationId(), new long[] { user.getUserId() }); Role siteRole = RoleTestUtil.addRole(RoleConstants.TYPE_SITE); UserGroupRoleLocalServiceUtil.addUserGroupRoles(user.getUserId(), organizationSite.getGroupId(), new long[] { siteRole.getRoleId() }); GroupLocalServiceUtil.deleteGroup(organizationSite); Assert.assertEquals(1, UserGroupRoleLocalServiceUtil.getUserGroupRolesCount(user.getUserId(), organizationSite.getGroupId())); UserLocalServiceUtil.deleteUser(user); OrganizationLocalServiceUtil.deleteOrganization(organization); }
From source file:com.liferay.users.admin.web.internal.display.context.UserDisplayContext.java
License:Open Source License
private boolean _isSiteRole(UserGroupRole userGroupRole) { long roleId = userGroupRole.getRoleId(); Role role = RoleLocalServiceUtil.fetchRole(roleId); if ((role != null) && (role.getType() == RoleConstants.TYPE_SITE)) { return true; }/* www. j a v a2 s . c om*/ return false; }
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java
License:Open Source License
@Override public List<Role> getSiteRoles(long companyId) throws PortalException { try {/* ww w. j a v a 2 s .com*/ List<Role> allRoles = this.getRolesInCompany(companyId); return this.getRolesForSpecificType(allRoles, RoleConstants.TYPE_SITE); } catch (PortalException e) { e.printStackTrace(); throw e; } }
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularRoleServiceImpl.java
License:Open Source License
public List<UserGroupRole> checkUserGroupRoles(long userId, List<UserGroupRole> userGroupRoles) throws PortalException { List<UserGroupRole> oldUserGroupRoles = null; PermissionChecker permissionChecker = getPermissionChecker(); if (userId != CompanyConstants.SYSTEM) { // Add back any user group roles that the administrator does not // have the rights to remove or that have a mandatory membership User user = UserLocalServiceUtil.getUser(userId); List<UserGroup> userGroups = user.getUserGroups(); for (UserGroup userGroup : userGroups) { List<UserGroupRole> roles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userId, userGroup.getUserGroupId()); oldUserGroupRoles.addAll(roles); }//ww w. ja v a 2 s. c om for (UserGroupRole oldUserGroupRole : oldUserGroupRoles) { Role role = oldUserGroupRole.getRole(); Group group = oldUserGroupRole.getGroup(); if (userGroupRoles.contains(oldUserGroupRole)) { continue; } if (role.getType() == RoleConstants.TYPE_ORGANIZATION) { Organization organization = OrganizationLocalServiceUtil .getOrganization(group.getOrganizationId()); if (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role) || OrganizationMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId, organization.getOrganizationId(), role.getRoleId()) || OrganizationMembershipPolicyUtil.isRoleRequired(userId, organization.getOrganizationId(), role.getRoleId())) { userGroupRoles.add(oldUserGroupRole); } } else if (role.getType() == RoleConstants.TYPE_SITE) { if (!userGroupRoles.contains(oldUserGroupRole) && (!UserGroupRolePermissionUtil.contains(permissionChecker, group, role) || SiteMembershipPolicyUtil.isRoleProtected(getPermissionChecker(), userId, group.getGroupId(), role.getRoleId()) || SiteMembershipPolicyUtil.isRoleRequired(userId, group.getGroupId(), role.getRoleId()))) { userGroupRoles.add(oldUserGroupRole); } } } } // Check that the administrator has the permission to add a new user // group role and that the user group role membership is allowed for (UserGroupRole userGroupRole : userGroupRoles) { if ((oldUserGroupRoles == null) || !oldUserGroupRoles.contains(userGroupRole)) { UserGroupRolePermissionUtil.check(permissionChecker, userGroupRole.getGroupId(), userGroupRole.getRoleId()); } } return userGroupRoles; }