1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.ftp.filesystembased;
21
22 import org.waarp.common.command.NextCommandReply;
23 import org.waarp.common.command.ReplyCode;
24 import org.waarp.common.command.exception.Reply421Exception;
25 import org.waarp.common.command.exception.Reply502Exception;
26 import org.waarp.common.command.exception.Reply530Exception;
27 import org.waarp.common.file.DirInterface;
28 import org.waarp.common.file.filesystembased.FilesystemBasedAuthImpl;
29 import org.waarp.ftp.core.file.FtpAuth;
30 import org.waarp.ftp.core.session.FtpSession;
31
32
33
34
35 public abstract class FilesystemBasedFtpAuth extends FilesystemBasedAuthImpl
36 implements FtpAuth {
37
38
39
40
41 protected String account;
42
43
44
45
46 protected FilesystemBasedFtpAuth(final FtpSession session) {
47 super(session);
48 }
49
50
51
52
53 @Override
54 public final String getAccount() {
55 return account;
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 protected abstract NextCommandReply setBusinessAccount(String account)
78 throws Reply421Exception, Reply530Exception, Reply502Exception;
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 @Override
95 public final NextCommandReply setAccount(final String account)
96 throws Reply421Exception, Reply530Exception, Reply502Exception {
97 final NextCommandReply next = setBusinessAccount(account);
98 this.account = account;
99 if (next.reply == ReplyCode.REPLY_230_USER_LOGGED_IN) {
100 setRootFromAuth();
101 session.getDir().initAfterIdentification();
102 }
103 return next;
104 }
105
106
107
108
109
110
111
112
113
114
115 @Override
116 protected final void setRootFromAuth() throws Reply421Exception {
117 rootFromAuth = setBusinessRootFromAuth();
118 if (rootFromAuth == null) {
119 if (account == null) {
120 rootFromAuth = DirInterface.SEPARATOR + user;
121 } else {
122 rootFromAuth =
123 DirInterface.SEPARATOR + user + DirInterface.SEPARATOR + account;
124 }
125 }
126 }
127
128
129
130
131 @Override
132 public final void clear() {
133 super.clear();
134 account = null;
135 }
136
137 @Override
138 public final String getBaseDirectory() {
139 return ((FtpSession) getSession()).getConfiguration().getBaseDirectory();
140 }
141 }