Search in sources :

Example 11 with RoleDAO

use of com.runwaysdk.business.rbac.RoleDAO in project geoprism-registry by terraframe.

the class ServerHierarchyTypeBuilder method createHierarchyType.

@Transaction
public ServerHierarchyType createHierarchyType(HierarchyType hierarchyType) {
    if (hierarchyType.getOrganizationCode() == null || hierarchyType.getOrganizationCode().equals("")) {
        // TODO : A better exception
        throw new AttributeValueException("Organization code cannot be null.", hierarchyType.getOrganizationCode());
    }
    Organization organization = Organization.getByCode(hierarchyType.getOrganizationCode());
    String addons = new String(RegistryConstants.UNIVERSAL_RELATIONSHIP_POST + "AllPathsTable");
    if (hierarchyType.getCode().length() > (64 - addons.length())) {
        // Initializing the Universal allpaths strategy creates this limitation.
        CodeLengthException ex = new CodeLengthException();
        ex.setLength(64 - addons.length());
        throw ex;
    }
    RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
    RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
    RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
    InitializationStrategyIF strategy = new InitializationStrategyIF() {

        @Override
        public void preApply(MdBusinessDAO mdBusiness) {
            mdBusiness.setValue(MdBusinessInfo.GENERATE_SOURCE, MdAttributeBooleanInfo.FALSE);
        }

        @Override
        public void postApply(MdBusinessDAO mdBusiness) {
            RoleDAO adminRole = RoleDAO.findRole(DefaultConfiguration.ADMIN).getBusinessDAO();
            adminRole.grantPermission(Operation.READ, mdBusiness.getOid());
            adminRole.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            adminRole.grantPermission(Operation.WRITE, mdBusiness.getOid());
            adminRole.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
            adminRole.grantPermission(Operation.CREATE, mdBusiness.getOid());
            adminRole.grantPermission(Operation.DELETE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.READ, mdBusiness.getOid());
            maintainer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            maintainer.grantPermission(Operation.WRITE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.WRITE_ALL, mdBusiness.getOid());
            maintainer.grantPermission(Operation.CREATE, mdBusiness.getOid());
            maintainer.grantPermission(Operation.DELETE, mdBusiness.getOid());
            consumer.grantPermission(Operation.READ, mdBusiness.getOid());
            consumer.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
            contributor.grantPermission(Operation.READ, mdBusiness.getOid());
            contributor.grantPermission(Operation.READ_ALL, mdBusiness.getOid());
        }
    };
    try {
        MdTermRelationship mdTermRelUniversal = this.newHierarchyToMdTermRelForUniversals(hierarchyType);
        mdTermRelUniversal.apply();
        this.grantWritePermissionsOnMdTermRel(mdTermRelUniversal);
        this.grantWritePermissionsOnMdTermRel(maintainer, mdTermRelUniversal);
        this.grantReadPermissionsOnMdTermRel(consumer, mdTermRelUniversal);
        this.grantReadPermissionsOnMdTermRel(contributor, mdTermRelUniversal);
        Universal.getStrategy().initialize(mdTermRelUniversal.definesType(), strategy);
        MdEdge mdEdge = this.createMdEdge(hierarchyType);
        this.grantWritePermissionsOnMdTermRel(mdEdge);
        this.grantWritePermissionsOnMdTermRel(maintainer, mdEdge);
        this.grantReadPermissionsOnMdTermRel(consumer, mdEdge);
        this.grantReadPermissionsOnMdTermRel(contributor, mdEdge);
        HierarchicalRelationshipType hierarchicalRelationship = new HierarchicalRelationshipType();
        hierarchicalRelationship.setCode(hierarchyType.getCode());
        hierarchicalRelationship.setOrganization(organization);
        populate(hierarchicalRelationship.getDisplayLabel(), hierarchyType.getLabel());
        populate(hierarchicalRelationship.getDescription(), hierarchyType.getDescription());
        hierarchicalRelationship.setMdTermRelationship(mdTermRelUniversal);
        hierarchicalRelationship.setMdEdge(mdEdge);
        hierarchicalRelationship.setAbstractDescription(hierarchyType.getAbstractDescription());
        hierarchicalRelationship.setAcknowledgement(hierarchyType.getAcknowledgement());
        hierarchicalRelationship.setDisclaimer(hierarchyType.getDisclaimer());
        hierarchicalRelationship.setContact(hierarchyType.getContact());
        hierarchicalRelationship.setPhoneNumber(hierarchyType.getPhoneNumber());
        hierarchicalRelationship.setEmail(hierarchyType.getEmail());
        hierarchicalRelationship.setProgress(hierarchyType.getProgress());
        hierarchicalRelationship.setAccessConstraints(hierarchyType.getAccessConstraints());
        hierarchicalRelationship.setUseConstraints(hierarchyType.getUseConstraints());
        hierarchicalRelationship.apply();
        return this.get(hierarchicalRelationship);
    } catch (DuplicateDataException ex) {
        DuplicateHierarchyTypeException ex2 = new DuplicateHierarchyTypeException();
        ex2.setDuplicateValue(hierarchyType.getCode());
        throw ex2;
    }
}
Also used : Organization(net.geoprism.registry.Organization) MdEdge(com.runwaysdk.system.metadata.MdEdge) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdBusinessDAO(com.runwaysdk.dataaccess.metadata.MdBusinessDAO) DuplicateHierarchyTypeException(net.geoprism.registry.DuplicateHierarchyTypeException) InitializationStrategyIF(com.runwaysdk.business.ontology.InitializationStrategyIF) HierarchicalRelationshipType(net.geoprism.registry.HierarchicalRelationshipType) AttributeValueException(com.runwaysdk.dataaccess.attributes.AttributeValueException) MdTermRelationship(com.runwaysdk.system.metadata.MdTermRelationship) CodeLengthException(net.geoprism.registry.CodeLengthException) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 12 with RoleDAO

use of com.runwaysdk.business.rbac.RoleDAO in project geoprism-registry by terraframe.

the class ClassificationType method assignPermissions.

/**
 * Assigns all permissions to the {@link ComponentIF} to the given role.
 *
 * Precondition: component is either a {@link MdGeoVertex} or a
 * {@link MdBusiness}.
 *
 * @param component
 * @param role
 * @param includeWrite
 *          TODO
 */
private void assignPermissions(ComponentIF component, Roles role, boolean includeWrite) {
    RoleDAO roleDAO = (RoleDAO) BusinessFacade.getEntityDAO(role);
    roleDAO.grantPermission(Operation.READ, component.getOid());
    roleDAO.grantPermission(Operation.READ_ALL, component.getOid());
    if (includeWrite) {
        roleDAO.grantPermission(Operation.CREATE, component.getOid());
        roleDAO.grantPermission(Operation.DELETE, component.getOid());
        roleDAO.grantPermission(Operation.WRITE, component.getOid());
        roleDAO.grantPermission(Operation.WRITE_ALL, component.getOid());
    }
}
Also used : RoleDAO(com.runwaysdk.business.rbac.RoleDAO)

Example 13 with RoleDAO

use of com.runwaysdk.business.rbac.RoleDAO in project geoprism-registry by terraframe.

the class DirectedAcyclicGraphType method create.

@Transaction
public static DirectedAcyclicGraphType create(String code, LocalizedValue label, LocalizedValue description) {
    RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
    RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
    RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
    try {
        MdVertexDAOIF mdBusGeoEntity = MdVertexDAO.getMdVertexDAO(GeoVertex.CLASS);
        MdEdgeDAO mdEdgeDAO = MdEdgeDAO.newInstance();
        mdEdgeDAO.setValue(MdEdgeInfo.PACKAGE, RegistryConstants.DAG_PACKAGE);
        mdEdgeDAO.setValue(MdEdgeInfo.NAME, code);
        mdEdgeDAO.setValue(MdEdgeInfo.PARENT_MD_VERTEX, mdBusGeoEntity.getOid());
        mdEdgeDAO.setValue(MdEdgeInfo.CHILD_MD_VERTEX, mdBusGeoEntity.getOid());
        LocalizedValueConverter.populate(mdEdgeDAO, MdEdgeInfo.DISPLAY_LABEL, label);
        LocalizedValueConverter.populate(mdEdgeDAO, MdEdgeInfo.DESCRIPTION, description);
        mdEdgeDAO.setValue(MdEdgeInfo.ENABLE_CHANGE_OVER_TIME, MdAttributeBooleanInfo.FALSE);
        mdEdgeDAO.apply();
        MdAttributeDateTimeDAO startDate = MdAttributeDateTimeDAO.newInstance();
        startDate.setValue(MdAttributeDateTimeInfo.NAME, GeoVertex.START_DATE);
        startDate.setStructValue(MdAttributeDateTimeInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "Start Date");
        startDate.setStructValue(MdAttributeDateTimeInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "Start Date");
        startDate.setValue(MdAttributeDateTimeInfo.DEFINING_MD_CLASS, mdEdgeDAO.getOid());
        startDate.apply();
        MdAttributeDateTimeDAO endDate = MdAttributeDateTimeDAO.newInstance();
        endDate.setValue(MdAttributeDateTimeInfo.NAME, GeoVertex.END_DATE);
        endDate.setStructValue(MdAttributeDateTimeInfo.DISPLAY_LABEL, MdAttributeLocalInfo.DEFAULT_LOCALE, "End Date");
        endDate.setStructValue(MdAttributeDateTimeInfo.DESCRIPTION, MdAttributeLocalInfo.DEFAULT_LOCALE, "End Date");
        endDate.setValue(MdAttributeDateTimeInfo.DEFINING_MD_CLASS, mdEdgeDAO.getOid());
        endDate.apply();
        ServerHierarchyTypeBuilder permissionBuilder = new ServerHierarchyTypeBuilder();
        permissionBuilder.grantWritePermissionsOnMdTermRel(mdEdgeDAO);
        permissionBuilder.grantWritePermissionsOnMdTermRel(maintainer, mdEdgeDAO);
        permissionBuilder.grantReadPermissionsOnMdTermRel(consumer, mdEdgeDAO);
        permissionBuilder.grantReadPermissionsOnMdTermRel(contributor, mdEdgeDAO);
        DirectedAcyclicGraphType graphType = new DirectedAcyclicGraphType();
        graphType.setCode(code);
        graphType.setMdEdgeId(mdEdgeDAO.getOid());
        LocalizedValueConverter.populate(graphType.getDisplayLabel(), label);
        LocalizedValueConverter.populate(graphType.getDescription(), description);
        graphType.apply();
        return graphType;
    } catch (DuplicateDataException ex) {
        DuplicateHierarchyTypeException ex2 = new DuplicateHierarchyTypeException();
        ex2.setDuplicateValue(code);
        throw ex2;
    }
}
Also used : MdVertexDAOIF(com.runwaysdk.dataaccess.MdVertexDAOIF) DuplicateDataException(com.runwaysdk.dataaccess.DuplicateDataException) RoleDAO(com.runwaysdk.business.rbac.RoleDAO) MdEdgeDAO(com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO) ServerHierarchyTypeBuilder(net.geoprism.registry.conversion.ServerHierarchyTypeBuilder) MdAttributeDateTimeDAO(com.runwaysdk.dataaccess.metadata.MdAttributeDateTimeDAO) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 14 with RoleDAO

use of com.runwaysdk.business.rbac.RoleDAO in project geoprism-registry by terraframe.

the class ListTypeVersion method assignDefaultRolePermissions.

private static void assignDefaultRolePermissions(ComponentIF component) {
    RoleDAO adminRole = RoleDAO.findRole(DefaultConfiguration.ADMIN).getBusinessDAO();
    adminRole.grantPermission(Operation.CREATE, component.getOid());
    adminRole.grantPermission(Operation.DELETE, component.getOid());
    adminRole.grantPermission(Operation.WRITE, component.getOid());
    adminRole.grantPermission(Operation.WRITE_ALL, component.getOid());
    RoleDAO maintainer = RoleDAO.findRole(RegistryConstants.REGISTRY_MAINTAINER_ROLE).getBusinessDAO();
    maintainer.grantPermission(Operation.CREATE, component.getOid());
    maintainer.grantPermission(Operation.DELETE, component.getOid());
    maintainer.grantPermission(Operation.WRITE, component.getOid());
    maintainer.grantPermission(Operation.WRITE_ALL, component.getOid());
    RoleDAO consumer = RoleDAO.findRole(RegistryConstants.API_CONSUMER_ROLE).getBusinessDAO();
    consumer.grantPermission(Operation.READ, component.getOid());
    consumer.grantPermission(Operation.READ_ALL, component.getOid());
    RoleDAO contributor = RoleDAO.findRole(RegistryConstants.REGISTRY_CONTRIBUTOR_ROLE).getBusinessDAO();
    contributor.grantPermission(Operation.READ, component.getOid());
    contributor.grantPermission(Operation.READ_ALL, component.getOid());
}
Also used : RoleDAO(com.runwaysdk.business.rbac.RoleDAO)

