Search in sources :

Example 1 with JpaFeedOpsAclEntry

use of com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry in project kylo by Teradata.

the class FeedHealthRepositoryTest method findAll_WithMatchingGroupAclEntry.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin", "user" })
@Test
public void findAll_WithMatchingGroupAclEntry() throws Exception {
    UUID uuid = UUID.randomUUID();
    JpaOpsManagerFeedHealth health = new JpaOpsManagerFeedHealth();
    health.setFeedId(new JpaOpsManagerFeedHealth.OpsManagerFeedHealthFeedId(uuid));
    repo.save(health);
    BaseFeed.FeedId healthId = new BaseFeed.FeedId(uuid);
    JpaFeedOpsAclEntry nonMatching = new JpaFeedOpsAclEntry(healthId, "admin", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(nonMatching);
    Iterable<JpaOpsManagerFeedHealth> all = repo.findAll();
    Assert.assertTrue(StreamSupport.stream(all.spliterator(), false).anyMatch(it -> it.getFeedId().getUuid().equals(uuid)));
}
Also used : FeedOpsAccessControlRepository(com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlRepository) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) TestPropertySource(org.springframework.test.context.TestPropertySource) UUID(java.util.UUID) TestJpaConfiguration(com.thinkbiganalytics.metadata.jpa.TestJpaConfiguration) FeedOpsAccessControlConfig(com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlConfig) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser) Configuration(org.springframework.context.annotation.Configuration) Inject(javax.inject.Inject) Mockito(org.mockito.Mockito) OperationalMetadataConfig(com.thinkbiganalytics.metadata.config.OperationalMetadataConfig) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) SpringApplicationConfiguration(org.springframework.boot.test.SpringApplicationConfiguration) AccessController(com.thinkbiganalytics.security.AccessController) CommonsSpringConfiguration(com.thinkbiganalytics.spring.CommonsSpringConfiguration) StreamSupport(java.util.stream.StreamSupport) Bean(org.springframework.context.annotation.Bean) Assert(org.junit.Assert) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) Transactional(org.springframework.transaction.annotation.Transactional) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) UUID(java.util.UUID) Test(org.junit.Test) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Example 2 with JpaFeedOpsAclEntry

use of com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry in project kylo by Teradata.

the class JpaFeedProviderTest method testFindFeedUsingGenericFilter.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin" })
@Test
public void testFindFeedUsingGenericFilter() {
    // Create feed
    final String name = "testCategory.testFeed";
    final String id = metadataAccess.commit(() -> {
        final OpsManagerFeed.ID feedId = feedProvider.resolveId(UUID.randomUUID().toString());
        feedProvider.save(feedId, name, false, 1000L);
        return feedId.toString();
    });
    // Add ACL entries
    final BaseFeed.FeedId feedId = new BaseFeed.FeedId(id);
    final JpaFeedOpsAclEntry userAcl = new JpaFeedOpsAclEntry(feedId, "dladmin", JpaFeedOpsAclEntry.PrincipalType.USER);
    final JpaFeedOpsAclEntry adminAcl = new JpaFeedOpsAclEntry(feedId, "admin", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclProvider.grantAccess(feedId, new UsernamePrincipal("dladmin"), new GroupPrincipal("admin"));
    // Verify access to feeds
    metadataAccess.read(() -> {
        List<OpsManagerFeed> feeds = feedProvider.findAll("name:" + name);
        Assert.assertTrue(feeds != null && !feeds.isEmpty());
        List<String> feedNames = feedProvider.getFeedNames();
        Assert.assertTrue(feedNames != null && !feedNames.isEmpty());
        return feeds;
    });
}
Also used : UsernamePrincipal(com.thinkbiganalytics.security.UsernamePrincipal) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) GroupPrincipal(com.thinkbiganalytics.security.GroupPrincipal) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) Test(org.junit.Test) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Example 3 with JpaFeedOpsAclEntry

use of com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry in project kylo by Teradata.

