jdk/src/share/classes/com/sun/jmx/snmp/IPAcl/Host.java
author darcy
Wed, 02 Apr 2014 21:38:45 -0700
changeset 23711 95fb268275e3
parent 5506 202f599c92aa
permissions -rw-r--r--
8039022: Fix serial lint warnings in sun.tools.java 8039027: Fix serial lint warnings in jconsole and jstat 8039038: Fix serial lint warnings in com.sun.jmx.snmp Reviewed-by: alanb, lancea, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23711
95fb268275e3 8039022: Fix serial lint warnings in sun.tools.java
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package com.sun.jmx.snmp.IPAcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
// java import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.acl.NotOwnerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import static com.sun.jmx.defaults.JmxProperties.SNMP_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The class defines an abstract representation of a host.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
23711
95fb268275e3 8039022: Fix serial lint warnings in sun.tools.java
darcy
parents: 5506
diff changeset
    47
@SuppressWarnings("serial") // JDK implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
abstract class Host extends SimpleNode implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public Host(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        super(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public Host(Parser p, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        super(p, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected abstract PrincipalImpl createAssociatedPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        throws UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected abstract String getHname();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // Create a principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        PrincipalImpl p=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            p = createAssociatedPrincipal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        } catch(UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        "buildAclEntries",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                        "Cannot create ACL entry; got exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            throw new IllegalArgumentException("Cannot create ACL entry for " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // Create an AclEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        AclEntryImpl entry= null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            entry = new AclEntryImpl(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            // Add permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            registerPermission(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            acl.addEntry(owner, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } catch(UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        "buildAclEntries",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                        "Cannot create ACL entry; got exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } catch(NotOwnerException a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        "buildAclEntries",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        "Cannot create ACL entry; got exception", a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private void registerPermission(AclEntryImpl entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        JDMHost host= (JDMHost) jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        JDMManagers manager= (JDMManagers) host.jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        JDMAclItem acl= (JDMAclItem) manager.jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        JDMAccess access= acl.getAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        access.putPermission(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        JDMCommunities comm= acl.getCommunities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        comm.buildCommunities(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void buildTrapEntries(Hashtable<InetAddress, Vector<String>> dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        JDMHostTrap host= (JDMHostTrap) jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        JDMTrapInterestedHost hosts= (JDMTrapInterestedHost) host.jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        JDMTrapItem trap = (JDMTrapItem) hosts.jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        JDMTrapCommunity community = trap.getCommunity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        String comm = community.getCommunity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        InetAddress add = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            add = java.net.InetAddress.getByName(getHname());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } catch(UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        "buildTrapEntries",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        "Cannot create TRAP entry; got exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Vector<String> list = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (dest.containsKey(add)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            list = dest.get(add);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            if (!list.contains(comm)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                list.addElement(comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            list = new Vector<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            list.addElement(comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            dest.put(add,list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void buildInformEntries(Hashtable<InetAddress, Vector<String>> dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        JDMHostInform host= (JDMHostInform) jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        JDMInformInterestedHost hosts= (JDMInformInterestedHost) host.jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        JDMInformItem inform = (JDMInformItem) hosts.jjtGetParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        JDMInformCommunity community = inform.getCommunity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        String comm = community.getCommunity();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        InetAddress add = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            add = java.net.InetAddress.getByName(getHname());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } catch(UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (SNMP_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                SNMP_LOGGER.logp(Level.FINEST, Host.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                        "buildTrapEntries",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                        "Cannot create INFORM entry; got exception", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Vector<String> list = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (dest.containsKey(add)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            list = dest.get(add);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (!list.contains(comm)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                list.addElement(comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            list = new Vector<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            list.addElement(comm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            dest.put(add,list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
}