List of usage examples for com.liferay.portal.kernel.security.permission PermissionThreadLocal getPermissionChecker
public static PermissionChecker getPermissionChecker()
From source file:com.liferay.alloy.mvc.jsonwebservice.BaseAlloyControllerInvokerImpl.java
License:Open Source License
protected DynamicServletRequest createRequest(String lifecycle, Object... parameters) throws Exception { if ((parameters.length % 2) != 0) { throw new IllegalArgumentException("Parameters length is not an even number"); }//from w w w . j a v a 2 s . co m HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper( new AlloyMockUtil.MockHttpServletRequest()); DynamicServletRequest request = new DynamicServletRequest(requestWrapper, false); for (int i = 0; i < parameters.length; i += 2) { request.appendParameter(String.valueOf(parameters[i]), String.valueOf(parameters[i + 1])); } request.appendParameter("controller", _controller); request.appendParameter("format", "json"); ThemeDisplay themeDisplay = (ThemeDisplay) _themeDisplay.clone(); PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); User user = UserLocalServiceUtil.getUser(permissionChecker.getUserId()); themeDisplay.setUser(user); request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay); request.setAttribute(WebKeys.LAYOUT, themeDisplay.getLayout()); LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) PortletConfigFactoryUtil.create(_portlet, null); request.setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, liferayPortletConfig); request.setAttribute(JavaConstants.JAVAX_PORTLET_PORTLET, _alloyPortlet); PortletRequest portletRequest = null; PortletResponse portletResponse = null; if (lifecycle.equals(PortletRequest.ACTION_PHASE)) { portletRequest = createActionRequest(); portletResponse = createActionResponse(); } else { portletRequest = createRenderRequest(); portletResponse = createRenderResponse(request, _portlet.getRootPortletId(), themeDisplay.getPlid(), lifecycle); } request.setAttribute(JavaConstants.JAVAX_PORTLET_REQUEST, portletRequest); request.setAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE, portletResponse); request.setAttribute(PortletRequest.LIFECYCLE_PHASE, lifecycle); request.setAttribute(BaseAlloyControllerImpl.VIEW_PATH, StringPool.BLANK); return request; }
From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java
License:Open Source License
protected void exportAssetObjects(PortletDataContext portletDataContext, PortletPreferences portletPreferences) throws Exception { List<AssetEntry> assetEntries = null; Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic"); if (selectionStyle.equals("dynamic")) { if (!_assetPublisherWebConfiguration.dynamicExportEnabled()) { return; }//from w ww . j av a 2 s .co m AssetEntryQuery assetEntryQuery = getAssetEntryQuery(layout, portletDataContext.getCompanyGroupId(), portletDataContext.getScopeGroupId(), portletPreferences); long assetVocabularyId = GetterUtil.getLong(portletPreferences.getValue("assetVocabularyId", null)); if (assetVocabularyId > 0) { mergeAnyCategoryIds(assetEntryQuery, assetVocabularyId); if (ArrayUtil.isEmpty(assetEntryQuery.getAnyCategoryIds())) { return; } } BaseModelSearchResult<AssetEntry> baseModelSearchResult = AssetPublisherUtil.getAssetEntries( assetEntryQuery, layout, portletPreferences, AssetPublisherPortletKeys.ASSET_PUBLISHER, LocaleUtil.getDefault(), TimeZoneUtil.getDefault(), portletDataContext.getCompanyId(), portletDataContext.getScopeGroupId(), UserConstants.USER_ID_DEFAULT, new HashMap<String, Serializable>(), assetEntryQuery.getStart(), assetEntryQuery.getEnd()); assetEntries = baseModelSearchResult.getBaseModels(); } else { if (!_assetPublisherWebConfiguration.manualExportEnabled()) { return; } long[] groupIds = AssetPublisherUtil.getGroupIds(portletPreferences, portletDataContext.getScopeGroupId(), layout); assetEntries = AssetPublisherUtil.getAssetEntries(null, portletPreferences, PermissionThreadLocal.getPermissionChecker(), groupIds, false, false); } for (AssetEntry assetEntry : assetEntries) { AssetRenderer<?> assetRenderer = assetEntry.getAssetRenderer(); if ((assetRenderer == null) || !(assetRenderer.getAssetObject() instanceof StagedModel)) { continue; } StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, portletDataContext.getPortletId(), (StagedModel) assetRenderer.getAssetObject()); } }
From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java
License:Open Source License
protected void updateImportScopeIds(PortletDataContext portletDataContext, PortletPreferences portletPreferences, String key, long companyGroupId, long plid) throws Exception { String[] oldValues = portletPreferences.getValues(key, null); if (oldValues == null) { return;/*from w w w. j av a2 s. c om*/ } StagedModelDataHandler<StagedGroup> stagedModelDataHandler = (StagedModelDataHandler<StagedGroup>) StagedModelDataHandlerRegistryUtil .getStagedModelDataHandler(StagedGroup.class.getName()); Element rootElement = portletDataContext.getImportDataRootElement(); Element groupIdMappingsElement = rootElement.element("group-id-mappings"); for (Element groupIdMappingElement : groupIdMappingsElement.elements("group-id-mapping")) { stagedModelDataHandler.importMissingReference(portletDataContext, groupIdMappingElement); } Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class); Layout layout = _layoutLocalService.getLayout(plid); String companyGroupScopeId = AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX + companyGroupId; List<String> newValues = new ArrayList<>(oldValues.length); for (String oldValue : oldValues) { String newValue = StringUtil.replace(oldValue, "[$COMPANY_GROUP_SCOPE_ID$]", companyGroupScopeId); if (Validator.isNumber(oldValue) && groupIds.containsKey(Long.valueOf(oldValue))) { Group group = _groupLocalService.fetchGroup(groupIds.get(Long.valueOf(oldValue))); if (group != null) { newValue = AssetPublisherUtil.getScopeId(group, portletDataContext.getScopeGroupId()); } } if (Validator.isNumber(newValue)) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring group ", newValue, " because it cannot ", "be converted to scope")); } continue; } try { if (!assetPublisherWebUtil.isScopeIdSelectable(PermissionThreadLocal.getPermissionChecker(), newValue, companyGroupId, layout, false)) { continue; } newValues.add(newValue); } catch (NoSuchGroupException nsge) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring scope ", newValue, " because the ", "referenced group was not found"), nsge); } } catch (NoSuchLayoutException nsle) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring scope ", newValue, " because the ", "referenced layout was not found"), nsle); } } catch (PrincipalException pe) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Ignoring scope ", newValue, " because the ", "referenced parent group no longer allows sharing ", "content with child sites"), pe); } } } portletPreferences.setValues(key, newValues.toArray(new String[newValues.size()])); }
From source file:com.liferay.blogs.portlet.test.PortletLayoutFinderTest.java
License:Open Source License
@Before public void setUp() throws Exception { _portletIds = new String[] { PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.MANAGE), PortletProviderUtil.getPortletId(BlogsEntry.class.getName(), PortletProvider.Action.VIEW) }; _portletLayoutFinder = new BasePortletLayoutFinder() { @Override/*w w w . j av a 2s . c om*/ protected String[] getPortletIds() { return _portletIds; } }; User user = TestPropsValues.getUser(); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); _originalPermissionChecker = PermissionThreadLocal.getPermissionChecker(); PermissionThreadLocal.setPermissionChecker(permissionChecker); }
From source file:com.liferay.calendar.search.test.CalendarBookingIndexerTest.java
License:Open Source License
protected void setUpPermissionThreadLocal() throws Exception { _originalPermissionChecker = PermissionThreadLocal.getPermissionChecker(); PermissionThreadLocal.setPermissionChecker(new SimplePermissionChecker() { {/* w w w . ja v a 2 s. com*/ init(TestPropsValues.getUser()); } @Override public boolean hasOwnerPermission(long companyId, String name, String primKey, long ownerId, String actionId) { return true; } }); }
From source file:com.liferay.calendar.service.test.CalendarBookingServiceTest.java
License:Open Source License
@Before public void setUp() throws Exception { _omnidminUser = UserTestUtil.addOmniAdminUser(); _user1 = UserTestUtil.addUser();//from w ww. ja va 2s . c o m _user2 = UserTestUtil.addUser(); _permissionChecker = PermissionThreadLocal.getPermissionChecker(); }
From source file:com.liferay.calendar.util.test.CalendarUtilTest.java
License:Open Source License
@Before public void setUp() throws Exception { _group = GroupTestUtil.addGroup();//from w w w . j a v a 2s . c o m _user = UserTestUtil.addUser(); _permissionChecker = PermissionThreadLocal.getPermissionChecker(); PermissionThreadLocal.setPermissionChecker(new SimplePermissionChecker()); }
From source file:com.liferay.calendar.util.test.CalendarUtilTest.java
License:Open Source License
protected ThemeDisplay createThemeDisplay() throws PortalException { ThemeDisplay themeDisplay = new ThemeDisplay(); Company company = CompanyLocalServiceUtil.getCompany(_group.getCompanyId()); themeDisplay.setCompany(company);/*from w ww.j ava2s . c o m*/ themeDisplay.setLocale(LocaleUtil.getDefault()); themeDisplay.setScopeGroupId(_group.getGroupId()); themeDisplay.setPermissionChecker(PermissionThreadLocal.getPermissionChecker()); themeDisplay.setUser(_user); return themeDisplay; }
From source file:com.liferay.document.library.search.test.DLFileEntrySearchTest.java
License:Open Source License
protected void setUpPermissionThreadLocal() throws Exception { _originalPermissionChecker = PermissionThreadLocal.getPermissionChecker(); PermissionThreadLocal.setPermissionChecker(new SimplePermissionChecker() { {//w w w. j a va2 s . c o m init(TestPropsValues.getUser()); } @Override public boolean hasOwnerPermission(long companyId, String name, String primKey, long ownerId, String actionId) { return true; } }); }
From source file:com.liferay.document.library.service.test.DLFileEntryTypeFinderTest.java
License:Open Source License
@Test public void testFilterCountByKeywordsAsPowerUser() throws Exception { User user = UserTestUtil.addGroupUser(_group, RoleConstants.POWER_USER); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); PermissionChecker originalPermissionChecker = PermissionThreadLocal.getPermissionChecker(); PermissionThreadLocal.setPermissionChecker(permissionChecker); try {/*from ww w.j ava2 s. c o m*/ int initialFileEntryTypesCount = DLFileEntryTypeFinderUtil.filterCountByKeywords(_group.getCompanyId(), new long[] { _group.getGroupId() }, _DL_FILE_ENTRY_TYPE_NAME, true); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), _user.getUserId()); addFileEntryType(serviceContext); Assert.assertEquals(initialFileEntryTypesCount + 1, DLFileEntryTypeFinderUtil.filterCountByKeywords( _group.getCompanyId(), new long[] { _group.getGroupId() }, _DL_FILE_ENTRY_TYPE_NAME, true)); } finally { PermissionThreadLocal.setPermissionChecker(originalPermissionChecker); } }