the class OpsManagerFeedRepositoryTest method findAll_NoMatchingGroupMatchingUserAclEntry.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin", "user" })
@Test
public void findAll_NoMatchingGroupMatchingUserAclEntry() throws Exception {
    JpaOpsManagerFeed feed = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed-name");
    repo.save(feed);
    BaseFeed.FeedId feedId = new BaseFeed.FeedId(feed.getId().getUuid());
    JpaFeedOpsAclEntry dladminUserAcl = new JpaFeedOpsAclEntry(feedId, "dladmin", JpaFeedOpsAclEntry.PrincipalType.USER);
    aclRepo.save(dladminUserAcl);
    JpaFeedOpsAclEntry nonMatching = new JpaFeedOpsAclEntry(feedId, "NON_MATCHING", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(nonMatching);
    Iterable<JpaOpsManagerFeed> all = repo.findAll();
    Assert.assertTrue(StreamSupport.stream(all.spliterator(), false).allMatch(it -> it.getName().equals("feed-name")));
}
Also used : FeedOpsAccessControlRepository(com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) FeedOpsAccessControlConfig(com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlConfig) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) GenericQueryDslFilter(com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) AccessController(com.thinkbiganalytics.security.AccessController) CommonsSpringConfiguration(com.thinkbiganalytics.spring.CommonsSpringConfiguration) Pageable(org.springframework.data.domain.Pageable) StreamSupport(java.util.stream.StreamSupport) PageRequest(org.springframework.data.domain.PageRequest) Test(org.junit.Test) TestPropertySource(org.springframework.test.context.TestPropertySource) Page(org.springframework.data.domain.Page) TestJpaConfiguration(com.thinkbiganalytics.metadata.jpa.TestJpaConfiguration) Configuration(org.springframework.context.annotation.Configuration) Mockito(org.mockito.Mockito) OperationalMetadataConfig(com.thinkbiganalytics.metadata.config.OperationalMetadataConfig) List(java.util.List) SpringApplicationConfiguration(org.springframework.boot.test.SpringApplicationConfiguration) Bean(org.springframework.context.annotation.Bean) Assert(org.junit.Assert) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) Transactional(org.springframework.transaction.annotation.Transactional) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) Test(org.junit.Test) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Example 4 with JpaFeedOpsAclEntry

use of com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry in project kylo by Teradata.

the class OpsManagerFeedRepositoryTest method findAll_NoMatchingGroupAclEntry.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin", "user" })
@Test
public void findAll_NoMatchingGroupAclEntry() throws Exception {
    JpaOpsManagerFeed feed = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed-name");
    repo.save(feed);
    BaseFeed.FeedId feedId = new BaseFeed.FeedId(feed.getId().getUuid());
    JpaFeedOpsAclEntry nonMatching = new JpaFeedOpsAclEntry(feedId, "NON_MATCHING", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(nonMatching);
    Iterable<JpaOpsManagerFeed> all = repo.findAll();
    Assert.assertFalse(StreamSupport.stream(all.spliterator(), false).anyMatch(it -> it.getName().equals("feed-name")));
}
Also used : FeedOpsAccessControlRepository(com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) FeedOpsAccessControlConfig(com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlConfig) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) GenericQueryDslFilter(com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) AccessController(com.thinkbiganalytics.security.AccessController) CommonsSpringConfiguration(com.thinkbiganalytics.spring.CommonsSpringConfiguration) Pageable(org.springframework.data.domain.Pageable) StreamSupport(java.util.stream.StreamSupport) PageRequest(org.springframework.data.domain.PageRequest) Test(org.junit.Test) TestPropertySource(org.springframework.test.context.TestPropertySource) Page(org.springframework.data.domain.Page) TestJpaConfiguration(com.thinkbiganalytics.metadata.jpa.TestJpaConfiguration) Configuration(org.springframework.context.annotation.Configuration) Mockito(org.mockito.Mockito) OperationalMetadataConfig(com.thinkbiganalytics.metadata.config.OperationalMetadataConfig) List(java.util.List) SpringApplicationConfiguration(org.springframework.boot.test.SpringApplicationConfiguration) Bean(org.springframework.context.annotation.Bean) Assert(org.junit.Assert) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) Transactional(org.springframework.transaction.annotation.Transactional) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) Test(org.junit.Test) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Example 5 with JpaFeedOpsAclEntry

use of com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry in project kylo by Teradata.

the class OpsManagerFeedRepositoryTest method findAll_TwoPages.

