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