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