use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class AccessControlledMixin method disableAccessControl.
default void disableAccessControl(JcrAllowedActions prototype, Principal owner, List<SecurityRole> roles) {
JcrAllowedActions allowed = getJcrAllowedActions();
prototype.copy(allowed.getNode(), owner);
allowed.removeAccessControl(owner);
if (roles.isEmpty()) {
JcrEntityRoleMembership.removeAll(getNode());
} else {
roles.forEach(role -> JcrEntityRoleMembership.remove(getNode(), ((JcrSecurityRole) role).getNode(), JcrEntityRoleMembership.class));
}
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions 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);
}
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class JcrDatasourceProvider method createImpl.
private <J extends JcrDatasource> J createImpl(String name, String descr, Class<? extends Datasource> type) {
try {
JcrTool tool = new JcrTool();
Class<J> implType = deriveImplType(type);
Field folderField = FieldUtils.getField(implType, "PATH_NAME", true);
String subfolderName = (String) folderField.get(null);
String dsPath = EntityUtil.pathForDataSource();
Node dsNode = getSession().getNode(dsPath);
Node subfolderNode = tool.findOrCreateChild(dsNode, subfolderName, "nt:folder");
Map<String, Object> props = new HashMap<>();
props.put(JcrDatasource.SYSTEM_NAME, name);
String encodedName = org.modeshape.jcr.value.Path.DEFAULT_ENCODER.encode(name);
final boolean isNew = !hasEntityNode(subfolderNode.getPath(), encodedName);
@SuppressWarnings("unchecked") J datasource = (J) findOrCreateEntity(subfolderNode.getPath(), encodedName, implType, props);
if (isNew && JcrUserDatasource.class.isAssignableFrom(type)) {
if (this.accessController.isEntityAccessControlled()) {
final List<SecurityRole> roles = roleProvider.getEntityRoles(SecurityRole.DATASOURCE);
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> ((JcrUserDatasource) datasource).enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
} else {
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> ((JcrUserDatasource) datasource).disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}
}
datasource.setTitle(name);
datasource.setDescription(descr);
return datasource;
} catch (IllegalArgumentException | IllegalAccessException | RepositoryException e) {
throw new MetadataException("Unable to create datasource: " + type, e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class JcrFeedProvider method ensureFeed.
/**
* Ensure the Feed, but the Category must exist!
*/
@Override
public Feed ensureFeed(String categorySystemName, String feedSystemName) {
JcrCategory category = null;
try {
String categoryPath = EntityUtil.pathForCategory(categorySystemName);
Node categoryNode = getSession().getNode(categoryPath);
if (categoryNode != null) {
category = JcrUtil.createJcrObject(categoryNode, JcrCategory.class);
} else {
category = (JcrCategory) categoryProvider.findBySystemName(categorySystemName);
}
} catch (RepositoryException e) {
throw new CategoryNotFoundException("Unable to find Category for " + categorySystemName, null);
}
String feedParentPath = category.getFeedParentPath();
boolean newFeed = !hasEntityNode(feedParentPath, feedSystemName);
Node feedNode = findOrCreateEntityNode(feedParentPath, feedSystemName, getJcrEntityClass());
JcrFeed feed = new JcrFeed(feedNode, category, this.opsAccessProvider);
feed.setSystemName(feedSystemName);
if (newFeed) {
if (this.accessController.isEntityAccessControlled()) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.FEED);
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feed.enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
} else {
this.actionsProvider.getAvailableActions(AllowedActions.FEED).ifPresent(actions -> feed.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}
addPostFeedChangeAction(feed, ChangeType.CREATE);
}
return feed;
}
use of com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions in project kylo by Teradata.
the class CheckEntityAccessControlAction method ensureFeedAccessControl.
private void ensureFeedAccessControl() {
List<Feed> feeds = feedProvider.findAll();
if (feeds != null) {
List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.FEED);
Optional<AllowedActions> allowedActions = this.actionsProvider.getAvailableActions(AllowedActions.FEED);
feeds.stream().forEach(feed -> {
Principal owner = feed.getOwner() != null ? feed.getOwner() : JcrMetadataAccess.getActiveUser();
allowedActions.ifPresent(actions -> ((JcrFeed) feed).enableAccessControl((JcrAllowedActions) actions, owner, roles));
});
}
}
Aggregations