1 20 21 package org.snmp4j.security; 22 23 import org.snmp4j.User; 24 import org.snmp4j.smi.OctetString; 25 import org.snmp4j.smi.OID; 26 27 39 public class UsmUser implements User, Comparable , Cloneable { 40 41 private static final long serialVersionUID = -2258973598142206767L; 42 43 private OctetString securityName; 44 private OctetString authenticationPassphrase; 45 private OctetString privacyPassphrase; 46 private OID authenticationProtocol; 47 private OID privacyProtocol; 48 private OctetString localizationEngineID; 49 50 73 public UsmUser(OctetString securityName, 74 OID authenticationProtocol, 75 OctetString authenticationPassphrase, 76 OID privacyProtocol, 77 OctetString privacyPassphrase) { 78 if (securityName == null) { 79 throw new NullPointerException (); 80 } 81 if ((authenticationProtocol != null) && 82 ((authenticationPassphrase != null) && 83 (authenticationPassphrase.length() < 8))) { 84 throw new IllegalArgumentException ( 85 "USM passphrases must be at least 8 bytes long (RFC3414 §11.2)"); 86 } 87 if ((privacyProtocol != null) && 88 ((privacyPassphrase != null) && 89 (privacyPassphrase.length() < 8))) { 90 throw new IllegalArgumentException ( 91 "USM passphrases must be at least 8 bytes long (RFC3414 §11.2)"); 92 } 93 this.securityName = securityName; 94 this.authenticationProtocol = authenticationProtocol; 95 this.authenticationPassphrase = authenticationPassphrase; 96 this.privacyProtocol = privacyProtocol; 97 this.privacyPassphrase = privacyPassphrase; 98 } 99 100 128 public UsmUser(OctetString securityName, 129 OID authenticationProtocol, 130 OctetString authenticationPassphrase, 131 OID privacyProtocol, 132 OctetString privacyPassphrase, 133 OctetString localizationEngineID) { 134 this(securityName, authenticationProtocol, authenticationPassphrase, 135 privacyProtocol, privacyPassphrase); 136 this.localizationEngineID = localizationEngineID; 137 } 138 139 144 public OctetString getSecurityName() { 145 return (OctetString) securityName.clone(); 146 } 147 148 153 public OID getAuthenticationProtocol() { 154 if (authenticationProtocol == null) { 155 return null; 156 } 157 return (OID) authenticationProtocol.clone(); 158 } 159 160 165 public OID getPrivacyProtocol() { 166 if (privacyProtocol == null) { 167 return null; 168 } 169 return (OID) privacyProtocol.clone(); 170 } 171 172 177 public OctetString getAuthenticationPassphrase() { 178 if (authenticationPassphrase == null) { 179 return null; 180 } 181 return (OctetString) authenticationPassphrase.clone(); 182 } 183 184 189 public OctetString getPrivacyPassphrase() { 190 if (privacyPassphrase == null) { 191 return null; 192 } 193 return (OctetString) privacyPassphrase.clone(); 194 } 195 196 204 public OctetString getLocalizationEngineID() { 205 return localizationEngineID; 206 } 207 208 216 public boolean isLocalized() { 217 return (localizationEngineID != null); 218 } 219 220 225 public int getSecurityModel() { 226 return SecurityModel.SECURITY_MODEL_USM; 227 } 228 229 237 public int compareTo(Object o) { 238 UsmUser other = (UsmUser)o; 240 return securityName.compareTo(other.securityName); 241 } 242 243 public Object clone() { 244 UsmUser copy = new UsmUser(this.securityName, this.authenticationProtocol, 245 this.authenticationPassphrase, 246 this.privacyProtocol, this.privacyPassphrase, 247 this.localizationEngineID); 248 return copy; 249 } 250 251 public String toString() { 252 return "UsmUser[secName="+securityName+ 253 ",authProtocol="+authenticationProtocol+ 254 ",authPassphrase="+authenticationPassphrase+ 255 ",privProtocol="+privacyProtocol+ 256 ",privPassphrase="+privacyPassphrase+ 257 ",localizationEngineID="+getLocalizationEngineID()+"]"; 258 } 259 260 } 261 | Popular Tags |