Search in sources :

Example 1 with RepositoryObjectAcl

use of org.pentaho.di.repository.pur.model.RepositoryObjectAcl 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
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Test(org.junit.Test)

Example 2 with RepositoryObjectAcl

use of org.pentaho.di.repository.pur.model.RepositoryObjectAcl 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
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Test(org.junit.Test)

Example 3 with RepositoryObjectAcl

use of org.pentaho.di.repository.pur.model.RepositoryObjectAcl 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
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ObjectId(org.pentaho.di.repository.ObjectId) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Test(org.junit.Test)

Example 4 with RepositoryObjectAcl

use of org.pentaho.di.repository.pur.model.RepositoryObjectAcl in project pentaho-kettle by pentaho.

the class UIRepositoryObjectAclModelTest method beforeTest.

@Before
public void beforeTest() {
    repositoryObjectAcls = new UIRepositoryObjectAcls();
    repObjectAcl = new RepositoryObjectAcl(new RepositoryObjectRecipient(RECIPIENT0, Type.ROLE));
    repositoryObjectAcls.setObjectAcl(new RepositoryObjectAcl(new RepositoryObjectRecipient(RECIPIENT0, Type.ROLE)));
    userAcl1 = new UIRepositoryObjectAcl(createUserAce(RECIPIENT1));
    userAcl2 = new UIRepositoryObjectAcl(createUserAce(RECIPIENT2));
    userAcl3 = new UIRepositoryObjectAcl(createUserAce(RECIPIENT3));
    repositoryObjectAclModel = new UIRepositoryObjectAclModel(repositoryObjectAcls);
    roleAcl1 = new UIRepositoryObjectAcl(createRoleAce(ROLE1));
    roleAcl2 = new UIRepositoryObjectAcl(createRoleAce(ROLE2));
    roleAcl3 = new UIRepositoryObjectAcl(createRoleAce(ROLE3));
    defaultUserNameList = Arrays.asList(new String[] { USER1, USER2, USER3 });
    defaultRoleNameList = Arrays.asList(new String[] { ROLE1, ROLE2, ROLE3 });
}
Also used : RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) Before(org.junit.Before)

Example 5 with RepositoryObjectAcl

use of org.pentaho.di.repository.pur.model.RepositoryObjectAcl in project pentaho-kettle by pentaho.

the class UnifiedRepositoryConnectionAclService method getAcl.

@Override
public ObjectAcl getAcl(ObjectId fileId, boolean forceParentInheriting) throws KettleException {
    RepositoryFileAcl acl = null;
    try {
        acl = pur.getAcl(fileId.getId());
    } catch (Exception drfe) {
        // The user does not have rights to view the acl information.
        throw new KettleException(drfe);
    }
    RepositoryFileSid sid = acl.getOwner();
    ObjectRecipient owner = new RepositoryObjectRecipient(sid.getName());
    if (sid.getType().equals(RepositoryFileSid.Type.USER)) {
        owner.setType(Type.USER);
    } else {
        owner.setType(Type.ROLE);
    }
    ObjectAcl objectAcl = new RepositoryObjectAcl(owner);
    List<RepositoryFileAce> aces;
    if (forceParentInheriting) {
        objectAcl.setEntriesInheriting(true);
        aces = pur.getEffectiveAces(acl.getId(), true);
    } else {
        objectAcl.setEntriesInheriting(acl.isEntriesInheriting());
        aces = (acl.isEntriesInheriting()) ? pur.getEffectiveAces(acl.getId()) : acl.getAces();
    }
    List<ObjectAce> objectAces = new ArrayList<ObjectAce>();
    for (RepositoryFileAce ace : aces) {
        EnumSet<RepositoryFilePermission> permissions = ace.getPermissions();
        EnumSet<RepositoryFilePermission> permissionSet = EnumSet.noneOf(RepositoryFilePermission.class);
        RepositoryFileSid aceSid = ace.getSid();
        ObjectRecipient recipient = new RepositoryObjectRecipient(aceSid.getName());
        if (aceSid.getType().equals(RepositoryFileSid.Type.USER)) {
            recipient.setType(Type.USER);
        } else {
            recipient.setType(Type.ROLE);
        }
        permissionSet.addAll(permissions);
        objectAces.add(new RepositoryObjectAce(recipient, permissionSet));
    }
    objectAcl.setAces(objectAces);
    return objectAcl;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) ObjectAcl(org.pentaho.di.repository.pur.model.ObjectAcl) RepositoryFileAce(org.pentaho.platform.api.repository2.unified.RepositoryFileAce) ObjectRecipient(org.pentaho.di.repository.ObjectRecipient) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) ArrayList(java.util.ArrayList) ObjectAce(org.pentaho.di.repository.pur.model.ObjectAce) RepositoryObjectAce(org.pentaho.di.repository.pur.model.RepositoryObjectAce) RepositoryObjectAce(org.pentaho.di.repository.pur.model.RepositoryObjectAce) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryObjectAcl(org.pentaho.di.repository.pur.model.RepositoryObjectAcl) RepositoryObjectRecipient(org.pentaho.di.repository.pur.model.RepositoryObjectRecipient) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

RepositoryObjectAcl (org.pentaho.di.repository.pur.model.RepositoryObjectAcl)7 RepositoryObjectRecipient (org.pentaho.di.repository.pur.model.RepositoryObjectRecipient)7 Test (org.junit.Test)4 KettleException (org.pentaho.di.core.exception.KettleException)4 ObjectRecipient (org.pentaho.di.repository.ObjectRecipient)4 ObjectAcl (org.pentaho.di.repository.pur.model.ObjectAcl)4 ObjectId (org.pentaho.di.repository.ObjectId)3 AccessDeniedException (org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException)3 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 ObjectAce (org.pentaho.di.repository.pur.model.ObjectAce)1 RepositoryObjectAce (org.pentaho.di.repository.pur.model.RepositoryObjectAce)1 RepositoryFileAce (org.pentaho.platform.api.repository2.unified.RepositoryFileAce)1 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)1 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)1 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)1