2121import com .keybox .manage .model .Auth ;
2222import com .keybox .manage .model .User ;
2323import com .keybox .manage .util .OTPUtil ;
24- import com .keybox .manage .util .PasswordUtil ;
2524import com .opensymphony .xwork2 .ActionSupport ;
2625import org .apache .commons .lang3 .StringUtils ;
2726import org .apache .struts2 .convention .annotation .Action ;
2827import org .apache .struts2 .convention .annotation .Result ;
2928import org .apache .struts2 .interceptor .ServletRequestAware ;
3029import org .apache .struts2 .interceptor .ServletResponseAware ;
31- import sun .misc .SharedSecrets ;
30+ import org .slf4j .Logger ;
31+ import org .slf4j .LoggerFactory ;
3232
3333import javax .servlet .http .HttpServletRequest ;
3434import javax .servlet .http .HttpServletResponse ;
3939 */
4040public class LoginAction extends ActionSupport implements ServletRequestAware , ServletResponseAware {
4141
42+ private static Logger loginAuditLogger = LoggerFactory .getLogger ("com.keybox.manage.action.LoginAudit" );
4243 HttpServletResponse servletResponse ;
4344 HttpServletRequest servletRequest ;
4445 Auth auth ;
4546 private final String AUTH_ERROR ="Authentication Failed : Login credentials are invalid" ;
47+ private final String AUTH_ERROR_NO_PROFILE ="Authentication Failed : There are no profiles assigned to this account" ;
4648 //check if otp is enabled
4749 boolean otpEnabled = ("required" .equals (AppConfig .getProperty ("oneTimePassword" )) || "optional" .equals (AppConfig .getProperty ("oneTimePassword" )));
4850
@@ -79,6 +81,11 @@ public String loginSubmit() {
7981 String retVal = SUCCESS ;
8082
8183 String authToken = AuthDB .login (auth );
84+
85+ String clientIP = servletRequest .getHeader ("X-FORWARDED-FOR" );
86+ if (StringUtils .isEmpty (clientIP )) {
87+ clientIP = servletRequest .getRemoteAddr ();
88+ }
8289 if (authToken != null ) {
8390
8491 User user = AuthDB .getUserByAuthToken (authToken );
@@ -87,13 +94,15 @@ public String loginSubmit() {
8794 if (otpEnabled ) {
8895 sharedSecret = AuthDB .getSharedSecret (user .getId ());
8996 if (StringUtils .isNotEmpty (sharedSecret ) && (auth .getOtpToken () == null || !OTPUtil .verifyToken (sharedSecret , auth .getOtpToken ()))) {
97+ loginAuditLogger .info (clientIP + " " + AUTH_ERROR );
9098 addActionError (AUTH_ERROR );
9199 return INPUT ;
92100 }
93101 }
94102 //check to see if admin has any assigned profiles
95103 if (!User .MANAGER .equals (user .getUserType ()) && (user .getProfileList ()==null || user .getProfileList ().size ()<=0 )){
96- addActionError ("Authentication Failed : There are no profiles assigned to this account" );
104+ loginAuditLogger .info (clientIP + " " + AUTH_ERROR_NO_PROFILE );
105+ addActionError (AUTH_ERROR_NO_PROFILE );
97106 return INPUT ;
98107 }
99108
@@ -104,19 +113,19 @@ public String loginSubmit() {
104113
105114 //for first time login redirect to set OTP
106115 if (otpEnabled && StringUtils .isEmpty (sharedSecret )) {
107- return "otp" ;
116+ retVal = "otp" ;
108117 } else if ("changeme" .equals (auth .getPassword ()) && Auth .AUTH_BASIC .equals (user .getAuthType ())) {
109118 retVal = "change_password" ;
110119 }
120+ loginAuditLogger .info (clientIP + " Authentication Success" );
111121 }
112122
113123 } else {
124+ loginAuditLogger .info (clientIP + " " + AUTH_ERROR );
114125 addActionError (AUTH_ERROR );
115126 retVal = INPUT ;
116127 }
117128
118-
119-
120129 return retVal ;
121130 }
122131
0 commit comments