use of org.pentaho.di.repository.ObjectRecipient in project pentaho-kettle by pentaho.
the class UIEEJobTest method testAcls.
@Test
public void testAcls() throws Exception {
final String owner = "owner";
final String role = "role";
ObjectRecipient mockObjectRecipient = mock(ObjectRecipient.class);
when(mockObjectRecipient.getName()).thenReturn(owner);
ObjectAcl mockAcl = mock(ObjectAcl.class);
when(mockAcl.getOwner()).thenReturn(mockObjectRecipient);
when(mockAclService.getAcl(mockObjectId, false)).thenReturn(mockAcl);
uiJob.clearAcl();
UIRepositoryObjectAcls acls = new UIRepositoryObjectAcls();
uiJob.getAcls(acls);
verify(mockAclService).getAcl(mockObjectId, false);
assertEquals(owner, acls.getOwner().getName());
acls = new UIRepositoryObjectAcls();
RepositoryObjectAcl repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE));
acls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE)));
uiJob.setAcls(acls);
verify(mockAclService).setAcl(mockObjectId, repObjectAcl);
when(mockAclService.getAcl(mockObjectId, false)).thenThrow(new KettleException(""));
uiJob.clearAcl();
try {
uiJob.getAcls(acls);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
doThrow(new KettleException("")).when(mockAclService).setAcl(any(ObjectId.class), any(RepositoryObjectAcl.class));
try {
uiJob.setAcls(acls);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
}
use of org.pentaho.di.repository.ObjectRecipient in project pentaho-kettle by pentaho.
the class UIEETransformationTest method testAcls.
@Test
public void testAcls() throws Exception {
final String owner = "owner";
final String role = "role";
ObjectRecipient mockObjectRecipient = mock(ObjectRecipient.class);
when(mockObjectRecipient.getName()).thenReturn(owner);
ObjectAcl mockAcl = mock(ObjectAcl.class);
when(mockAcl.getOwner()).thenReturn(mockObjectRecipient);
when(mockAclService.getAcl(mockObjectId, false)).thenReturn(mockAcl);
uiTransformation.clearAcl();
UIRepositoryObjectAcls acls = new UIRepositoryObjectAcls();
uiTransformation.getAcls(acls);
verify(mockAclService).getAcl(mockObjectId, false);
assertEquals(owner, acls.getOwner().getName());
acls = new UIRepositoryObjectAcls();
RepositoryObjectAcl repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE));
acls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE)));
uiTransformation.setAcls(acls);
verify(mockAclService).setAcl(mockObjectId, repObjectAcl);
when(mockAclService.getAcl(mockObjectId, false)).thenThrow(new KettleException(""));
uiTransformation.clearAcl();
try {
uiTransformation.getAcls(acls);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
doThrow(new KettleException("")).when(mockAclService).setAcl(any(ObjectId.class), any(RepositoryObjectAcl.class));
try {
uiTransformation.setAcls(acls);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
}
use of org.pentaho.di.repository.ObjectRecipient in project pentaho-kettle by pentaho.
the class UIEERepositoryDirectoryTest method testAcls.
@Test
public void testAcls() throws Exception {
final String owner = "owner";
final String role = "role";
ObjectRecipient mockObjectRecipient = mock(ObjectRecipient.class);
when(mockObjectRecipient.getName()).thenReturn(owner);
ObjectAcl mockAcl = mock(ObjectAcl.class);
when(mockAcl.getOwner()).thenReturn(mockObjectRecipient);
when(mockAclService.getAcl(mockObjectId, false)).thenReturn(mockAcl);
uiRepDir.clearAcl();
UIRepositoryObjectAcls acls = new UIRepositoryObjectAcls();
uiRepDir.getAcls(acls);
verify(mockAclService, times(1)).getAcl(mockObjectId, false);
assertEquals(owner, acls.getOwner().getName());
acls = new UIRepositoryObjectAcls();
uiRepDir.getAcls(acls, false);
verify(mockAclService, times(2)).getAcl(mockObjectId, false);
assertEquals(owner, acls.getOwner().getName());
acls = new UIRepositoryObjectAcls();
RepositoryObjectAcl repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE));
acls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(role, Type.ROLE)));
uiRepDir.setAcls(acls);
verify(mockAclService).setAcl(mockObjectId, repObjectAcl);
when(mockAclService.getAcl(mockObjectId, false)).thenThrow(new KettleException(""));
uiRepDir.clearAcl();
try {
uiRepDir.getAcls(acls);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
when(mockAclService.getAcl(mockObjectId, true)).thenThrow(new KettleException(""));
uiRepDir.clearAcl();
try {
uiRepDir.getAcls(acls, true);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
doThrow(new KettleException("")).when(mockAclService).setAcl(any(ObjectId.class), any(ObjectAcl.class));
uiRepDir.clearAcl();
try {
uiRepDir.setAcls(acls);
fail("Expected an exception");
} catch (AccessDeniedException e) {
// Test Succeeded if here
}
}
use of org.pentaho.di.repository.ObjectRecipient in project pentaho-kettle by pentaho.
the class UIRepositoryObjectAclModelTest method createRoleAce.
private ObjectAce createRoleAce(String recipientName) {
ObjectRecipient objectRecipient = new RepositoryObjectRecipient(recipientName, ObjectRecipient.Type.ROLE);
ObjectAce objectAce = new RepositoryObjectAce(objectRecipient, EnumSet.of(RepositoryFilePermission.READ, RepositoryFilePermission.WRITE));
return objectAce;
}
use of org.pentaho.di.repository.ObjectRecipient in project pentaho-kettle by pentaho.
the class UnifiedRepositoryConnectionAclService method setAcl.
@Override
public void setAcl(ObjectId fileId, ObjectAcl objectAcl) throws KettleException {
try {
RepositoryFileAcl acl = pur.getAcl(fileId.getId());
RepositoryFileAcl.Builder newAclBuilder = new RepositoryFileAcl.Builder(acl).entriesInheriting(objectAcl.isEntriesInheriting()).clearAces();
if (!objectAcl.isEntriesInheriting()) {
List<ObjectAce> aces = objectAcl.getAces();
for (ObjectAce objectAce : aces) {
EnumSet<RepositoryFilePermission> permissions = objectAce.getPermissions();
EnumSet<RepositoryFilePermission> permissionSet = EnumSet.noneOf(RepositoryFilePermission.class);
ObjectRecipient recipient = objectAce.getRecipient();
RepositoryFileSid sid;
if (recipient.getType().equals(Type.ROLE)) {
sid = new RepositoryFileSid(recipient.getName(), RepositoryFileSid.Type.ROLE);
} else {
sid = new RepositoryFileSid(recipient.getName());
}
if (permissions != null) {
permissionSet.addAll(permissions);
}
newAclBuilder.ace(sid, permissionSet);
}
}
pur.updateAcl(newAclBuilder.build());
} catch (Exception drfe) {
// The user does not have rights to view or set the acl information.
throw new KettleException(drfe);
}
}
Aggregations