1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.gateway.ftp.file;
22
23 import org.waarp.common.logging.WaarpLogger;
24 import org.waarp.common.logging.WaarpLoggerFactory;
25 import org.waarp.gateway.ftp.exec.AbstractExecutor.CommandExecutor;
26
27
28
29
30 public class SimpleAuth {
31
32
33
34 private static final WaarpLogger logger =
35 WaarpLoggerFactory.getLogger(SimpleAuth.class);
36
37
38
39
40 private String user;
41
42
43
44
45 private String password;
46
47
48
49
50 private String[] accounts;
51
52
53
54
55
56 private boolean isAdmin;
57
58
59
60 private String storCmd;
61
62
63
64 private long storDelay;
65
66
67
68 private String retrCmd;
69
70
71
72 private long retrDelay;
73
74 private CommandExecutor commandExecutor;
75
76
77
78
79
80
81
82
83
84
85 public SimpleAuth(final String user, final String password,
86 final String[] accounts, final String storCmd,
87 final long storDelay, final String retrCmd,
88 final long retrDelay) {
89 setUser(user);
90 setPassword(password);
91 setAccounts(accounts);
92 setStorCmd(storCmd);
93 setStorDelay(storDelay);
94 setRetrCmd(retrCmd);
95 setRetrDelay(retrDelay);
96 setCommandExecutor(
97 new CommandExecutor(retrCmd, retrDelay, storCmd, storDelay));
98 if (logger.isInfoEnabled()) {
99 logger.info("Executor for " + user + " configured as [RETR: " +
100 getCommandExecutor().getRetrType() + ':' +
101 getCommandExecutor().pretrCMD + ':' +
102 getCommandExecutor().getPretrDelay() + ':' +
103 getCommandExecutor().isPretrRefused() + "] [STOR: " +
104 getCommandExecutor().getStorType() + ':' +
105 getCommandExecutor().pstorCMD + ':' +
106 getCommandExecutor().getPstorDelay() + ':' +
107 getCommandExecutor().isPstorRefused() + ']');
108 }
109 }
110
111
112
113
114
115
116
117
118 public final boolean isPasswordValid(final String newpassword) {
119 if (getPassword() == null) {
120 return true;
121 }
122 if (newpassword == null) {
123 return false;
124 }
125 return getPassword().equals(newpassword);
126 }
127
128
129
130
131
132
133
134
135 public final boolean isAccountValid(final String account) {
136 if (getAccounts() == null) {
137 logger.debug("No account needed");
138 return true;
139 }
140 if (account == null) {
141 logger.info("No account given");
142 return false;
143 }
144 for (final String acct : getAccounts()) {
145 if (acct.equals(account)) {
146 logger.debug("Account found");
147 return true;
148 }
149 }
150 logger.info("No account found");
151 return false;
152 }
153
154
155
156
157 public final void setAdmin(final boolean isAdmin) {
158 this.isAdmin = isAdmin;
159 }
160
161
162
163
164 public final String getUser() {
165 return user;
166 }
167
168
169
170
171 private void setUser(final String user) {
172 this.user = user;
173 }
174
175
176
177
178 public final String getPassword() {
179 return password;
180 }
181
182
183
184
185 private void setPassword(final String password) {
186 this.password = password;
187 }
188
189
190
191
192 public final String[] getAccounts() {
193 return accounts;
194 }
195
196
197
198
199 private void setAccounts(final String[] accounts) {
200 this.accounts = accounts;
201 }
202
203
204
205
206 public final boolean isAdmin() {
207 return isAdmin;
208 }
209
210
211
212
213 public final String getStorCmd() {
214 return storCmd;
215 }
216
217
218
219
220 private void setStorCmd(final String storCmd) {
221 this.storCmd = storCmd;
222 }
223
224
225
226
227 public final long getStorDelay() {
228 return storDelay;
229 }
230
231
232
233
234 private void setStorDelay(final long storDelay) {
235 this.storDelay = storDelay;
236 }
237
238
239
240
241 public final String getRetrCmd() {
242 return retrCmd;
243 }
244
245
246
247
248 private void setRetrCmd(final String retrCmd) {
249 this.retrCmd = retrCmd;
250 }
251
252
253
254
255 public final long getRetrDelay() {
256 return retrDelay;
257 }
258
259
260
261
262 private void setRetrDelay(final long retrDelay) {
263 this.retrDelay = retrDelay;
264 }
265
266
267
268
269 public final CommandExecutor getCommandExecutor() {
270 return commandExecutor;
271 }
272
273
274
275
276 private void setCommandExecutor(final CommandExecutor commandExecutor) {
277 this.commandExecutor = commandExecutor;
278 }
279 }