Search in sources :

Example 6 with JcrCategory

use of com.thinkbiganalytics.metadata.modeshape.category.JcrCategory 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;
}
Also used : SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Node(javax.jcr.Node) CategoryNotFoundException(com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)

Example 7 with JcrCategory

use of com.thinkbiganalytics.metadata.modeshape.category.JcrCategory in project kylo by Teradata.

the class CheckEntityAccessControlAction method ensureCategoryAccessControl.

private void ensureCategoryAccessControl() {
    List<Category> categories = categoryProvider.findAll();
    if (categories != null) {
        List<SecurityRole> catRoles = this.roleProvider.getEntityRoles(SecurityRole.CATEGORY);
        List<SecurityRole> feedRoles = this.roleProvider.getEntityRoles(SecurityRole.FEED);
        Optional<AllowedActions> allowedActions = this.actionsProvider.getAvailableActions(AllowedActions.CATEGORY);
        categories.stream().forEach(category -> {
            Principal owner = category.getOwner() != null ? category.getOwner() : JcrMetadataAccess.getActiveUser();
            allowedActions.ifPresent(actions -> ((JcrCategory) category).enableAccessControl((JcrAllowedActions) actions, owner, catRoles, feedRoles));
        });
    }
}
Also used : SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Category(com.thinkbiganalytics.metadata.api.category.Category) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Principal(java.security.Principal)

Aggregations

JcrCategory (com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)7 Category (com.thinkbiganalytics.metadata.api.category.Category)4 JcrFeed (com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed)4 Node (javax.jcr.Node)3 JcrFeedProvider (com.thinkbiganalytics.metadata.modeshape.feed.JcrFeedProvider)2 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)2 SecurityRole (com.thinkbiganalytics.security.role.SecurityRole)2 Test (org.junit.Test)2 CategoryNotFoundException (com.thinkbiganalytics.metadata.api.category.CategoryNotFoundException)1 Feed (com.thinkbiganalytics.metadata.api.feed.Feed)1 FeedSource (com.thinkbiganalytics.metadata.api.feed.FeedSource)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)1 JcrDatasource (com.thinkbiganalytics.metadata.modeshape.datasource.JcrDatasource)1 JcrDerivedDatasource (com.thinkbiganalytics.metadata.modeshape.datasource.JcrDerivedDatasource)1 AllowedActions (com.thinkbiganalytics.security.action.AllowedActions)1 UpgradeException (com.thinkbiganalytics.server.upgrade.UpgradeException)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1 RepositoryException (javax.jcr.RepositoryException)1