use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.
the class SessionMgr method processStandaloneSuccessLogin.
// non-WEB processing
public UserSessionBase processStandaloneSuccessLogin(int authType, String ipAddress) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentLoginId = authentication.getName();
// Need to build the UserSession
XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(currentLoginId);
if (gjUser == null) {
logger.error("Error getting user for loginId=" + currentLoginId, new Exception());
return null;
}
XXAuthSession gjAuthSession = new XXAuthSession();
gjAuthSession.setLoginId(currentLoginId);
gjAuthSession.setUserId(gjUser.getId());
gjAuthSession.setAuthTime(DateUtil.getUTCDate());
gjAuthSession.setAuthStatus(XXAuthSession.AUTH_STATUS_SUCCESS);
gjAuthSession.setAuthType(authType);
gjAuthSession.setDeviceType(RangerCommonEnums.DEVICE_UNKNOWN);
gjAuthSession.setExtSessionId(null);
gjAuthSession.setRequestIP(ipAddress);
gjAuthSession.setRequestUserAgent(null);
gjAuthSession = storeAuthSession(gjAuthSession);
UserSessionBase userSession = new UserSessionBase();
userSession.setXXPortalUser(gjUser);
userSession.setXXAuthSession(gjAuthSession);
// create context with user-session and set in thread-local
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(userSession);
RangerContextHolder.setSecurityContext(context);
resetUserSessionForProfiles(userSession);
resetUserModulePermission(userSession);
return userSession;
}
use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.
the class SessionMgr method getActiveSessionsOnServer.
public CopyOnWriteArrayList<UserSessionBase> getActiveSessionsOnServer() {
CopyOnWriteArrayList<HttpSession> activeHttpUserSessions = RangerHttpSessionListener.getActiveSessionOnServer();
CopyOnWriteArrayList<UserSessionBase> activeRangerUserSessions = new CopyOnWriteArrayList<UserSessionBase>();
if (CollectionUtils.isEmpty(activeHttpUserSessions)) {
return activeRangerUserSessions;
}
for (HttpSession httpSession : activeHttpUserSessions) {
if (httpSession.getAttribute(RangerSecurityContextFormationFilter.AKA_SC_SESSION_KEY) == null) {
continue;
}
RangerSecurityContext securityContext = (RangerSecurityContext) httpSession.getAttribute(RangerSecurityContextFormationFilter.AKA_SC_SESSION_KEY);
if (securityContext.getUserSession() != null) {
activeRangerUserSessions.add(securityContext.getUserSession());
}
}
return activeRangerUserSessions;
}
use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.
the class ContextUtil method getCurrentUserSession.
public static UserSessionBase getCurrentUserSession() {
UserSessionBase userSession = null;
RangerSecurityContext context = RangerContextHolder.getSecurityContext();
if (context != null) {
userSession = context.getUserSession();
}
return userSession;
}
use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.
the class TestRangerPolicyService method setup.
public void setup() {
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(true);
}
use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.
the class TestRangerPolicyServiceBase method setup.
public void setup() {
RangerSecurityContext context = new RangerSecurityContext();
context.setUserSession(new UserSessionBase());
RangerContextHolder.setSecurityContext(context);
UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
currentUserSession.setUserAdmin(true);
}
Aggregations