⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 permprep.bsh

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 BSH
字号:
/* * $Id: permprep.bsh 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2003-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * @author     <a href="mailto:byersa@automationgroups.com">Al Byers</a> * @author     David E. Jones * @version    $Rev: 5462 $ * @since      3.0 * Does either a "simple" (does entity perm check) or complex * (uses EntityPurpose/Operation/etc. tables) to check by roles. */import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;import java.util.TreeSet;import org.ofbiz.base.util.*;import org.ofbiz.entity.*;import org.ofbiz.security.*;import org.ofbiz.service.*;import org.ofbiz.entity.model.*;import org.ofbiz.widget.html.*;import org.ofbiz.widget.form.*;import org.ofbiz.content.content.PermissionRecorder;import org.ofbiz.content.ContentManagementWorker;import javax.servlet.*;import javax.servlet.http.*;paramMap = UtilHttp.getParameterMap(request);//Debug.logInfo("in permprep, userLogin(0):" + userLogin, null);// Get permission from pagedef config filepermission = page.get("permission");permissionType = page.get("permissionType");if (permissionType == null) permissionType = "simple";entityName = page.get("entityName");entityOperation = page.get("entityOperation");targetOperation = page.get("targetOperation");//Debug.logInfo("in permprep, targetOperation(0):" + targetOperation, null);mode = paramMap.get("mode");//Debug.logInfo("in permprep, contentId(0):" + request.getAttribute("contentId"),"");currentValue = (GenericValue)request.getAttribute("currentValue");//Debug.logInfo("in permprep, paramMap(1):" + paramMap, null);//Debug.logInfo("in permprep, currentValue(1):" + currentValue, null);if (UtilValidate.isNotEmpty(mode) && mode.equals("add")) {    entityOperation = page.get("addEntityOperation");    if (UtilValidate.isEmpty(entityOperation)) {        entityOperation = page.get("entityOperation");        if (UtilValidate.isEmpty(entityOperation)) {            entityOperation = "_CREATE";        }    }    targetOperation = page.get("addTargetOperation");    //org.ofbiz.base.util.Debug.logInfo("in permprep, targetOperation:" + targetOperation, null);    if (UtilValidate.isEmpty(targetOperation)) {        targetOperation = page.get("targetOperation");        if (UtilValidate.isEmpty(targetOperation)) {            targetOperation = "CONTENT_CREATE";        }    }} else {    if (UtilValidate.isEmpty(entityOperation)) {        entityOperation = "_UPDATE";    }    if (UtilValidate.isEmpty(targetOperation)) {        targetOperation = "CONTENT_UPDATE";    }}if (permissionType.equals("complex")) {    mapIn = new HashMap();    mapIn.put("userLogin", userLogin);    List targetOperationList = StringUtil.split(targetOperation, "|");    mapIn.put("targetOperationList", targetOperationList );    String thisContentId = null;        //Debug.logInfo("in permprep, userLogin(1):" + userLogin, null);    //if (userLogin != null) {        //Debug.logInfo("in permprep, userLoginId(1):" + userLogin.get("userLoginId"), null);    //}    if (currentValue == null || (entityName != null && !entityName.equals("Content"))) {        permissionIdName = page.get("permissionIdName");        //org.ofbiz.base.util.Debug.logInfo("in permprep, permissionIdName(1):" + permissionIdName, null);        if (UtilValidate.isNotEmpty(permissionIdName)) {            thisContentId = ContentManagementWorker.getFromSomewhere(permissionIdName, paramMap, request, context);        } else if (UtilValidate.isEmpty(thisContentId)) {            thisContentId = ContentManagementWorker.getFromSomewhere("subContentId", paramMap, request, context);        } else if (UtilValidate.isEmpty(thisContentId)) {            thisContentId = ContentManagementWorker.getFromSomewhere("contentIdTo", paramMap, request, context);        } else if (UtilValidate.isEmpty(thisContentId)) {            thisContentId = ContentManagementWorker.getFromSomewhere("contentId", paramMap, request, context);        }        //org.ofbiz.base.util.Debug.logInfo("in permprep, thisContentId(2):" + thisContentId, null);    } else {        thisContentId = currentValue.get("contentId");    }    //org.ofbiz.base.util.Debug.logInfo("in permprep, thisContentId(3):" + thisContentId, null);    if (currentValue == null || (entityName != null && !entityName.equals("Content"))) {        if (UtilValidate.isNotEmpty(thisContentId)) {            currentValue = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", thisContentId));        }    }    if (UtilValidate.isNotEmpty(mode) && mode.equals("add")) {        addEntityOperation = page.get("addEntityOperation");        if (UtilValidate.isNotEmpty(addEntityOperation)) {            entityOperation = addEntityOperation;        }    } else {        editEntityOperation = page.get("editEntityOperation");        if (UtilValidate.isNotEmpty(editEntityOperation)) {            entityOperation = editEntityOperation;        }    }    //org.ofbiz.base.util.Debug.logInfo("in permprep, currentValue(2):" + currentValue, null);    if (currentValue != null && currentValue.getEntityName().equals("Content")) {        mapIn.put("currentContent", currentValue);    }    mapIn.put("entityOperation", entityOperation);    contentPurposeTypeId = page.get("contentPurposeTypeId");    if (UtilValidate.isNotEmpty(contentPurposeTypeId)) {        mapIn.put("contentPurposeList", StringUtil.split(contentPurposeTypeId, "|"));    }    //org.ofbiz.base.util.Debug.logInfo("in permprep, mapIn:" + mapIn, null);    result = dispatcher.runSync("checkContentPermission", mapIn);    permissionStatus = result.get("permissionStatus");    //org.ofbiz.base.util.Debug.logInfo("in permprep, permissionStatus:" + permissionStatus, null);    if (permissionStatus != null && permissionStatus.equals("granted")) {        context.put("hasPermission", Boolean.TRUE);        request.setAttribute("hasPermission", Boolean.TRUE);        request.setAttribute("permissionStatus", "granted");    } else {        context.put("hasPermission", Boolean.FALSE);        request.setAttribute("hasPermission", Boolean.FALSE);        request.setAttribute("permissionStatus", "");        String errorMessage = "Permission to display:" + page.getPageName() + " is denied.";        PermissionRecorder recorder = (PermissionRecorder)result.get("permissionRecorder");        //Debug.logInfo("recorder(0):" + recorder, "");        if (recorder != null) {            String permissionMessage = recorder.toHtml();            //Debug.logInfo("permissionMessage(0):" + permissionMessage, "");            errorMessage += " \n " + permissionMessage;        }        request.setAttribute("errorMsgReq", errorMessage);    }    //Debug.logInfo("in permprep, contentId(1):" + request.getAttribute("contentId"),"");} else {    //org.ofbiz.base.util.Debug.logInfo("permission:" + permission , null);    //org.ofbiz.base.util.Debug.logInfo("entityOperation:" + entityOperation , null);    if (security.hasEntityPermission(permission, entityOperation, session)) {        //org.ofbiz.base.util.Debug.logInfo("hasEntityPermission is true:" , null);    	context.put("hasPermission", Boolean.TRUE);        request.setAttribute("hasPermission", Boolean.TRUE);        request.setAttribute("permissionStatus", "granted");    } else {        //org.ofbiz.base.util.Debug.logInfo("hasEntityPermission is false:" , null);    	context.put("hasPermission", Boolean.FALSE);        request.setAttribute("hasPermission", Boolean.FALSE);        request.setAttribute("permissionStatus", "");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -