Search in sources :

Example 21 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.

the class TestUserMgr 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 22 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.

the class TestXUserMgr method setup.

public void setup() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(true);
    XXPortalUser gjUser = new XXPortalUser();
    gjUser.setLoginId("test");
    gjUser.setId(1L);
    currentUserSession.setXXPortalUser(gjUser);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 23 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.

the class TestPublicAPIsv2 method setup.

@Before
public void setup() throws Exception {
    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) Before(org.junit.Before)

Example 24 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.

the class TestServiceREST 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 25 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext in project ranger by apache.

the class JPABeanCallbacks method onPrePersist.

@PrePersist
void onPrePersist(Object o) {
    try {
        if (o != null && o instanceof XXDBBase) {
            XXDBBase entity = (XXDBBase) o;
            entity.setUpdateTime(DateUtil.getUTCDate());
            RangerSecurityContext context = RangerContextHolder.getSecurityContext();
            if (context != null) {
                UserSessionBase userSession = context.getUserSession();
                if (userSession != null) {
                    entity.setAddedByUserId(userSession.getUserId());
                    entity.setUpdatedByUserId(userSession.getUserId());
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Security context not found for this request. obj=" + o, new Throwable());
                }
            }
        }
    } catch (Throwable t) {
        logger.error(t);
    }
}
Also used : RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) XXDBBase(org.apache.ranger.entity.XXDBBase) UserSessionBase(org.apache.ranger.common.UserSessionBase) PrePersist(javax.persistence.PrePersist)

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