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

📄 snmpacl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      /**     * Checks whether or not the specified host and community have <CODE>READ</CODE> access.     *     * @param address The host address to check.     * @param community The community associated with the host.     *     * @return <CODE>true</CODE> if the pair (host, community) has read permission, <CODE>false</CODE> otherwise.     */    public boolean checkReadPermission(InetAddress address, String community) {        if (alwaysAuthorized) return ( true );        PrincipalImpl p = new PrincipalImpl(address);        return acl.checkPermission(p, community, READ);    }      /**     * Checks whether or not a community string is defined.     *     * @param community The community to check.     *     * @return <CODE>true</CODE> if the community is known, <CODE>false</CODE> otherwise.     */    public boolean checkCommunity(String community) {        return acl.checkCommunity(community);    }      /**     * Checks whether or not the specified host has <CODE>WRITE</CODE> access.     *     * @param address The host address to check.     *     * @return <CODE>true</CODE> if the host has write permission, <CODE>false</CODE> otherwise.     */    public boolean checkWritePermission(InetAddress address) {        if (alwaysAuthorized) return ( true );        PrincipalImpl p = new PrincipalImpl(address);        return acl.checkPermission(p, WRITE);    }     /**     * Checks whether or not the specified host and community have <CODE>WRITE</CODE> access.     *     * @param address The host address to check.     * @param community The community associated with the host.     *     * @return <CODE>true</CODE> if the pair (host, community) has write permission, <CODE>false</CODE> otherwise.     */    public boolean checkWritePermission(InetAddress address, String community) {        if (alwaysAuthorized) return ( true );        PrincipalImpl p = new PrincipalImpl(address);        return acl.checkPermission(p, community, WRITE);    }       /**     * Returns an enumeration of trap destinations.     *     * @return An enumeration of the trap destinations (enumeration of <CODE>InetAddress</CODE>).     */    public Enumeration getTrapDestinations() {        return trapDestList.keys();    }      /**     * Returns an enumeration of trap communities for a given host.     *     * @param i The address of the host.     *     * @return An enumeration of trap communities for a given host (enumeration of <CODE>String</CODE>).     */    public Enumeration getTrapCommunities(InetAddress i) {        Vector list = null;        if ((list = (Vector)trapDestList.get(i)) != null ) {            if (isTraceOn()) {                trace("getTrapCommunities", "["+i.toString()+"] is in list");            }            return list.elements();        } else {            list = new Vector();            if (isTraceOn()) {                trace("getTrapCommunities", "["+i.toString()+"] is not in list");            }            return list.elements();        }     }      /**     * Returns an enumeration of inform destinations.     *     * @return An enumeration of the inform destinations (enumeration of <CODE>InetAddress</CODE>).     */    public Enumeration getInformDestinations() {        return informDestList.keys();    }      /**     * Returns an enumeration of inform communities for a given host.     *     * @param i The address of the host.     *     * @return An enumeration of inform communities for a given host (enumeration of <CODE>String</CODE>).     */    public Enumeration getInformCommunities(InetAddress i) {        Vector list = null;        if ((list = (Vector)informDestList.get(i)) != null ) {            if (isTraceOn()) {                trace("getInformCommunities", "["+i.toString()+"] is in list");            }            return list.elements();        } else {            list = new Vector();            if (isTraceOn()) {                trace("getInformCommunities", "["+i.toString()+"] is not in list");            }            return list.elements();        }     }      /**     * Converts the input configuration file into ACL.     */    private void readAuthorizedListFile() {        alwaysAuthorized = false;        if (authorizedListFile == null) {            if (isTraceOn()) {                trace("readAuthorizedListFile", "alwaysAuthorized set to true");            }            alwaysAuthorized = true ;        } else {            // Read the file content            Parser parser = null;              try {                parser= new Parser(new FileInputStream(getAuthorizedListFile()));            } catch (FileNotFoundException e) {                if (isDebugOn()) {                    debug("readAuthorizedListFile", "The specified file was not found, authorize everybody");                }                alwaysAuthorized = true ;                return;            }                      try {                JDMSecurityDefs n = parser.SecurityDefs();                n.buildAclEntries(owner, acl);                n.buildTrapEntries(trapDestList);                n.buildInformEntries(informDestList);            } catch (ParseException e) {                if (isDebugOn()) {                    debug("readAuthorizedListFile", "Parsing exception " + e);                }		throw new IllegalArgumentException(e.getMessage());            } catch (Error err) {                if (isDebugOn()) {                    debug("readAuthorizedListFile", "Error exception");                }		throw new IllegalArgumentException(err.getMessage());            }                      for(Enumeration e = acl.entries(); e.hasMoreElements();) {                AclEntryImpl aa = (AclEntryImpl) e.nextElement();                if (isTraceOn()) {                    trace("readAuthorizedListFile", "===> " + aa.getPrincipal().toString());                }                for (Enumeration eee = aa.permissions();eee.hasMoreElements();) {                    java.security.acl.Permission perm = (java.security.acl.Permission)eee.nextElement();                    if (isTraceOn()) {                        trace("readAuthorizedListFile", "perm = " + perm);                    }                }            }        }    }      /**     * Set the default full path for "snmp.acl" input file.     * Do not complain if the file does not exists.     */    private void setDefaultFileName() {	try {	    setAuthorizedListFile(getDefaultAclFileName());	} catch (IllegalArgumentException x) {	    // OK...	}    }          // TRACES & DEBUG    //---------------        boolean isTraceOn() {        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP);    }    void trace(String clz, String func, String info) {        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info);    }    void trace(String func, String info) {        trace(dbgTag, func, info);    }        boolean isDebugOn() {        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP);    }    void debug(String clz, String func, String info) {        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info);    }    void debug(String func, String info) {        debug(dbgTag, func, info);    }        String dbgTag = "SnmpAcl";        // PRIVATE VARIABLES    //------------------        /**     * Represents the Access Control List.     */    private AclImpl acl = null;    /**     * Flag indicating whether the access is always authorized.     * <BR>This is the case if there is no flat file defined.     */    private boolean alwaysAuthorized = false;    /**     * Represents the Access Control List flat file.     */    private String authorizedListFile = null;    /**     * Contains the hosts list for trap destination.     */    private Hashtable trapDestList = null;    /**     * Contains the hosts list for inform destination.     */    private Hashtable informDestList = null;        private PrincipalImpl owner = null;}

⌨️ 快捷键说明

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