Search in sources :

Example 11 with VXGroup

use of org.apache.ranger.view.VXGroup in project ranger by apache.

the class TestXUserREST method test69deleteXGroupByGroupNameflase.

@Test
public void test69deleteXGroupByGroupNameflase() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    String TestforceDeleteStr = "true";
    boolean forceDelete = false;
    Mockito.when(request.getParameter("forceDelete")).thenReturn(TestforceDeleteStr);
    VXGroup testVXGroup = createVXGroup();
    Mockito.when(xGroupService.getGroupByGroupName(testVXGroup.getName())).thenReturn(testVXGroup);
    forceDelete = true;
    Mockito.doNothing().when(xUserMgr).deleteXGroup(testVXGroup.getId(), forceDelete);
    xUserRest.deleteXGroupByGroupName(testVXGroup.getName(), request);
    Mockito.verify(xUserMgr).deleteXGroup(testVXGroup.getId(), forceDelete);
    Mockito.verify(xGroupService).getGroupByGroupName(testVXGroup.getName());
    Mockito.verify(request).getParameter("forceDelete");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXString(org.apache.ranger.view.VXString) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 12 with VXGroup

use of org.apache.ranger.view.VXGroup in project ranger by apache.

the class TestXUserREST method test67deleteXGroupByGroupName.

@Test
public void test67deleteXGroupByGroupName() {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    String TestforceDeleteStr = "false";
    boolean forceDelete = true;
    Mockito.when(request.getParameter("forceDelete")).thenReturn(TestforceDeleteStr);
    VXGroup testVXGroup = createVXGroup();
    Mockito.when(xGroupService.getGroupByGroupName(testVXGroup.getName())).thenReturn(testVXGroup);
    forceDelete = false;
    Mockito.doNothing().when(xUserMgr).deleteXGroup(testVXGroup.getId(), forceDelete);
    xUserRest.deleteXGroupByGroupName(testVXGroup.getName(), request);
    Mockito.verify(xUserMgr).deleteXGroup(testVXGroup.getId(), forceDelete);
    Mockito.verify(xGroupService).getGroupByGroupName(testVXGroup.getName());
    Mockito.verify(request).getParameter("forceDelete");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VXString(org.apache.ranger.view.VXString) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 13 with VXGroup

use of org.apache.ranger.view.VXGroup in project ranger by apache.

the class TestXUserREST method test6secureUpdateXGroup.

@Test
public void test6secureUpdateXGroup() {
    VXGroup compareTestVXGroup = createVXGroup();
    Mockito.when(xUserMgr.updateXGroup(compareTestVXGroup)).thenReturn(compareTestVXGroup);
    VXGroup retVxGroup = xUserRest.secureUpdateXGroup(compareTestVXGroup);
    assertNotNull(retVxGroup);
    assertEquals(compareTestVXGroup.getId(), retVxGroup.getId());
    assertEquals(compareTestVXGroup.getName(), retVxGroup.getName());
    Mockito.verify(xUserMgr).updateXGroup(compareTestVXGroup);
}
Also used : VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 14 with VXGroup

use of org.apache.ranger.view.VXGroup in project ranger by apache.

the class TestXUserREST method createxGroupList.

private VXGroupList createxGroupList() {
    VXGroupList testVXGroupList = new VXGroupList();
    VXGroup VXGroup1 = createVXGroup();
    List<VXGroup> vXGroups = new ArrayList<VXGroup>();
    vXGroups.add(VXGroup1);
    testVXGroupList.setVXGroups(vXGroups);
    testVXGroupList.setStartIndex(0);
    testVXGroupList.setTotalCount(1);
    return testVXGroupList;
}
Also used : VXGroupList(org.apache.ranger.view.VXGroupList) ArrayList(java.util.ArrayList) VXGroup(org.apache.ranger.view.VXGroup)

Example 15 with VXGroup

use of org.apache.ranger.view.VXGroup in project ranger by apache.

the class ServiceDBStore method createDefaultPolicyUsersAndGroups.

void createDefaultPolicyUsersAndGroups(List<RangerPolicy> defaultPolicies) {
    Set<String> defaultPolicyUsers = new HashSet<String>();
    Set<String> defaultPolicyGroups = new HashSet<String>();
    for (RangerPolicy defaultPolicy : defaultPolicies) {
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getAllowExceptions()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDenyPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDenyExceptions()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getDataMaskPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
        for (RangerPolicyItem defaultPolicyItem : defaultPolicy.getRowFilterPolicyItems()) {
            defaultPolicyUsers.addAll(defaultPolicyItem.getUsers());
            defaultPolicyGroups.addAll(defaultPolicyItem.getGroups());
        }
    }
    for (String policyUser : defaultPolicyUsers) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Checking policyUser:[" + policyUser + "] for existence");
        }
        if (StringUtils.isNotBlank(policyUser) && !StringUtils.equals(policyUser, RangerPolicyEngine.USER_CURRENT) && !StringUtils.equals(policyUser, RangerPolicyEngine.RESOURCE_OWNER)) {
            XXUser xxUser = daoMgr.getXXUser().findByUserName(policyUser);
            if (xxUser == null) {
                UserSessionBase usb = ContextUtil.getCurrentUserSession();
                if (usb != null && !usb.isKeyAdmin() && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
                    throw restErrorUtil.createRESTException("User does not exist with given username: [" + policyUser + "] please use existing user", MessageEnums.OPER_NO_PERMISSION);
                }
                xUserMgr.createServiceConfigUser(policyUser);
            }
        }
    }
    for (String policyGroup : defaultPolicyGroups) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Checking policyGroup:[" + policyGroup + "] for existence");
        }
        if (StringUtils.isNotBlank(policyGroup)) {
            XXGroup xxGroup = daoMgr.getXXGroup().findByGroupName(policyGroup);
            if (xxGroup == null) {
                UserSessionBase usb = ContextUtil.getCurrentUserSession();
                if (usb != null && !usb.isKeyAdmin() && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
                    throw restErrorUtil.createRESTException("Group does not exist with given groupname: [" + policyGroup + "] please use existing group", MessageEnums.OPER_NO_PERMISSION);
                }
                VXGroup vXGroup = new VXGroup();
                vXGroup.setName(policyGroup);
                vXGroup.setDescription(policyGroup);
                vXGroup.setGroupSource(RangerCommonEnums.GROUP_INTERNAL);
                vXGroup.setIsVisible(RangerCommonEnums.IS_VISIBLE);
                xGroupService.createResource(vXGroup);
            }
        }
    }
}
Also used : XXUser(org.apache.ranger.entity.XXUser) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXGroup(org.apache.ranger.entity.XXGroup) VXString(org.apache.ranger.view.VXString) RangerPolicyItem(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem) VXGroup(org.apache.ranger.view.VXGroup) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Aggregations

VXGroup (org.apache.ranger.view.VXGroup)32 Test (org.junit.Test)26 VXString (org.apache.ranger.view.VXString)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 XXGroup (org.apache.ranger.entity.XXGroup)7 ArrayList (java.util.ArrayList)5 XXGroupDao (org.apache.ranger.db.XXGroupDao)5 VXStringList (org.apache.ranger.view.VXStringList)4 HashMap (java.util.HashMap)3 VXGroupUser (org.apache.ranger.view.VXGroupUser)3 VXUser (org.apache.ranger.view.VXUser)3 XXGroupUserDao (org.apache.ranger.db.XXGroupUserDao)2 VXGroupList (org.apache.ranger.view.VXGroupList)2 VXGroupUserList (org.apache.ranger.view.VXGroupUserList)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXAuditMapDao (org.apache.ranger.db.XXAuditMapDao)1