1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.gateway.ftp.config;
21
22 import org.waarp.common.command.ReplyCode;
23 import org.waarp.common.command.exception.CommandAbstractException;
24 import org.waarp.common.command.exception.Reply500Exception;
25 import org.waarp.common.command.exception.Reply501Exception;
26 import org.waarp.common.logging.WaarpLogger;
27 import org.waarp.common.logging.WaarpLoggerFactory;
28 import org.waarp.ftp.core.command.AbstractCommand;
29
30 import java.io.File;
31
32
33
34
35
36
37
38
39
40
41
42 public class AUTHUPDATE extends AbstractCommand {
43
44
45
46 private static final WaarpLogger logger =
47 WaarpLoggerFactory.getLogger(AUTHUPDATE.class);
48
49 @Override
50 public final void exec() throws CommandAbstractException {
51 if (!getSession().getAuth().isAdmin()) {
52
53 throw new Reply500Exception("Command Not Allowed");
54 }
55 String filename = null;
56 boolean purge = false;
57 boolean write = false;
58 if (!hasArg()) {
59 filename =
60 ((FileBasedConfiguration) getConfiguration()).getAuthenticationFile();
61 } else {
62 final String[] authents = getArgs();
63 for (final String authent : authents) {
64 if ("PURGE".equalsIgnoreCase(authent)) {
65 purge = true;
66 } else if ("SAVE".equalsIgnoreCase(authent)) {
67 write = true;
68 } else if (filename == null) {
69 filename = authent;
70 }
71 }
72 if (filename == null) {
73 filename =
74 ((FileBasedConfiguration) getConfiguration()).getAuthenticationFile();
75 }
76 final File file = new File(filename);
77 if (!file.canRead()) {
78 throw new Reply501Exception(
79 "Filename given as parameter is not found: " + filename);
80 }
81 }
82 if (!((FileBasedConfiguration) getConfiguration()).initializeAuthent(
83 filename, purge)) {
84 throw new Reply501Exception("Filename given as parameter is not correct");
85 }
86 if (write &&
87 !((FileBasedConfiguration) getConfiguration()).saveAuthenticationFile(
88 ((FileBasedConfiguration) getConfiguration()).getAuthenticationFile())) {
89 throw new Reply501Exception(
90 "Update is done but Write operation is not correct");
91 }
92 logger.warn("Authentication was updated from " + filename);
93 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
94 "Authentication is updated");
95 }
96
97 }