1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.openr66.pojo;
22
23 import com.fasterxml.jackson.annotation.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import org.waarp.common.database.exception.WaarpDatabaseSqlException;
26 import org.waarp.common.utility.WaarpStringUtils;
27
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.XmlTransient;
32 import javax.xml.bind.annotation.XmlType;
33 import java.sql.Types;
34
35 import static org.waarp.common.database.data.AbstractDbData.*;
36 import static org.waarp.openr66.configuration.FileBasedElements.*;
37
38
39
40
41 @XmlType(name = XML_AUTHENTICATION_ENTRY)
42 @XmlAccessorType(XmlAccessType.FIELD)
43 public class Host {
44 @XmlElement(name = XML_AUTHENTICATION_HOSTID)
45 @JsonProperty("HOSTID")
46 private String hostid;
47
48 @XmlElement(name = XML_AUTHENTICATION_ADDRESS)
49 @JsonProperty("ADDRESS")
50 private String address;
51
52 @XmlElement(name = XML_AUTHENTICATION_PORT)
53 @JsonProperty("PORT")
54 private int port;
55
56 @XmlTransient
57 @JsonProperty("HOSTKEY")
58 private byte[] hostkey;
59
60 @XmlElement(name = XML_AUTHENTICATION_ISSSL)
61 @JsonProperty("ISSSL")
62 private boolean ssl;
63
64 @XmlElement(name = XML_AUTHENTICATION_ISCLIENT)
65 @JsonProperty("ISCLIENT")
66 private boolean client;
67
68 @XmlElement(name = XML_AUTHENTICATION_ISPROXIFIED)
69 @JsonProperty("ISPROXIFIED")
70 private boolean proxified;
71
72 @XmlElement(name = XML_AUTHENTICATION_ADMIN)
73 @JsonProperty("ADMINROLE")
74 private boolean admin = true;
75
76 @XmlElement(name = XML_AUTHENTICATION_ISACTIVE)
77 @JsonProperty("ISACTIVE")
78 private boolean active = true;
79
80 @JsonProperty("UPDATEDINFO")
81 private UpdatedInfo updatedInfo = UpdatedInfo.UNKNOWN;
82
83
84
85
86 public Host() {
87
88 }
89
90 public Host(final String hostid, final String address, final int port,
91 final byte[] hostkey, final boolean ssl, final boolean client,
92 final boolean proxified, final boolean admin,
93 final boolean active, final UpdatedInfo updatedInfo)
94 throws WaarpDatabaseSqlException {
95 this(hostid, address, port, hostkey, ssl, client, proxified, admin, active);
96 this.updatedInfo = updatedInfo;
97 }
98
99 public Host(final String hostid, final String address, final int port,
100 final byte[] hostkey, final boolean ssl, final boolean client,
101 final boolean proxified, final boolean admin,
102 final boolean active) throws WaarpDatabaseSqlException {
103 this.hostid = hostid;
104 this.hostkey = hostkey;
105
106 this.address = address;
107 this.port = port;
108 this.client = client;
109 this.ssl = ssl;
110 this.proxified = proxified;
111 this.admin = admin;
112 this.active = active;
113 checkValues();
114 }
115
116 public Host(final String hostid, final String address, final int port,
117 final byte[] hostkey, final boolean ssl, final boolean client,
118 final boolean proxified, final boolean admin)
119 throws WaarpDatabaseSqlException {
120 this(hostid, address, port, hostkey, ssl, client, proxified, admin, true);
121 }
122
123 public Host(final String hostid, final String address, final int port,
124 final byte[] hostkey, final boolean ssl, final boolean client)
125 throws WaarpDatabaseSqlException {
126 this(hostid, address, port, hostkey, ssl, client, false, true, true);
127 }
128
129 @JsonIgnore
130 public final void checkValues() throws WaarpDatabaseSqlException {
131 validateLength(hostkey);
132 validateLength(Types.NVARCHAR, address, hostid);
133 }
134
135 public final String getHostid() {
136 return hostid;
137 }
138
139 public final void setHostid(final String hostid) {
140 this.hostid = hostid;
141 }
142
143 public final String getAddress() {
144 return address;
145 }
146
147 public final void setAddress(final String address) {
148 this.address = address;
149 }
150
151 public final int getPort() {
152 return port;
153 }
154
155 public final void setPort(final int port) {
156 this.port = port;
157 }
158
159 public final byte[] getHostkey() {
160 return hostkey;
161 }
162
163 @XmlElement(name = XML_AUTHENTICATION_KEY)
164 @JsonIgnore
165 public final String getKey() {
166 return new String(hostkey, WaarpStringUtils.UTF8);
167 }
168
169 public final void setKey(final String key) {
170 hostkey = key.getBytes(WaarpStringUtils.UTF8);
171 }
172
173 public final void setHostkey(final byte[] hostkey) {
174 this.hostkey = hostkey;
175 }
176
177 public final boolean isSSL() {
178 return ssl;
179 }
180
181 public final void setSSL(final boolean ssl) {
182 this.ssl = ssl;
183 }
184
185 public final boolean isClient() {
186 return client;
187 }
188
189 public final void setClient(final boolean client) {
190 this.client = client;
191 }
192
193 public final boolean isAdmin() {
194 return admin;
195 }
196
197 public final void setAdmin(final boolean admin) {
198 this.admin = admin;
199 }
200
201 public final boolean isProxified() {
202 return proxified;
203 }
204
205 public final void setProxified(final boolean proxified) {
206 this.proxified = proxified;
207 }
208
209 public final boolean isActive() {
210 return active;
211 }
212
213 public final void setActive(final boolean active) {
214 this.active = active;
215 }
216
217 public final UpdatedInfo getUpdatedInfo() {
218 return updatedInfo;
219 }
220
221 public final void setUpdatedInfo(final UpdatedInfo info) {
222 updatedInfo = info;
223 }
224 }