diff --git a/conf/hash-replies.properties b/conf/hash-replies.properties
index 45fa65f..ff69402 100644
--- a/conf/hash-replies.properties
+++ b/conf/hash-replies.properties
@@ -1,2 +1,2 @@
-prompt=$
+prompt={user}$
chpasswd=Password updated
\ No newline at end of file
diff --git a/conf/log4j2.xml b/conf/log4j2.xml
index d0cc96c..530126a 100644
--- a/conf/log4j2.xml
+++ b/conf/log4j2.xml
@@ -32,13 +32,25 @@
+
+
+
+
+
+
-
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 0a2c180..b307b2e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.example.sshd
echo-sshd-server
- 1.4.1
+ 1.4.2
ECHO SSH SERVER
Learning Apache Mina SSHD library
diff --git a/src/main/java/com/example/sshd/config/SshConfig.java b/src/main/java/com/example/sshd/config/SshConfig.java
index ede4d7e..e8b2259 100644
--- a/src/main/java/com/example/sshd/config/SshConfig.java
+++ b/src/main/java/com/example/sshd/config/SshConfig.java
@@ -3,6 +3,7 @@ package com.example.sshd.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Properties;
@@ -28,7 +29,7 @@ import com.example.sshd.core.OnetimeCommand;
@Configuration
public class SshConfig {
- private static final Logger logger = LoggerFactory.getLogger(SshConfig.class);
+ private static final Logger loginLogger = LoggerFactory.getLogger("login");
@Value("${ssh-server.port}")
private int port;
@@ -57,7 +58,15 @@ public class SshConfig {
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(final String username, final String password, final ServerSession session) {
- logger.info("Login Attempt: username = {}, password = {}", username, password);
+ if (session.getIoSession().getRemoteAddress() instanceof InetSocketAddress) {
+ InetSocketAddress remoteAddress = (InetSocketAddress) session.getIoSession().getRemoteAddress();
+ String remoteIpAddress = remoteAddress.getAddress().getHostAddress();
+ loginLogger.info("[{}] Login Attempt: username = {}, password = {}", remoteIpAddress, username,
+ password);
+ } else {
+ loginLogger.info("[{}] Login Attempt: username = {}, password = {}",
+ session.getIoSession().getRemoteAddress(), username, password);
+ }
return Arrays.asList(usernames).contains(username);
}
});
diff --git a/src/main/java/com/example/sshd/core/EchoShell.java b/src/main/java/com/example/sshd/core/EchoShell.java
index 085771b..b961777 100644
--- a/src/main/java/com/example/sshd/core/EchoShell.java
+++ b/src/main/java/com/example/sshd/core/EchoShell.java
@@ -91,7 +91,7 @@ public class EchoShell implements Command, Runnable, SessionAware {
@Override
public void run() {
- String prompt = hashReplies.getProperty("prompt", "$ ");
+ String prompt = hashReplies.getProperty("prompt", "$ ").replace("{user}", environment.getEnv().get("USER"));
try {
out.write(prompt.getBytes());
out.flush();
diff --git a/src/main/java/com/example/sshd/service/JdbcService.java b/src/main/java/com/example/sshd/service/JdbcService.java
index 24a611c..94d168e 100644
--- a/src/main/java/com/example/sshd/service/JdbcService.java
+++ b/src/main/java/com/example/sshd/service/JdbcService.java
@@ -2,6 +2,7 @@ package com.example.sshd.service;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -35,12 +36,24 @@ public class JdbcService {
new RowMapper