Search in sources :

Example 56 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerServiceDefServiceBase 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 57 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerServiceService 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 58 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerServiceServiceBase 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 59 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerBizUtil method testGetXUserId_NoUser.

@Test
public void testGetXUserId_NoUser() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    XXPortalUser xxPortalUser = new XXPortalUser();
    xxPortalUser.setId(id);
    xxPortalUser.setLoginId("12121");
    context.getUserSession().setXXPortalUser(xxPortalUser);
    XXUser xxUser = new XXUser();
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
    Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPortalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Long chk = rangerBizUtil.getXUserId();
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertNull(chk);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) XXUserDao(org.apache.ranger.db.XXUserDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Example 60 with UserSessionBase

use of org.apache.ranger.common.UserSessionBase in project ranger by apache.

the class TestRangerBizUtil method testIsAdmin.

@Test
public void testIsAdmin() {
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    currentUserSession.setUserAdmin(true);
    boolean isAdminChk = rangerBizUtil.isAdmin();
    Assert.assertTrue(isAdminChk);
}
Also used : UserSessionBase(org.apache.ranger.common.UserSessionBase) Test(org.junit.Test)

Aggregations

UserSessionBase (org.apache.ranger.common.UserSessionBase)69 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)24 XXPortalUser (org.apache.ranger.entity.XXPortalUser)11 VXString (org.apache.ranger.view.VXString)11 XXUser (org.apache.ranger.entity.XXUser)8 ArrayList (java.util.ArrayList)6 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)6 XXService (org.apache.ranger.entity.XXService)5 VXResponse (org.apache.ranger.view.VXResponse)4 Test (org.junit.Test)4 Authentication (org.springframework.security.core.Authentication)4 HashSet (java.util.HashSet)3 HttpSession (javax.servlet.http.HttpSession)3 XXGroupUser (org.apache.ranger.entity.XXGroupUser)3 XXResource (org.apache.ranger.entity.XXResource)3 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2