KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > SecureTarget


1 /*_############################################################################
2   _##
3   _## SNMP4J - SecureTarget.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21 package org.snmp4j;
22
23 import org.snmp4j.smi.OctetString;
24 import java.io.*;
25 import org.snmp4j.security.SecurityLevel;
26 import org.snmp4j.security.SecurityModel;
27 import org.snmp4j.smi.Address;
28
29 /**
30  * The <code>SecureTarget</code> is an security model independent abstract class
31  * for all targets supporting secure SNMP communication.
32  *
33  * @author Jochen Katz & Frank Fock
34  * @version 1.0
35  */

36 public abstract class SecureTarget
37     extends AbstractTarget implements Serializable {
38
39   private static final long serialVersionUID = 3864834593299255038L;
40
41   private int securityLevel = SecurityLevel.NOAUTH_NOPRIV;
42   private int securityModel = SecurityModel.SECURITY_MODEL_ANY;
43   private OctetString securityName = new OctetString();
44
45   /**
46    * Default constructor.
47    */

48   protected SecureTarget() {
49   }
50
51   /**
52    * Creates a SNMPv3 secure target with an address and security name.
53    * @param address
54    * an <code>Address</code> instance denoting the transport address of the
55    * target.
56    * @param securityName
57    * a <code>OctetString</code> instance representing the security name
58    * of the USM user used to access the target.
59    */

60   protected SecureTarget(Address address, OctetString securityName) {
61     super(address);
62     setSecurityName(securityName);
63   }
64
65   /**
66    * Gets the security model associated with this target.
67    * @return
68    * an <code>int</code> value as defined in the {@link SecurityModel}
69    * interface or any third party subclass thereof.
70    */

71   public int getSecurityModel() {
72     return securityModel;
73   }
74
75   /**
76    * Gets the security name associated with this target. The security name
77    * is used by the security model to lookup further parameters like
78    * authentication and privacy protocol settings from the security model
79    * dependent internal storage.
80    * @return
81    * an <code>OctetString</code> instance (never <code>null</code>).
82    */

83   public final OctetString getSecurityName() {
84     return securityName;
85   }
86
87   /**
88    * Gets the security level associated with this target.
89    * @return
90    * one of
91    * <P><UL>
92    * <LI>{@link SecurityLevel#NOAUTH_NOPRIV}
93    * <LI>{@link SecurityLevel#AUTH_NOPRIV}
94    * <LI>{@link SecurityLevel#AUTH_PRIV}
95    * </UL></P>
96    */

97   public int getSecurityLevel() {
98     return securityLevel;
99   }
100
101   /**
102    * Sets the security level for this target. The supplied security level must
103    * be supported by the security model dependent information associated with
104    * the security name set for this target.
105    * @param securityLevel
106    * one of
107    * <P><UL>
108    * <LI>{@link SecurityLevel#NOAUTH_NOPRIV}
109    * <LI>{@link SecurityLevel#AUTH_NOPRIV}
110    * <LI>{@link SecurityLevel#AUTH_PRIV}
111    * </UL></P>
112    */

113   public void setSecurityLevel(int securityLevel) {
114     this.securityLevel = securityLevel;
115   }
116
117   /**
118    * Sets the security model for this target.
119    * @param securityModel
120    * an <code>int</code> value as defined in the {@link SecurityModel}
121    * interface or any third party subclass thereof.
122    */

123   public void setSecurityModel(int securityModel) {
124     this.securityModel = securityModel;
125   }
126
127   /**
128    * Sets the security name to be used with this target.
129    * @param securityName
130    * an <code>OctetString</code> instance (must not be <code>null</code>).
131    * @see #getSecurityName()
132    */

133   public final void setSecurityName(OctetString securityName) {
134     this.securityName = securityName;
135   }
136
137 }
138
Popular Tags