use of com.thinkbiganalytics.security.UsernamePrincipal 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;
});
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class JcrUserProviderTest method testUserGetPrincipals.
@Test(dependsOnMethods = "testAddUsersMembers")
public void testUserGetPrincipals() {
metadata.read(() -> {
User user1 = this.provider.findUserBySystemName("user1").get();
User user2 = this.provider.findUserBySystemName("user2").get();
User user3 = this.provider.findUserBySystemName("user3").get();
assertThat(user1.getPrincipal()).isEqualTo(new UsernamePrincipal("user1"));
assertThat(user2.getPrincipal()).isEqualTo(new UsernamePrincipal("user2"));
assertThat(user3.getPrincipal()).isEqualTo(new UsernamePrincipal("user3"));
});
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class JcrProjectProvider method getMyEditableProjects.
@Override
public List<Project> getMyEditableProjects() {
UsernamePrincipal user = JcrMetadataAccess.getActiveUser();
logger.debug("user={}", user);
List<Project> projects = getProjects();
return projects.stream().filter(prj -> {
try {
prj.getAllowedActions().checkPermission(ProjectAccessControl.EDIT_PROJECT);
return true;
} catch (AccessControlException ace) {
return false;
}
}).collect(Collectors.toList());
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class JcrActionsGroupBuilder method build.
/* (non-Javadoc)
* @see com.thinkbiganalytics.security.action.config.ActionsModuleBuilder#build()
*/
@Override
public AllowedActions build() {
try {
Session session = this.protoActionsNode.getSession();
JcrAccessControlUtil.addPermissions(this.protoActionsNode, this.managementPrincipal, Privilege.JCR_ALL);
JcrAccessControlUtil.addPermissions(this.protoActionsNode, new UsernamePrincipal(session.getUserID()), Privilege.JCR_ALL);
JcrAccessControlUtil.addPermissions(this.protoActionsNode, SimplePrincipal.EVERYONE, Privilege.JCR_READ);
JcrAllowedActions protoAllowed = new JcrAllowedActions(this.protoActionsNode);
return protoAllowed;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to build action", e);
}
}
use of com.thinkbiganalytics.security.UsernamePrincipal in project kylo by Teradata.
the class JcrDatasourceProvider method ensureDatasourceDetails.
@Override
public <D extends DatasourceDetails> Optional<D> ensureDatasourceDetails(@Nonnull final Datasource.ID id, @Nonnull final Class<D> type) {
try {
// Ensure the data source exists
final Optional<JcrUserDatasource> parent = Optional.ofNullable(getDatasource(id)).filter(JcrUserDatasource.class::isInstance).map(JcrUserDatasource.class::cast);
if (!parent.isPresent()) {
return Optional.empty();
}
// Create the details
final Class<? extends JcrDatasourceDetails> implType = JcrUserDatasource.resolveDetailsClass(type);
final boolean isNew = !hasEntityNode(parent.get().getPath(), JcrUserDatasource.DETAILS);
final Node node = findOrCreateEntityNode(parent.get().getPath(), JcrUserDatasource.DETAILS, implType);
@SuppressWarnings("unchecked") final D details = (D) JcrUtil.createJcrObject(node, implType);
// Re-assign permissions to data source
if (isNew) {
final UsernamePrincipal owner = parent.map(JcrUserDatasource::getOwner).map(Principal::getName).map(UsernamePrincipal::new).orElse(JcrMetadataAccess.getActiveUser());
if (accessController.isEntityAccessControlled()) {
final List<SecurityRole> roles = roleProvider.getEntityRoles(SecurityRole.DATASOURCE);
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> parent.get().enableAccessControl((JcrAllowedActions) actions, owner, roles));
} else {
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> parent.get().disableAccessControl((JcrAllowedActions) actions, owner));
}
}
return Optional.of(details);
} catch (final IllegalArgumentException e) {
throw new MetadataException("Unable to create datasource details: " + type, e);
}
}
Aggregations