// Add to the MDC logging
MdcInjectionFilter.setProperty(session, "userName", userName);
// already logged-in
User user = session.getUser();
if (session.isLoggedIn()) {
if (userName.equals(user.getName())) {
session.write(LocalizedFtpReply.translate(session, request,
context, FtpReply.REPLY_230_USER_LOGGED_IN, "USER",
null));
success = true;
} else {
session.write(LocalizedFtpReply.translate(session, request,
context, 530, "USER.invalid", null));
}
return;
}
// anonymous login is not enabled
boolean anonymous = userName.equals("anonymous");
if (anonymous
&& (!context.getConnectionConfig()
.isAnonymousLoginEnabled())) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_530_NOT_LOGGED_IN, "USER.anonymous",
null));
return;
}
// anonymous login limit check
int currAnonLogin = stat.getCurrentAnonymousLoginNumber();
int maxAnonLogin = context.getConnectionConfig()
.getMaxAnonymousLogins();
if (anonymous && (currAnonLogin >= maxAnonLogin)) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
"USER.anonymous", null));
return;
}
// login limit check
int currLogin = stat.getCurrentLoginNumber();
int maxLogin = context.getConnectionConfig().getMaxLogins();
if (maxLogin != 0 && currLogin >= maxLogin) {
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
"USER.login", null));
return;
}
User configUser = context.getUserManager().getUserByName(userName);
if (configUser != null) {
// user login limit check
InetAddress address = null;
if (session.getRemoteAddress() instanceof InetSocketAddress) {
address = ((InetSocketAddress) session.getRemoteAddress())
.getAddress();
}
ConcurrentLoginRequest loginRequest = new ConcurrentLoginRequest(
stat.getCurrentUserLoginNumber(configUser) + 1,
stat.getCurrentUserLoginNumber(configUser, address) + 1);
if (configUser.authorize(loginRequest) == null) {
session
.write(LocalizedFtpReply
.translate(
session,
request,