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

📄 permission.java

📁 java版源代码,里面包含很多源代码,大家可以看看.
💻 JAVA
字号:
package com.trulytech.mantis.system;

import java.util.HashMap;
import com.trulytech.mantis.system.SQLParser;

/**
 * <p>Title: Mantis</p>
 * <p>Description: 权限控制</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author Wang Xian
 * @version 1.2
 */

public class Permission {

  static final public int ALLOW = 2; //权限允许
  static final public int DENY = 1; //权限禁止
  static final public int ERROR = 0; //权限超时

  //权限列表(由2个HashMap构成 ServletName(1)——Action(*))
  private HashMap Permission_list = null;
  /**
   * 初始化
   */
  public Permission() {
    Permission_list = new HashMap();
  }

  /**
   * 判断是否有权限
   * @param UserID String 用户ID
   * @param ServletName String Servlet类名
   * @param Action String Action动作
   * @param Parser SQLParser SQL解析器
   * @return int 是否具有权限 ALLOW-有,DENY-无,ERROR-超时
   * @throws Exception
   */
  protected int HasPermission(String UserID, String ServletName, String Action,
                              SQLParser Parser) throws Exception {
    HashMap map = (HashMap) Permission_list.get(ServletName);
    if (map == null)return DENY;
    else {
      String Name = (String) map.get(Action);
      if (Name == null)return DENY;
      else {
        if (com.trulytech.mantis.system.Properties.isAduit) {
          com.trulytech.mantis.system.logWriter.Debug("写操作员日志");
          Parser.SQLExecute(
              "insert into operatorlog(operid,name,timestamp) values ('" +
              UserID + "','" + Name + "',sysdate)");

        }

        return ALLOW;
      }
    }

  }


  /**
   * 设置权限
   * @param ServletName Servlet名称
   * @param Action Action动作
   * @param Name Action名称
   */
  public void setPermission(String ServletName, String Action, String Name) {
    HashMap map = (HashMap) Permission_list.get(ServletName);
    if (map == null) {
      HashMap rec = new HashMap();
      rec.put(Action, Name);
      Permission_list.put(ServletName, rec);
    }
    else {
      map.put(Action, Name);
      Permission_list.put(ServletName, map);
    }
  }

  /**
   * 用户菜单判断权限
   * @param ServletName String Servlet名
   * @param Action String Action名
   * @return boolean
   * @throws Exception
   */
  public boolean isPermission(String ServletName,
                              String Action) throws
      Exception {
    HashMap map = (HashMap) Permission_list.get(ServletName);
    if (map == null)return false;
    else {
      String Name = (String) map.get(Action);
      if (Name == null)return false;
      else {
        return true;
      }
    }

  }
}

⌨️ 快捷键说明

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