Search in sources :

Example 1 with RangerSecurityContext

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;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) Authentication(org.springframework.security.core.Authentication) XXAuthSession(org.apache.ranger.entity.XXAuthSession) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 2 with RangerSecurityContext

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;
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) HttpSession(javax.servlet.http.HttpSession) UserSessionBase(org.apache.ranger.common.UserSessionBase) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with RangerSecurityContext

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;
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext)

Example 4 with RangerSecurityContext

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);
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 5 with RangerSecurityContext

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);
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Aggregations

RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)25 UserSessionBase (org.apache.ranger.common.UserSessionBase)24 XXPortalUser (org.apache.ranger.entity.XXPortalUser)8 Authentication (org.springframework.security.core.Authentication)4 HttpSession (javax.servlet.http.HttpSession)3 Before (org.junit.Before)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)2 XXUserDao (org.apache.ranger.db.XXUserDao)2 XXAuthSession (org.apache.ranger.entity.XXAuthSession)2 XXUser (org.apache.ranger.entity.XXUser)2 Test (org.junit.Test)2 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)2 SignedJWT (com.nimbusds.jwt.SignedJWT)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 PrePersist (javax.persistence.PrePersist)1