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

📄 snmpacl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)file      SnmpAcl.java * @(#)author    Sun Microsystems, Inc. * @(#)version   4.34 * @(#)date      08/07/21 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */package com.sun.jmx.snmp.IPAcl;// java import//import java.io.Serializable;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.Hashtable;import java.util.Vector;import java.util.Enumeration;import java.util.HashSet;import java.security.acl.AclEntry; import java.security.acl.NotOwnerException; // SNMP Runtime import//import com.sun.jmx.snmp.InetAddressAcl;import com.sun.jmx.trace.Trace;/** * Defines an implementation of the {@link com.sun.jmx.snmp.InetAddressAcl InetAddressAcl} interface. * <p> * In this implementation the ACL information is stored on a flat file and  * its default location is "$JRE/lib/snmp.acl" - See  * {@link #getDefaultAclFileName()} * <p> * <OL>  * * <p><b>This API is a Sun Microsystems internal API  and is subject  * to change without notice.</b></p> * @version     4.34     04/07/06 * @author      Sun Microsystems, Inc */public class SnmpAcl implements InetAddressAcl, Serializable {      static final PermissionImpl READ  = new PermissionImpl("READ");     static final PermissionImpl WRITE = new PermissionImpl("WRITE");      /**     * Constructs the Java Dynamic Management(TM) Access Control List     * based on IP addresses. The ACL will take the given owner name.     * The current IP address will be the owner of the ACL.     *     * @param Owner The name of the ACL Owner.     *     * @exception UnknownHostException If the local host is unknown.     * @exception IllegalArgumentException If the ACL file doesn't exist.     */    public SnmpAcl(String Owner) 	throws UnknownHostException, IllegalArgumentException {   	this(Owner,null);    }      /**     * Constructs the Java Dynamic Management(TM) Access Control List     * based on IP addresses. The ACL will take the given owner name.     * The current IP address will be the owner of the ACL.     *     * @param Owner The name of the ACL Owner.     * @param aclFileName The name of the ACL File.     *     * @exception UnknownHostException If the local host is unknown.     * @exception IllegalArgumentException If the ACL file doesn't exist.     */    public SnmpAcl(String Owner, String aclFileName) 	throws UnknownHostException, IllegalArgumentException {           trapDestList= new Hashtable();        informDestList= new Hashtable();                // PrincipalImpl() take the current host as entry        owner = new PrincipalImpl();        try {            acl = new AclImpl(owner,Owner);            AclEntry ownEntry = new AclEntryImpl(owner);            ownEntry.addPermission(READ);            ownEntry.addPermission(WRITE);            acl.addEntry(owner,ownEntry);        } catch (NotOwnerException ex) {            if (isDebugOn()) {                debug("constructor", 		      "Should never get NotOwnerException as the owner"+		      " is built in this constructor");            }        }        if (aclFileName == null) setDefaultFileName();	else setAuthorizedListFile(aclFileName);        readAuthorizedListFile();    }      /**     * Returns an enumeration of the entries in this ACL. Each element in the     * enumeration is of type <CODE>java.security.acl.AclEntry</CODE>.     *     * @return An enumeration of the entries in this ACL.     */    public Enumeration entries() {        return acl.entries();    }      /**     * Returns ann enumeration of community strings. Community strings are returned as String.     * @return The enumeration of community strings.     */    public Enumeration communities() {	HashSet set = new HashSet();	Vector res = new Vector();	for (Enumeration e = acl.entries() ; e.hasMoreElements() ;) {	    AclEntryImpl entry = (AclEntryImpl) e.nextElement();	    for (Enumeration cs = entry.communities(); 		 cs.hasMoreElements() ;) {		set.add((String) cs.nextElement());	    }	}	Object[] objs = set.toArray();	for(int i = 0; i < objs.length; i++)	    res.addElement(objs[i]);	return res.elements();    }    /**     * Returns the name of the ACL.     *     * @return The name of the ACL.     */    public String getName() {        return acl.getName();    }      /**     * Returns the read permission instance used.     *     * @return The read permission instance.     */    static public PermissionImpl getREAD() {        return READ;    }      /**     * Returns the write permission instance used.     *     * @return  The write permission instance.     */    static public PermissionImpl getWRITE() {        return WRITE;    }      /**     * Get the default name for the ACL file.     * In this implementation this is "$JRE/lib/snmp.acl"     * @return The default name for the ACL file.     **/    public static String getDefaultAclFileName() {	final String fileSeparator = 	    System.getProperty("file.separator");	final StringBuffer defaultAclName = 	    new StringBuffer(System.getProperty("java.home")).	    append(fileSeparator).append("lib").append(fileSeparator).	    append("snmp.acl");	return defaultAclName.toString();    }    /**     * Sets the full path of the file containing the ACL information.     *     * @param filename The full path of the file containing the ACL information.     * @throws IllegalArgumentException If the passed ACL file doesn't exist.     */    public void setAuthorizedListFile(String filename) 	throws IllegalArgumentException {	File file = new File(filename);	if (!file.isFile() ) {	    if (isDebugOn()) {		debug("setAuthorizedListFile", 		      "ACL file not found: " + filename);	    }	    throw new 		IllegalArgumentException("The specified file ["+file+"] "+					 "doesn't exist or is not a file, "+					 "no configuration loaded");	}        if (isTraceOn()) {            trace("setAuthorizedListFile", "Default file set to " + filename);        }        authorizedListFile = filename;    }      /**     * Resets this ACL to the values contained in the configuration file.     *     * @exception NotOwnerException If the principal attempting the reset is not an owner of this ACL.     * @exception UnknownHostException If IP addresses for hosts contained in the ACL file couldn't be found.     */    public void rereadTheFile() throws NotOwnerException, UnknownHostException {        alwaysAuthorized = false;        acl.removeAll(owner);        trapDestList.clear();        informDestList.clear();        AclEntry ownEntry = new AclEntryImpl(owner);        ownEntry.addPermission(READ);        ownEntry.addPermission(WRITE);          acl.addEntry(owner,ownEntry);        readAuthorizedListFile();    }      /**     * Returns the full path of the file used to get ACL information.     *     * @return The full path of the file used to get ACL information.     */    public String getAuthorizedListFile() {        return authorizedListFile;    }      /**     * Checks whether or not the specified host has <CODE>READ</CODE> access.     *     * @param address The host address to check.     *     * @return <CODE>true</CODE> if the host has read permission, <CODE>false</CODE> otherwise.     */    public boolean checkReadPermission(InetAddress address) {        if (alwaysAuthorized) return ( true );        PrincipalImpl p = new PrincipalImpl(address);        return acl.checkPermission(p, READ);    }

⌨️ 快捷键说明

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