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");
}
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");
}
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);
}
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;
}
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);
}
}
}
}
Aggregations