Example 15 with RoleDAO

use of com.runwaysdk.business.rbac.RoleDAO in project geoprism-registry by terraframe.

the class Organization method createRegistryAdminOrganizationRole.

/**
 * Creates a Registry Administrator {@link RoleDAOIF} for this
 * {@link Organization}.
 *
 * Precondition: a {@link RoleDAOIF} does not exist for this
 * {@link Organization}. Precondition: the display label for the default
 * locale has a value for this {@link Organization}
 */
private void createRegistryAdminOrganizationRole() {
    String registryAdminRoleName = this.getRegistryAdminRoleName();
    String defaultDisplayLabel = this.getDisplayLabel().getDefaultValue() + " Registry Administrator";
    // Heads up: clean up move to Roles.java?
    Roles raOrgRole = new Roles();
    raOrgRole.setRoleName(registryAdminRoleName);
    raOrgRole.getDisplayLabel().setDefaultValue(defaultDisplayLabel);
    raOrgRole.apply();
    Roles orgRole = (Roles) this.getRole();
    RoleDAO orgRoleDAO = (RoleDAO) BusinessFacade.getEntityDAO(orgRole);
    RoleDAO raOrgRoleDAO = (RoleDAO) BusinessFacade.getEntityDAO(raOrgRole);
    orgRoleDAO.addInheritance(raOrgRoleDAO);
    // Inherit the permissions from the root RA role
    RoleDAO rootRA_DAO = (RoleDAO) BusinessFacade.getEntityDAO(Roles.findRoleByName(RegistryConstants.REGISTRY_ADMIN_ROLE));
    rootRA_DAO.addInheritance(raOrgRoleDAO);
}
Also used : RoleDAO(com.runwaysdk.business.rbac.RoleDAO) Roles(com.runwaysdk.system.Roles)

Aggregations

RoleDAO (com.runwaysdk.business.rbac.RoleDAO)20 Roles (com.runwaysdk.system.Roles)6 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)5 DuplicateDataException (com.runwaysdk.dataaccess.DuplicateDataException)3 MdVertexDAOIF (com.runwaysdk.dataaccess.MdVertexDAOIF)3 MdEdgeDAO (com.runwaysdk.dataaccess.metadata.graph.MdEdgeDAO)3 Locale (java.util.Locale)3 InitializationStrategyIF (com.runwaysdk.business.ontology.InitializationStrategyIF)2 AttributeValueException (com.runwaysdk.dataaccess.attributes.AttributeValueException)2 MdAttributeDateTimeDAO (com.runwaysdk.dataaccess.metadata.MdAttributeDateTimeDAO)2 MdBusinessDAO (com.runwaysdk.dataaccess.metadata.MdBusinessDAO)2 MdTermRelationship (com.runwaysdk.system.metadata.MdTermRelationship)2 ServerHierarchyTypeBuilder (net.geoprism.registry.conversion.ServerHierarchyTypeBuilder)2 ComponentIF (com.runwaysdk.ComponentIF)1 RoleDAOIF (com.runwaysdk.business.rbac.RoleDAOIF)1 UserDAOIF (com.runwaysdk.business.rbac.UserDAOIF)1 MdAttributeCharacterDAO (com.runwaysdk.dataaccess.metadata.MdAttributeCharacterDAO)1 MdAttributeGraphReferenceDAO (com.runwaysdk.dataaccess.metadata.MdAttributeGraphReferenceDAO)1 MdVertexDAO (com.runwaysdk.dataaccess.metadata.graph.MdVertexDAO)1 QueryFactory (com.runwaysdk.query.QueryFactory)1