use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class JcrFeedEnableAccessControlTest method testDisableFeedAccessControl.
@Test
public void testDisableFeedAccessControl() {
when(this.accessController.isEntityAccessControlled()).thenReturn(true);
createFeeds();
metadata.commit(() -> {
JcrFeed feedB = (JcrFeed) this.feedProvider.getFeed(idB);
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feedB.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
JcrFeed feedC = (JcrFeed) this.feedProvider.getFeed(idC);
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feedC.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}, TEST_USER2);
int feedCnt1 = metadata.read(() -> this.feedProvider.getFeeds().size(), TEST_USER1);
assertThat(feedCnt1).isEqualTo(3);
int feedCnt2 = metadata.read(() -> this.feedProvider.getFeeds().size(), TEST_USER2);
assertThat(feedCnt2).isEqualTo(2);
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class JcrFeedEnableAccessControlTest method testEnableFeedAccessControl.
@Test
public void testEnableFeedAccessControl() {
when(this.accessController.isEntityAccessControlled()).thenReturn(false);
createFeeds();
metadata.commit(() -> {
JcrFeed feedA = (JcrFeed) this.feedProvider.getFeed(idA);
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feedA.enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), Collections.emptyList()));
}, TEST_USER1);
int feedCnt1 = metadata.read(() -> this.feedProvider.getFeeds().size(), TEST_USER1);
assertThat(feedCnt1).isEqualTo(3);
int feedCnt2 = metadata.read(() -> this.feedProvider.getFeeds().size(), TEST_USER2);
assertThat(feedCnt2).isEqualTo(2);
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class JcrProjectProvider method createProject.
/**
* Creates a new user with the specified name.
*
* @param name the name of the Project
* @param ensure {@code true} to return the Project if it already exists, or {@code false} to throw an exception
* @return the Project
* @throws MetadataRepositoryException if the user could not be created
*/
@Nonnull
private Project createProject(@Nonnull final String name, final boolean ensure) {
final Session session = getSession();
final String projPath = ProjectPaths.projectPath(name).toString();
logger.debug("workspace= {}", session.getWorkspace().getName());
try {
Node projNode = session.getRootNode().getNode(ProjectPaths.PROJECTS.toString());
if (session.getRootNode().hasNode(projPath)) {
if (ensure) {
return JcrUtil.getJcrObject(projNode, name, JcrProject.class);
} else {
// TODO specialize me..
throw new RuntimeException(projPath);
}
} else {
// project does not yet exist
JcrProject newProject = JcrUtil.getOrCreateNode(projNode, name, JcrProject.NODE_TYPE, JcrProject.class);
// grant (or deny) current user access to the project he is creating
if (this.accessController.isEntityAccessControlled()) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.PROJECT);
this.actionsProvider.getAvailableActions(AllowedActions.PROJECTS).ifPresent(actions -> newProject.enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
} else {
this.actionsProvider.getAvailableActions(AllowedActions.PROJECTS).ifPresent(actions -> newProject.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}
return newProject;
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed attempting to create a new Project with name: " + name, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class CheckEntityAccessControlAction method ensureTemplateAccessControl.
private void ensureTemplateAccessControl() {
List<FeedManagerTemplate> templates = feedManagerTemplateProvider.findAll();
if (templates != null) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.TEMPLATE);
Optional<AllowedActions> allowedActions = this.actionsProvider.getAvailableActions(AllowedActions.TEMPLATE);
templates.stream().forEach(template -> {
Principal owner = template.getOwner() != null ? template.getOwner() : JcrMetadataAccess.getActiveUser();
allowedActions.ifPresent(actions -> ((JcrFeedTemplate) template).enableAccessControl((JcrAllowedActions) actions, owner, roles));
});
}
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class EnsureServicesAccessControlAction method run.
@Override
public void run() {
log.info("Ensuring the Services prototype access control permissions are members of the actual Services access control node");
metadata.commit(() -> {
// find services entity node
Optional<AllowedActions> option = this.allowedEntityActionsProvider.getAllowedActions(AllowedActions.SERVICES);
Node servicesNode = ((JcrAllowedActions) option.get()).getNode();
JcrAllowedActions allowedAction = ((JcrAllowedActions) allowedEntityActionsProvider.getAvailableActions(AllowedActions.SERVICES).get());
allowedAction.copy(servicesNode, MetadataAccess.ADMIN, Privilege.JCR_ALL);
}, MetadataAccess.SERVICE);
}
Aggregations