Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions security-admin/src/main/java/org/apache/ranger/biz/SessionMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -326,6 +327,18 @@ public XXAuthSession processFailureLogin(int authStatus, int authType,
return gjAuthSession;
}

public Date getLastSuccessLoginAuthTimeByUserId(String loginId) {
XXAuthSession xXAuthSession = daoManager.getXXAuthSession().getLastSuccessLoginAuthSessionByUserId(loginId);

if (xXAuthSession != null) {
return authSessionService.populateViewBean(xXAuthSession).getAuthTime();
} else {
logger.info("Session cleaned up or User logged in for first time");
}

return null;
}

protected boolean validateUserSession(UserSessionBase userSession,
String currentLoginId) {
if (currentLoginId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ public VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user,

userProfile.setUserRoleList(userRoleList);
}
userProfile.setLastLoginTime(sessionMgr.getLastSuccessLoginAuthTimeByUserId(sess.getLoginId()));
userProfile.setUserSource(user.getUserSource());

return userProfile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ public List<XXAuthSession> getAuthSessionByUserId(Long userId){
}
}

public XXAuthSession getLastSuccessLoginAuthSessionByUserId(String loginId) {
if (loginId == null) {
return null;
}
try {
List<XXAuthSession> sessions = getEntityManager()
.createNamedQuery("XXAuthSession.getSuccessAuthSessionsByUserId", tClass)
.setParameter("loginId", loginId)
.setParameter("authStatus", XXAuthSession.AUTH_STATUS_SUCCESS)
.setMaxResults(2)
.getResultList();
return sessions.size() >= 2 ? sessions.get(1) : null;
} catch (NoResultException ignoreNoResultFound) {
return null;
}
}

public long getRecentAuthFailureCountByLoginId(String loginId, int timeRangezSecond){
Date authWindowStartTime = new Date(DateUtil.getUTCDate().getTime() - timeRangezSecond * 1000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
package org.apache.ranger.view;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ranger.common.AppConstants;
import org.apache.ranger.json.JsonDateSerializer;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@JsonAutoDetect(getterVisibility=Visibility.NONE, setterVisibility=Visibility.NONE, fieldVisibility=Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -95,6 +98,9 @@ public class VXPortalUser extends VXDataObject implements java.io.Serializable {
*/
protected String syncSource;

@JsonSerialize(using = JsonDateSerializer.class)
protected Date lastLoginTime;

/**
* Configuration properties.
*
Expand Down Expand Up @@ -348,6 +354,14 @@ public void setSyncSource(final String syncSource) {
this.syncSource = syncSource;
}

public Date getLastLoginTime() {
return lastLoginTime;
}

public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}

/**
* This return the bean content in string format
* @return formatedStr
Expand All @@ -366,6 +380,7 @@ public String toString( ) {
str += "userRoleList={" + userRoleList + "} ";
str += "otherAttributes={" + otherAttributes + "} ";
str += "syncSource={" + syncSource + "} ";
str += "lastLoginTime={" + lastLoginTime + "} ";
str += "}";
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<query>DELETE FROM XXAuthSession obj WHERE obj.id in :ids
</query>
</named-query>
<named-query name="XXAuthSession.getSuccessAuthSessionsByUserId">
<query>SELECT obj FROM XXAuthSession obj WHERE obj.loginId = :loginId and obj.authStatus = :authStatus order by obj.id DESC
</query>
</named-query>


<!-- XXPortalUser -->
<named-query name="XXPortalUser.findByEmailAddress">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ header {
}

.top-scroll {
bottom: 3px;
bottom: 10px;
right: 5px;
}

Expand Down
11 changes: 11 additions & 0 deletions security-admin/src/main/webapp/react-webapp/src/views/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Loader } from "../components/CommonComponents";
import { Suspense } from "react";
import { PathAssociateWithModule } from "../utils/XAEnums";
import { flatMap, values } from "lodash";
import dateFormat from "dateformat";

const Layout = () => {
let location = useLocation();
Expand Down Expand Up @@ -94,6 +95,13 @@ const Layout = () => {
activate();
};

const lastLoginInformation = userProfile?.lastLoginTime
? `You last logged in on, ${dateFormat(
new Date(userProfile.lastLoginTime),
"dddd, mmm dd, yyyy, hh:MM:ss TT"
)}`
: "";

useEffect(() => {
const interval = setInterval(() => {
if (isPrompted()) {
Expand Down Expand Up @@ -170,6 +178,9 @@ const Layout = () => {
>
Licensed under the Apache License, Version 2.0
</a>
<span className="float-end mb-2 me-4" style={{ color: "#999" }}>
{lastLoginInformation}
</span>
</p>
</div>
</footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const SideBar = () => {

const userProps = getUserProfile();
const loginId = (
<span className="login-id user-name">{userProps?.loginId}</span>
<span className="login-id user-name p-0">{userProps?.loginId}</span>
);

let location = useLocation();
Expand Down