@WithMockJaasUser(username = "dladmin", password = "secret", authorities = { "admin", "user" })
@Test
public void findAll_TwoPages() throws Exception {
    JpaOpsManagerFeed feed1 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed1-name");
    repo.save(feed1);
    BaseFeed.FeedId feed1Id = new BaseFeed.FeedId(feed1.getId().getUuid());
    JpaFeedOpsAclEntry acl1 = new JpaFeedOpsAclEntry(feed1Id, "admin", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl1);
    JpaOpsManagerFeed feed2 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed2-name");
    repo.save(feed2);
    BaseFeed.FeedId feed2Id = new BaseFeed.FeedId(feed2.getId().getUuid());
    JpaFeedOpsAclEntry acl2 = new JpaFeedOpsAclEntry(feed2Id, "user", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl2);
    JpaOpsManagerFeed feed3 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed3-name");
    repo.save(feed3);
    BaseFeed.FeedId feed3Id = new BaseFeed.FeedId(feed3.getId().getUuid());
    JpaFeedOpsAclEntry acl3 = new JpaFeedOpsAclEntry(feed3Id, "NON_MATCHING", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl3);
    JpaOpsManagerFeed feed4 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed4-name");
    repo.save(feed4);
    BaseFeed.FeedId feed4Id = new BaseFeed.FeedId(feed4.getId().getUuid());
    JpaFeedOpsAclEntry acl4 = new JpaFeedOpsAclEntry(feed4Id, "user", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl4);
    JpaOpsManagerFeed feed5 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed5-name");
    repo.save(feed5);
    BaseFeed.FeedId feed5Id = new BaseFeed.FeedId(feed5.getId().getUuid());
    JpaFeedOpsAclEntry acl5 = new JpaFeedOpsAclEntry(feed5Id, "NON_MATCHING", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl5);
    JpaOpsManagerFeed feed6 = new JpaOpsManagerFeed(OpsManagerFeedId.create(), "feed6-name");
    repo.save(feed6);
    BaseFeed.FeedId feed6Id = new BaseFeed.FeedId(feed6.getId().getUuid());
    JpaFeedOpsAclEntry acl6 = new JpaFeedOpsAclEntry(feed6Id, "user", JpaFeedOpsAclEntry.PrincipalType.GROUP);
    aclRepo.save(acl6);
    Pageable page1Request = new PageRequest(0, 2);
    Page<JpaOpsManagerFeed> page1 = repo.findAll(page1Request);
    Assert.assertEquals(0, page1.getNumber());
    Assert.assertEquals(2, page1.getNumberOfElements());
    Assert.assertEquals(2, page1.getTotalPages());
    Assert.assertEquals(4, page1.getTotalElements());
    Pageable page2Request = new PageRequest(1, 2);
    Page<JpaOpsManagerFeed> page2 = repo.findAll(page2Request);
    Assert.assertEquals(1, page2.getNumber());
    Assert.assertEquals(2, page2.getNumberOfElements());
    Assert.assertEquals(2, page2.getTotalPages());
    Assert.assertEquals(4, page2.getTotalElements());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) BaseFeed(com.thinkbiganalytics.metadata.core.feed.BaseFeed) JpaFeedOpsAclEntry(com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry) Test(org.junit.Test) WithMockJaasUser(com.thinkbiganalytics.test.security.WithMockJaasUser)

Aggregations

JpaFeedOpsAclEntry (com.thinkbiganalytics.metadata.jpa.feed.security.JpaFeedOpsAclEntry)20 BaseFeed (com.thinkbiganalytics.metadata.core.feed.BaseFeed)19 WithMockJaasUser (com.thinkbiganalytics.test.security.WithMockJaasUser)19 Test (org.junit.Test)19 OperationalMetadataConfig (com.thinkbiganalytics.metadata.config.OperationalMetadataConfig)10 TestJpaConfiguration (com.thinkbiganalytics.metadata.jpa.TestJpaConfiguration)10 FeedOpsAccessControlConfig (com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlConfig)10 FeedOpsAccessControlRepository (com.thinkbiganalytics.metadata.jpa.feed.security.FeedOpsAccessControlRepository)10 AccessController (com.thinkbiganalytics.security.AccessController)10 CommonsSpringConfiguration (com.thinkbiganalytics.spring.CommonsSpringConfiguration)10 StreamSupport (java.util.stream.StreamSupport)10 Assert (org.junit.Assert)10 RunWith (org.junit.runner.RunWith)10 Mockito (org.mockito.Mockito)10 SpringApplicationConfiguration (org.springframework.boot.test.SpringApplicationConfiguration)10 Bean (org.springframework.context.annotation.Bean)10 Configuration (org.springframework.context.annotation.Configuration)10 TestPropertySource (org.springframework.test.context.TestPropertySource)10 SpringJUnit4ClassRunner (org.springframework.test.context.junit4.SpringJUnit4ClassRunner)10 Transactional (org.springframework.transaction.annotation.Transactional)10