0956403f759a3888523c99047f9d2da76b118d27
[public/netxms.git] / src / client / java / netxms-client / src / main / java / org / netxms / client / snmp / SnmpUsmCredential.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2009 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client.snmp;
20
21 import org.netxms.base.NXCPMessage;
22
23 /**
24 * @author Victor
25 *
26 */
27 public class SnmpUsmCredential
28 {
29 private String name;
30 private int authMethod;
31 private int privMethod;
32 private String authPassword;
33 private String privPassword;
34
35 /**
36 * Create credentials object from data in NXCP message
37 *
38 * @param msg NXCP message
39 * @param baseId Base variable ID
40 */
41 public SnmpUsmCredential(NXCPMessage msg, long baseId)
42 {
43 name = msg.getFieldAsString(baseId);
44 authMethod = msg.getFieldAsInt32(baseId + 1);
45 privMethod = msg.getFieldAsInt32(baseId + 2);
46 authPassword = msg.getFieldAsString(baseId + 3);
47 privPassword = msg.getFieldAsString(baseId + 4);
48 }
49
50 /**
51 * Default constructor.
52 */
53 public SnmpUsmCredential()
54 {
55 name = "";
56 authMethod = 0;
57 privMethod = 0;
58 authPassword = "";
59 privPassword = "";
60 }
61
62 /**
63 * Fill NXCP message with object's data
64 *
65 * @param msg NXCP message
66 * @param baseId Base variable ID
67 */
68 public void fillMessage(final NXCPMessage msg, long baseId)
69 {
70 msg.setField(baseId, name);
71 msg.setFieldInt16(baseId + 1, authMethod);
72 msg.setFieldInt16(baseId + 2, privMethod);
73 msg.setField(baseId + 3, authPassword);
74 msg.setField(baseId + 4, privPassword);
75 }
76
77 /**
78 * @return the name
79 */
80 public String getName()
81 {
82 return name;
83 }
84
85 /**
86 * @param name the name to set
87 */
88 public void setName(String name)
89 {
90 this.name = name;
91 }
92
93 /**
94 * @return the authMethod
95 */
96 public int getAuthMethod()
97 {
98 return authMethod;
99 }
100
101 /**
102 * @param authMethod the authMethod to set
103 */
104 public void setAuthMethod(int authMethod)
105 {
106 this.authMethod = authMethod;
107 }
108
109 /**
110 * @return the privMethod
111 */
112 public int getPrivMethod()
113 {
114 return privMethod;
115 }
116
117 /**
118 * @param privMethod the privMethod to set
119 */
120 public void setPrivMethod(int privMethod)
121 {
122 this.privMethod = privMethod;
123 }
124
125 /**
126 * @return the authPassword
127 */
128 public String getAuthPassword()
129 {
130 return authPassword;
131 }
132
133 /**
134 * @param authPassword the authPassword to set
135 */
136 public void setAuthPassword(String authPassword)
137 {
138 this.authPassword = authPassword;
139 }
140
141 /**
142 * @return the privPassword
143 */
144 public String getPrivPassword()
145 {
146 return privPassword;
147 }
148
149 /**
150 * @param privPassword the privPassword to set
151 */
152 public void setPrivPassword(String privPassword)
153 {
154 this.privPassword = privPassword;
155 }
156
157 /* (non-Javadoc)
158 * @see java.lang.Object#hashCode()
159 */
160 @Override
161 public int hashCode()
162 {
163 final int prime = 31;
164 int result = 1;
165 result = prime * result + authMethod;
166 result = prime * result + ((authPassword == null) ? 0 : authPassword.hashCode());
167 result = prime * result + ((name == null) ? 0 : name.hashCode());
168 result = prime * result + privMethod;
169 result = prime * result + ((privPassword == null) ? 0 : privPassword.hashCode());
170 return result;
171 }
172
173 /* (non-Javadoc)
174 * @see java.lang.Object#equals(java.lang.Object)
175 */
176 @Override
177 public boolean equals(Object obj)
178 {
179 if (this == obj)
180 return true;
181 if (obj == null)
182 return false;
183 if (getClass() != obj.getClass())
184 return false;
185 SnmpUsmCredential other = (SnmpUsmCredential)obj;
186 if (authMethod != other.authMethod)
187 return false;
188 if (authPassword == null)
189 {
190 if (other.authPassword != null)
191 return false;
192 }
193 else if (!authPassword.equals(other.authPassword))
194 return false;
195 if (name == null)
196 {
197 if (other.name != null)
198 return false;
199 }
200 else if (!name.equals(other.name))
201 return false;
202 if (privMethod != other.privMethod)
203 return false;
204 if (privPassword == null)
205 {
206 if (other.privPassword != null)
207 return false;
208 }
209 else if (!privPassword.equals(other.privPassword))
210 return false;
211 return true;
212 }
213 }