1 20 21 package org.snmp4j.security; 22 23 import java.io.Serializable ; 24 import org.snmp4j.smi.OctetString; 25 import org.snmp4j.smi.OID; 26 27 34 public class UsmUserEntry implements Serializable , Comparable { 35 36 private static final long serialVersionUID = -3021438367015187166L; 37 38 private OctetString engineID; 39 private OctetString userName; 40 private UsmUser usmUser; 41 private byte[] authenticationKey; 42 private byte[] privacyKey; 43 44 47 public UsmUserEntry() { 48 engineID = new OctetString(); 49 userName = new OctetString(); 50 usmUser = new UsmUser(new OctetString(), null, null, null, null); 51 } 52 53 61 public UsmUserEntry(OctetString userName, UsmUser user) { 62 this.userName = userName; 63 this.usmUser = user; 64 if (user.isLocalized()) { 65 if ((user.getAuthenticationProtocol() != null) && 66 (user.getAuthenticationPassphrase() != null)) { 67 authenticationKey = user.getAuthenticationPassphrase().getValue(); 68 if ((user.getPrivacyProtocol() != null) && 69 (user.getPrivacyPassphrase() != null)) { 70 privacyKey = user.getPrivacyPassphrase().getValue(); 71 } 72 } 73 } 74 } 75 76 86 public UsmUserEntry(OctetString userName, 87 OctetString engineID, 88 UsmUser user) { 89 this(userName, user); 90 this.engineID = engineID; 91 } 92 93 108 public UsmUserEntry(byte[] engineID, OctetString securityName, 109 OID authProtocol, byte[] authKey, 110 OID privProtocol, byte[] privKey) { 111 this.engineID = (engineID == null) ? null : new OctetString(engineID); 112 this.userName = securityName; 113 this.authenticationKey = authKey; 114 this.privacyKey = privKey; 115 this.usmUser = 116 new UsmUser(userName, authProtocol, 117 ((authenticationKey != null) ? 118 new OctetString(authenticationKey) : null), 119 privProtocol, 120 ((privacyKey != null) ? 121 new OctetString(privacyKey) : null), this.engineID); 122 } 123 124 public OctetString getEngineID() { 125 return engineID; 126 } 127 public void setEngineID(OctetString engineID) { 128 this.engineID = engineID; 129 } 130 public void setUserName(OctetString userName) { 131 this.userName = userName; 132 } 133 public OctetString getUserName() { 134 return userName; 135 } 136 public void setUsmUser(UsmUser usmUser) { 137 this.usmUser = usmUser; 138 } 139 public UsmUser getUsmUser() { 140 return usmUser; 141 } 142 public void setAuthenticationKey(byte[] authenticationKey) { 143 this.authenticationKey = authenticationKey; 144 } 145 public byte[] getAuthenticationKey() { 146 return authenticationKey; 147 } 148 public void setPrivacyKey(byte[] privacyKey) { 149 this.privacyKey = privacyKey; 150 } 151 public byte[] getPrivacyKey() { 152 return privacyKey; 153 } 154 155 165 public int compareTo(Object o) { 166 UsmUserEntry other = (UsmUserEntry)o; 167 int result = 0; 168 if ((engineID != null) && (other.engineID != null)) { 169 result = engineID.compareTo(other.engineID); 170 } 171 else if ((engineID != null) && (other.engineID == null)) { 172 result = 1; 173 } 174 else if ((engineID == null) && (other.engineID != null)) { 175 result = -1; 176 } 177 if (result == 0) { 178 result = userName.compareTo(other.userName); 179 if (result == 0) { 180 result = usmUser.compareTo(other.usmUser); 181 } 182 } 183 return result; 184 } 185 186 public String toString() { 187 return "UsmUserEntry[userName="+userName+",usmUser="+usmUser+"]"; 188 } 189 190 } 191 192 | Popular Tags |