KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > UserTarget


1 /*_############################################################################
2   _##
3   _## SNMP4J - UserTarget.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
22
23
24
25 package org.snmp4j;
26
27 import org.snmp4j.smi.OctetString;
28 import org.snmp4j.security.SecurityModel;
29 // for JavaDoc
30
import org.snmp4j.security.SecurityLevel;
31 import org.snmp4j.smi.Address;
32
33 /**
34  * User based target for SNMPv3 or later.
35  *
36  * @author Frank Fock
37  * @version 1.0
38  */

39 public class UserTarget extends SecureTarget {
40
41   private static final long serialVersionUID = -1426511355567423746L;
42
43   private OctetString authoritativeEngineID = new OctetString();
44
45   /**
46    * Creates a target for a user based security model target.
47    */

48   public UserTarget() {
49   }
50
51   /**
52    * Creates a SNMPv3 USM target with security level noAuthNoPriv, one second
53    * time-out without retries.
54    * @param address
55    * the transport <code>Address</code> of the target.
56    * @param securityName
57    * the USM security name to be used to access the target.
58    * @param authoritativeEngineID
59    * the authoritative engine ID as a possibly zero length byte
60    * array which must not be <code>null</code>.
61    */

62   public UserTarget(Address address, OctetString securityName,
63                     byte[] authoritativeEngineID) {
64     super(address, securityName);
65     setAuthoritativeEngineID(authoritativeEngineID);
66   }
67
68   /**
69    * Creates a SNMPv3 USM target with the supplied security level, one second
70    * time-out without retries.
71    * @param address
72    * the transport <code>Address</code> of the target.
73    * @param securityName
74    * the USM security name to be used to access the target.
75    * @param authoritativeEngineID
76    * the authoritative engine ID as a possibly zero length byte
77    * array which must not be <code>null</code>.
78    * @param securityLevel
79    * the {@link SecurityLevel} to use.
80    * @since 1.1
81    */

82   public UserTarget(Address address, OctetString securityName,
83                     byte[] authoritativeEngineID, int securityLevel) {
84     super(address, securityName);
85     setAuthoritativeEngineID(authoritativeEngineID);
86     setSecurityLevel(securityLevel);
87   }
88
89   /**
90    * Sets the authoritative engine ID of this target.
91    * @param authoritativeEngineID
92    * a possibly zero length byte array (must not be <code>null</code>).
93    */

94   public void setAuthoritativeEngineID(byte[] authoritativeEngineID) {
95     this.authoritativeEngineID.setValue(authoritativeEngineID);
96   }
97
98   /**
99    * Gets the authoritative engine ID of this target.
100    * @return
101    * a possibly zero length byte array.
102    */

103   public byte[] getAuthoritativeEngineID() {
104     return authoritativeEngineID.getValue();
105   }
106
107   /**
108    * Gets the security model for the user target.
109    *
110    * @return
111    * {@link SecurityModel#SECURITY_MODEL_USM}
112    */

113   public int getSecurityModel() {
114     return SecurityModel.SECURITY_MODEL_USM;
115   }
116
117   /**
118    * Sets the security model for the user target.
119    *
120    * @param securityModel
121    * {@link SecurityModel#SECURITY_MODEL_USM}, for any other value a
122    * <code>IllegalArgumentException</code> is thrown.
123    */

124   public void setSecurityModel(int securityModel) {
125     if (securityModel != SecurityModel.SECURITY_MODEL_USM) {
126       throw new IllegalArgumentException JavaDoc("The UserTarget target can only be " +
127                                          "used with the User Based Security " +
128                                          "Model (USM)");
129     }
130   }
131
132 }
133
134
Popular Tags