public boolean hasPermission(Page page) { Identity identity = getIdentity(); if (PortalConfig.USER_TYPE.equals(page.getOwnerType())) { if (page.getOwnerId().equals(identity.getUserId())) { page.setModifiable(true); return true; } } if (superUser_.equals(identity.getUserId())) { page.setModifiable(true); return true; } if (hasEditPermission(page)) { page.setModifiable(true); return true; } page.setModifiable(false); String[] accessPerms = page.getAccessPermissions(); if (accessPerms != null) { for (String per : accessPerms) { if (hasPermission(identity, per)) { return true; } } } return false; }
/** * Minh Hoang TO - This method is equivalent to <code>hasEditPermission(Page)</code>. It allows us * to check edit permission with a UIPage, without converting UIPage into Page via * PortalDataMapper */ public boolean hasEditPermissionOnPage( String ownerType, String ownerId, String editPermExpression) { Identity identity = this.getIdentity(); if (PortalConfig.USER_TYPE.equals(ownerType)) { if (ownerId.equals(identity.getUserId())) { return true; } return false; } return hasPermission(identity, editPermExpression); }
public void invokeSetBindingBean(Object bean) throws Exception { String ownerType = getUIFormSelectBox("ownerType").getValue(); String ownerId = getUIStringInput("ownerId").getValue(); // As ownerId is now normalized, we have to maker sure that owenerId of 'group' type starts with // a '/' if (PortalConfig.GROUP_TYPE.equals(ownerType) && ownerId.charAt(0) != '/') { ownerId = "/" + ownerId; } Page page = (Page) bean; page.setPageId(getUIStringInput("pageId").getValue()); page.setOwnerType(ownerType); page.setOwnerId(ownerId); page.setName(getUIStringInput("name").getValue()); String title = getUIStringInput("title").getValue(); if (title == null || title.trim().length() < 1) title = page.getName(); page.setTitle(title); if (!page.isShowMaxWindow()) { page.setShowMaxWindow((Boolean) getUIFormCheckBoxInput("showMaxWindow").getValue()); } if (!PortalConfig.USER_TYPE.equals(page.getOwnerType())) { page.setAccessPermissions( uiPermissionSetting.getChild(UIListPermissionSelector.class).getValue()); page.setEditPermission(uiPermissionSetting.getChild(UIPermissionSelector.class).getValue()); } UserACL userACL = getApplicationComponent(UserACL.class); userACL.hasPermission(page); UIFormInputItemSelector uiTemplate = getChildById("Template"); if (uiTemplate != null) { SelectItemOption<?> itemOption = uiTemplate.getSelectedItemOption(); if (itemOption != null) { page.setFactoryId(itemOption.getIcon()); // page.setTemplate((String)itemOption.getValue()); if (page.getFactoryId().equals(Page.DESKTOP_PAGE)) page.setShowMaxWindow(true); } } UIPageTemplateOptions uiConfigOptions = getChild(UIPageTemplateOptions.class); if (uiConfigOptions == null) return; Page selectedPage = uiConfigOptions.createPageFromSelectedOption(page.getOwnerType(), page.getOwnerId()); if (selectedPage == null) return; page.setChildren(selectedPage.getChildren()); page.setFactoryId(selectedPage.getFactoryId()); if (Page.DESKTOP_PAGE.equals(page.getFactoryId())) page.setShowMaxWindow(true); }
public boolean hasEditPermission(Page page) { Identity identity = getIdentity(); if (PortalConfig.USER_TYPE.equals(page.getOwnerType())) { if (page.getOwnerId().equals(identity.getUserId())) { page.setModifiable(true); return true; } return false; } if (hasPermission(identity, page.getEditPermission())) { page.setModifiable(true); return true; } page.setModifiable(false); return false; }
public void execute(Event<UIPageForm> event) throws Exception { UIPageForm uiForm = event.getSource(); UIFormSelectBox uiSelectBox = uiForm.getUIFormSelectBox(OWNER_TYPE); String ownerType = uiSelectBox.getValue(); PortalRequestContext prContext = Util.getPortalRequestContext(); UIFormInputSet uiSettingSet = uiForm.getChildById("PageSetting"); uiForm.setSelectedTab("PageSetting"); List<UIComponent> list = uiSettingSet.getChildren(); if (PortalConfig.USER_TYPE.equals(ownerType)) { uiForm.removeChildById("PermissionSetting"); list.remove(2); list.add(2, uiForm.ownerIdInput); uiForm.ownerIdInput.setValue(prContext.getRemoteUser()); } else { if (uiForm.getChildById("PermissionSetting") == null) { uiForm.addUIComponentInput(uiForm.uiPermissionSetting); } if (PortalConfig.PORTAL_TYPE.equals(ownerType)) { list.remove(2); list.add(2, uiForm.ownerIdInput); uiForm.ownerIdInput.setValue(prContext.getPortalOwner()); uiForm .findFirstComponentOfType(UIListPermissionSelector.class) .setValue(Util.getUIPortal().getAccessPermissions()); uiForm .findFirstComponentOfType(UIPermissionSelector.class) .setValue(Util.getUIPortal().getEditPermission()); } else { list.remove(2); list.add(2, uiForm.groupIdSelectBox); String groupIdSelected = uiForm.groupIdSelectBox.getValue(); groupIdSelected = groupIdSelected.startsWith("/") ? groupIdSelected : "/" + groupIdSelected; String permission = "*:" + groupIdSelected; uiForm .findFirstComponentOfType(UIListPermissionSelector.class) .setValue(new String[] {permission}); UserACL userACL = uiForm.getApplicationComponent(UserACL.class); permission = userACL.getMakableMT() + ":" + groupIdSelected; uiForm.findFirstComponentOfType(UIPermissionSelector.class).setValue(permission); } } prContext.addUIComponentToUpdateByAjax(uiForm.getParent()); }