Skip to content

Commit f6d16d0

Browse files
SakshamsAlena Prokharchyk
authored andcommitted
CS-15018: Event USER.LOGIN should contain the client IP address. Changes made in accordance with the coding convention.
Reviewed-by: Alena Prokharchyk
1 parent 8101515 commit f6d16d0

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎server/src/com/cloud/api/ApiServer.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public Long fetchDomainId(String domainUUID){
773773
}
774774
}
775775

776-
public void loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
776+
public void loginUser(HttpSession session, String username, String password, Long domainId, String domainPath, String loginIpAddress ,Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
777777
// We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist
778778
// we will default to ROOT
779779
if (domainId == null) {
@@ -789,7 +789,7 @@ public void loginUser(HttpSession session, String username, String password, Lon
789789
}
790790
}
791791

792-
UserAccount userAcct = _accountMgr.authenticateUser(username, password, domainId, requestParameters);
792+
UserAccount userAcct = _accountMgr.authenticateUser(username, password, domainId, loginIpAddress, requestParameters);
793793
if (userAcct != null) {
794794
String timezone = userAcct.getTimezone();
795795
float offsetInHrs = 0f;

‎server/src/com/cloud/api/ApiServlet.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private void processRequest(HttpServletRequest req, HttpServletResponse resp) {
203203
if (username != null) {
204204
String pwd = ((password == null) ? null : password[0]);
205205
try {
206-
_apiServer.loginUser(session, username[0], pwd, domainId, domain, params);
206+
_apiServer.loginUser(session, username[0], pwd, domainId, domain, req.getRemoteAddr(), params);
207207
auditTrailSb.insert(0,
208208
"(userId=" + session.getAttribute("userid") + " accountId=" + ((Account) session.getAttribute("accountobj")).getId() + " sessionId=" + session.getId() + ")");
209209
String loginResponse = getLoginSuccessResponse(session, responseType);

‎server/src/com/cloud/user/AccountManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public interface AccountManager extends AccountService {
7171
* made, and the signature itself in the single sign-on case
7272
* @return a user object, null if the user failed to authenticate
7373
*/
74-
UserAccount authenticateUser(String username, String password, Long domainId, Map<String, Object[]> requestParameters);
74+
UserAccount authenticateUser(String username, String password, Long domainId, String loginIpAddress, Map<String, Object[]> requestParameters);
7575

7676
/**
7777
* Locate a user by their apiKey

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ public UserAccount getUserAccount(String username, Long domainId) {
16181618
}
16191619

16201620
@Override
1621-
public UserAccount authenticateUser(String username, String password, Long domainId, Map<String, Object[]> requestParameters) {
1621+
public UserAccount authenticateUser(String username, String password, Long domainId, String loginIpAddress, Map<String, Object[]> requestParameters) {
16221622
UserAccount user = null;
16231623
if (password != null) {
16241624
user = getUserAccount(username, password, domainId, requestParameters);
@@ -1720,7 +1720,13 @@ public UserAccount authenticateUser(String username, String password, Long domai
17201720
if (s_logger.isDebugEnabled()) {
17211721
s_logger.debug("User: " + username + " in domain " + domainId + " has successfully logged in");
17221722
}
1723-
EventUtils.saveEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_LOGIN, "user has logged in");
1723+
if (NetUtils.isValidIp(loginIpAddress)) {
1724+
EventUtils.saveEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_LOGIN,
1725+
"user has logged in from IP Address " + loginIpAddress);
1726+
} else {
1727+
EventUtils.saveEvent(user.getId(), user.getAccountId(), user.getDomainId(), EventTypes.EVENT_USER_LOGIN,
1728+
"user has logged in. The IP Address cannot be determined");
1729+
}
17241730
return user;
17251731
} else {
17261732
if (s_logger.isDebugEnabled()) {

‎server/test/com/cloud/user/MockAccountManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public UserAccount getUserAccount(String username, Long domainId) {
254254
}
255255

256256
@Override
257-
public UserAccount authenticateUser(String username, String password, Long domainId, Map<String, Object[]> requestParameters) {
257+
public UserAccount authenticateUser(String username, String password, Long domainId, String loginIpAddress, Map<String, Object[]> requestParameters) {
258258
return null;
259259
}
260260

0 commit comments

Comments
 (0)