Search in sources :

Example 16 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext 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 17 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext 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 18 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext 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 19 with RangerSecurityContext

use of org.apache.ranger.security.context.RangerSecurityContext 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 20 with RangerSecurityContext

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

the class TestRangerBizUtil method testGetXUserId.

@Test
public void testGetXUserId() {
    XXPortalUser xxPortalUser = new XXPortalUser();
    xxPortalUser.setId(id);
    xxPortalUser.setLoginId("12121");
    XXUser xxUser = new XXUser();
    xxUser.setId(id);
    XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    RangerSecurityContext context = new RangerSecurityContext();
    UserSessionBase userSessionBase = new UserSessionBase();
    userSessionBase.setUserAdmin(true);
    context.setUserSession(userSessionBase);
    userSessionBase.setXXPortalUser(xxPortalUser);
    RangerContextHolder.setSecurityContext(context);
    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.assertEquals(chk, id);
}
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)

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