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