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

📄 permissionmodule.java

📁 CRMS客户关系管理系统(JAVA版),这是一个客户关系管理系统。
💻 JAVA
字号:
    /* CRMS, customer relationship management system    Copyright (C) 2003  Service To Youth Council    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    For further information contact the SYC ICT department on GPL@syc.net.au    98 Kermode Street    North Adelaide    South Australia    SA 5006     +61 (0)8 8367 0755    *//* * PermissionModule.java * * Created on 15 May 2003, 12:17 */package crms.module;import crms.dao.*;import crms.vo.*;import crms.util.*;import java.util.*;import org.apache.log4j.Logger;import com.Ostermiller.util.Base64;/** * * @author  dmurphy */public class PermissionModule {        Logger logger = Logger.getLogger(PermissionModule.class);        public static String PREFIX = "permissions.";        public static String PERM_ALL_ENTITY = "permissions.entity.all";    public static String PERM_SAVE_ENTITY = "permissions.entity.save";    public static String PERM_AUTHENTICATE = "permissions.authenticate";        public static String PARAM_ENTITY_ID = "entityid";    public static String PARAM_ENTITY_TYPE = "type";        public static String PARAM_KEY = "key";        PermissionDAO dao = DAOFactory.getInstance().getPermissionDAO();    LDAPDAO ldapDAO = LDAPDAOFactory.getInstance().getLDAPDAO();        /** Creates a new instance of PermissionModule */    public PermissionModule() {    }        public ServerResponse processCommand(ServerCommand command) throws Exception {                String user = command.getUser();        ServerResponse response = new ServerResponse();                if (command.getKey().equals(PERM_ALL_ENTITY)) {                        logger.debug("PARAM_ENTITY_ID=" + command.getParameterValue(PARAM_ENTITY_ID));            logger.debug("PARAM_ENTITY_ID=" + command.getParameterValue(PARAM_ENTITY_TYPE));                        int id = Integer.parseInt((String)command.getParameterValue(PARAM_ENTITY_ID));            String typeCode = (String) command.getParameterValue(PARAM_ENTITY_TYPE);            EntityType type = (EntityType) AbstractCode.decode(typeCode, EntityType.class);                        List userResults = getPermissionsFor(id, type, null);            setReferences(userResults);            response.addPart("permissions", userResults);           /*             List groupResults = getPermissionsFor(id, type, PermissionType.PERMISSION_GROUP);            setReferences(groupResults);                        response.addPart("permissions.group", groupResults);                        List allList = getPermissionsFor(id, type, PermissionType.PERMISSION_ALL);                        if (allList != null && allList.size() > 0) {                Permission all = (Permission) allList.get(0);                response.addPart("permissions.all", all);            } else {                response.addPart("permissions.all", null);               }  */                      // Add the list of available groups to the response, to enable            // adding new group permissions....                        List groupList = getGroupList();            logger.debug("Adding " + groupList.size() + " elements to group.list");            response.addPart("group.list", getGroupList());                        return response;        }        else if (command.getKey().equals(PERM_SAVE_ENTITY)) {                        logger.debug("PARAM_ENTITY_ID=" + command.getParameterValue(PARAM_ENTITY_ID));            logger.debug("PARAM_ENTITY_TYPE=" + command.getParameterValue(PARAM_ENTITY_TYPE));                        int id = Integer.parseInt((String)command.getParameterValue(PARAM_ENTITY_ID));            String typeCode = (String) command.getParameterValue(PARAM_ENTITY_TYPE);            EntityType type = (EntityType) AbstractCode.decode(typeCode, EntityType.class);                                    List userPerms = (List) command.getParameterValue("permissions");            //List groupPerms = (List) command.getParameterValue("permissions.group");            setReferences(userPerms);            //setReferences(groupPerms);                        //Permission allPerm = (Permission) command.getParameterValue("permissions.all");            List wholeList = new ArrayList();            wholeList.addAll(userPerms);            //wholeList.addAll(groupPerms);            //wholeList.add(allPerm);            updatePermissions(id, type, wholeList);                        return ServerResponse.ACKNOWLEDGE_OKAY;        } else if (command.getKey().equals(PERM_AUTHENTICATE)) {            logger.debug("Authenticating user: " + user);            String key = (String) command.getParameterValue(PARAM_KEY);            boolean authenticated = ldapDAO.autenticateUser(user, Base64.decode(key));            if (authenticated) {                logger.debug("User authenticated.");                return ServerResponse.ACKNOWLEDGE_OKAY;            } else {                logger.debug("User authentication failed!");                return ServerResponse.PERMISSION_DENIED;               }        }                return ServerResponse.ACKNOWLEDGE_OKAY;    }                public void setReferences(List permissionList) {                for (int i=0; i < permissionList.size(); i++) {            Permission p = (Permission) permissionList.get(i);                permissionList.remove(p);            //if (p.getPermissionType().equals(PermissionType.PERMISSION_USER)) {			if (p.getID() != null && p.getID().compareTo("") != 0 && p.getID().compareTo("null") != 0) {                StaffMember sm = ldapDAO.getUser(p.getID());                p.setReference(sm);			}            /*} else if (p.getPermissionType().equals(PermissionType.PERMISSION_GROUP)) {                Group gp = ldapDAO.getGroup(p.getID());                p.setReference(gp);   */            //}            permissionList.add(i,p);        }    }        /**     *  Discovers the "best" permission this user can have for the given     *  entity. Note, if user permissions are added along with group or all     *  permissions, the less general will prevail.     *       *  Note also - no permission (ie, none of the three types) implies no     *  access - a "No Access" permission is created and returned in this     *  case.     */        public Permission getUserPermissionFor(int entityID, EntityType type, String user ) {                ArrayList groups = (ArrayList) ldapDAO.getGroupMembership(user);        ArrayList permissions = (ArrayList) dao.getPermissions(entityID, type, user,  groups);                if (permissions != null && permissions.size() > 0) {            logger.debug("getUserPermissionFor: returning existing permission.");            return (Permission) permissions.get(0);            } else {            Permission p = new Permission();            p.setEntityID(entityID);            p.setEntityType(type);            p.setID(user);            logger.debug("getUserPermissionFor: Building and returning no-access permission.");            return p;        }    }        public List getPermissionsFor(int entityID, EntityType type, PermissionType permType) {                List permissions = (ArrayList) dao.getPermissionsForEntity(entityID, type, permType);        return permissions;    }        public void setPermission(Permission p) {        dao.setPermission(p);       }        public void updatePermissions(int entityID, EntityType type, List permList) {                try {            dao.updatePermissions(entityID, type, permList);           }        catch (java.sql.SQLException ex) {            logger.debug("Exception updating permissions.",ex);            throw new RuntimeException(ex);           }    }        public List getGroupList() {        return ldapDAO.getGroups();    }}

⌨️ 快捷键说明

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