Examples of BundleGroup


Examples of org.rhq.core.domain.bundle.BundleGroup

            // remove bundle groups to free up bundles
            q = em.createQuery("SELECT bg FROM BundleGroup bg WHERE bg.name LIKE '" + TEST_PREFIX + "%'");
            doomed = q.getResultList();
            for (Object removeMe : doomed) {
                BundleGroup doomedBundleGroup = em.find(BundleGroup.class, ((BundleGroup) removeMe).getId());
                doomedBundleGroup.setBundles(new HashSet<Bundle>());
                em.remove(doomedBundleGroup);
            }

            // remove bundles which cascade remove packageTypes and destinations
            // packagetypes cascade remove packages
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        Subject subject = createNewSubject(TEST_USER_NAME);
        Role role = createNewRoleForSubject(subject, TEST_ROLE_NAME);

        subject = createSession(subject); // start a session so we can use this subject in SLSB calls

        BundleGroup bundleGroup = new BundleGroup(TEST_BUNDLE_GROUP_NAME);
        bundleGroup.setDescription("test");

        // deny bundle group create
        try {
            bundleManager.createBundleGroup(subject, bundleGroup);
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle group create
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        bundleGroup = bundleManager.createBundleGroup(subject, bundleGroup);

        // deny bundle group delete
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        try {
            bundleManager.deleteBundleGroups(subject, new int[] { bundleGroup.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny global perm bundleGroup view
        BundleGroupCriteria bgCriteria = new BundleGroupCriteria();
        List<BundleGroup> bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not be able to see unassociated bundle group";

        // allow global perm bundleGroup view
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assertEquals("Should be able to see unassociated bundle group", 1, bundleGroups.size());

        // allow bundle group delete
        bundleManager.deleteBundleGroups(subject, new int[] { bundleGroup.getId() });
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // deny unassigned bundle create (no global create or view)
        try {
            createBundle(subject, TEST_PREFIX + ".bundle");
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny unassigned bundle create (no global view)
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        try {
            createBundle(subject, TEST_PREFIX + ".bundle");
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny unassigned bundle create (no global create)
        removeRolePermissions(role, Permission.CREATE_BUNDLES);
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        try {
            createBundle(subject, TEST_PREFIX + ".bundle");
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow unassigned bundle create
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        Bundle bundle = createBundle(subject, TEST_PREFIX + ".bundle");

        // deny unassigned bundle view
        removeRolePermissions(role, Permission.CREATE_BUNDLES, Permission.VIEW_BUNDLES);
        BundleCriteria bCriteria = new BundleCriteria();
        List<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not be able to see unassigned bundle";

        // allow unassigned bundle view
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see unassigned bundle", 1, bundles.size());

        // deny global perm bundle assign
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        bundleGroup = new BundleGroup(TEST_BUNDLE_GROUP_NAME);
        bundleGroup.setDescription("test");

        bundleGroup = bundleManager.createBundleGroup(subject, bundleGroup);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle assign via global manage_bundle_groups
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // allow bundle unassign via global manage_bundle_groups
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // allow bundle assign via global create
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // deny bundle unassign via global create
        try {
            bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle unassign via global delete
        addRolePermissions(role, Permission.DELETE_BUNDLES);
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });
        removeRolePermissions(role, Permission.DELETE_BUNDLES);

        // deny bundle assign with global create but no view
        removeRolePermissions(role, Permission.VIEW_BUNDLES);
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // go back and again assign via global create and view
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // deny assigned, unassociated-bundle-group bundle view
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        removeRolePermissions(role, Permission.VIEW_BUNDLES);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not be able to see assigned bundle";

        // allow assigned, associated-bundle-group bundle view
        addRoleBundleGroup(role, bundleGroup);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());

        // check new bundle criteria options (no match)
        bCriteria.addFilterBundleGroupIds(87678);
        bCriteria.fetchBundleGroups(true);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not have found anything";

        // check new bundle criteria options (match)
        bCriteria.addFilterBundleGroupIds(bundleGroup.getId());
        bCriteria.fetchBundleGroups(true);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());
        assertNotNull(bundles.get(0).getBundleGroups());
        assertEquals("Should have fetched bundlegroup", 1, bundles.get(0).getBundleGroups().size());
        assertEquals("Should have fetched expected bundlegroup", bundleGroup, bundles.get(0).getBundleGroups()
            .iterator().next());

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterId(87678);
        bgCriteria.addFilterBundleIds(87678);
        bgCriteria.addFilterRoleIds(87678);
        bgCriteria.fetchBundles(true);
        bgCriteria.fetchRoles(true);
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterId(bundleGroup.getId());
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (no match)
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        subject = createSession(subject); // start a session so we can use this subject in SLSB calls

        // create bundle group
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        BundleGroup bundleGroup1 = new BundleGroup(TEST_BUNDLE_GROUP_NAME + "_1");
        bundleGroup1.setDescription("bg-1");
        bundleGroup1 = bundleManager.createBundleGroup(subject, bundleGroup1);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // add bg1 to the role, but no perms
        addRoleBundleGroup(role, bundleGroup1);

        // deny bundle create in bg1 (no create perm)
        try {
            createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup1.getId());
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle creation in bg1 (has create perm)
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);
        Bundle bundle = createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup1.getId());

        // deny bundle version creation (perm taken away)
        removeRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);
        try {
            BundleVersion bv1 = createBundleVersion(subject, bundle.getName() + "-1", null, bundle);
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle version creation (perm granted)
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);
        BundleVersion bv1 = createBundleVersion(subject, bundle.getName() + "-1", null, bundle);
        assertNotNull(bv1);
        assertEquals("1.0", bv1.getVersion());
        assert 0 == bv1.getVersionOrder();

        // create second role
        Role role2 = createNewRoleForSubject(subject, TEST_ROLE_NAME + "_2");
        addRolePermissions(role2, Permission.CREATE_BUNDLES_IN_GROUP);

        // create second bundle group
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        BundleGroup bundleGroup2 = new BundleGroup(TEST_BUNDLE_GROUP_NAME + "_2");
        bundleGroup2.setDescription("bg-2");
        bundleGroup2 = bundleManager.createBundleGroup(subject, bundleGroup2);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // deny bundle create in bg2 (not associated with role)
        try {
            createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup2.getId());
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny bundle assign to bg2 (not associated with role)
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup2.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // add bg2 to the role
        addRoleBundleGroup(role2, bundleGroup2);

        // deny bundle assign to bg2 (no perm)
        removeRolePermissions(role2, Permission.CREATE_BUNDLES_IN_GROUP);
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup2.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle assign to bg2
        addRolePermissions(role2, Permission.ASSIGN_BUNDLES_TO_GROUP);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup2.getId() },
            new int[] { bundle.getId() });

        // should fetch the single bundle even though it is in two groups
        BundleCriteria bundleCriteria = new BundleCriteria();
        bundleCriteria.addFilterBundleGroupIds(bundleGroup1.getId(), bundleGroup2.getId());
        List<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, bundleCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());
        assertEquals("Should have fetched bundle", bundle, bundles.get(0));

        BundleVersionCriteria bvCriteria = new BundleVersionCriteria();
        bvCriteria.addFilterBundleId(bundle.getId());
        List<BundleVersion> bundleVersions = bundleManager.findBundleVersionsByCriteria(subject, bvCriteria);
        assertNotNull(bundleVersions);
        assertEquals("Should be able to see assigned bundle bundleversion", 1, bundleVersions.size());
        assertEquals("Should have fetched bundleversion", bv1, bundleVersions.get(0));

        // deny unassign
        try {
            bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup2.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow unassigns
        addRolePermissions(role, Permission.UNASSIGN_BUNDLES_FROM_GROUP);
        addRolePermissions(role2, Permission.UNASSIGN_BUNDLES_FROM_GROUP);
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup1.getId() },
            new int[] { bundle.getId() });
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup2.getId() },
            new int[] { bundle.getId() });

        // should not find the now unassigned bundle
        bundles = bundleManager.findBundlesByCriteria(subject, bundleCriteria);
        assertNotNull(bundles);
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        subject = createSession(subject); // start a session so we can use this subject in SLSB calls

        // create bundle group
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        BundleGroup bundleGroup1 = new BundleGroup(TEST_BUNDLE_GROUP_NAME + "_1");
        bundleGroup1.setDescription("bg-1");
        bundleGroup1 = bundleManager.createBundleGroup(subject, bundleGroup1);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // add bg1 to the role with group create
        addRoleBundleGroup(role, bundleGroup1);
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);

        // allow bundle creation in bg1 (has create perm)
        Bundle bundle = createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup1.getId());

        // allow delete, global perm
        addRolePermissions(role, Permission.DELETE_BUNDLES);
        deleteBundleVersion(subject, bundle);

        // allow bundle creation in bg1 (has create perm)
        bundle = createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup1.getId());

        // allow delete, bundle group perm
        removeRolePermissions(role, Permission.DELETE_BUNDLES);
        addRolePermissions(role, Permission.DELETE_BUNDLES_FROM_GROUP);
        deleteBundleVersion(subject, bundle);

        // allow bundle creation in bg1 (has create perm)
        bundle = createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup1.getId());

        // deny delete, no delete perms
        removeRolePermissions(role, Permission.DELETE_BUNDLES_FROM_GROUP);
        try {
            deleteBundleVersion(subject, bundle);
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        Role role = createNewRoleForSubject(subject, TEST_ROLE_NAME);
        subject = createSession(subject); // start a session so we can use this subject in SLSB calls

        // create bundle group
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        BundleGroup bundleGroup = new BundleGroup(TEST_BUNDLE_GROUP_NAME);
        bundleGroup.setDescription("bg");
        bundleGroup = bundleManager.createBundleGroup(subject, bundleGroup);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // add bg to the role with group create
        addRoleBundleGroup(role, bundleGroup);
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);

        // allow bundle creation in bg (has create perm)
        Bundle b1 = createBundle(subject, "one", bundleGroup.getId());
        assertNotNull(b1);
        BundleVersion bv1 = createBundleVersion(subject, b1.getName() + "-1", null, b1);
        assertNotNull(bv1);
        ResourceGroup platformResourceGroup = createTestResourceGroup();
        assertNotNull(platformResourceGroup);
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        Role role = createNewRoleForSubject(subject, TEST_ROLE_NAME);
        subject = createSession(subject); // start a session so we can use this subject in SLSB calls

        // create bundle group
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        BundleGroup bundleGroup = new BundleGroup(TEST_BUNDLE_GROUP_NAME);
        bundleGroup.setDescription("bg");
        bundleGroup = bundleManager.createBundleGroup(subject, bundleGroup);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // add bg to the role with group create
        addRoleBundleGroup(role, bundleGroup);
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);

        // allow bundle creation in bg (has create perm)
        Bundle b1 = createBundle(subject, "one", bundleGroup.getId());
        assertNotNull(b1);
        BundleVersion bv1 = createBundleVersion(subject, b1.getName() + "-1", null, b1);
        assertNotNull(bv1);
        ResourceGroup platformResourceGroup = createTestResourceGroup();
        assertNotNull(platformResourceGroup);
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

    }

    @Override
    public BundleGroup createBundleGroup(BundleGroup bundleGroup) throws RuntimeException {
        try {
            BundleGroup results = bundleManager.createBundleGroup(getSessionSubject(), bundleGroup);
            return SerialUtility.prepare(results, "createBundleGroup");
        } catch (Throwable t) {
            throw getExceptionToThrowToClient(t);
        }
    }
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

    }

    @Override
    public BundleGroup updateBundleGroup(BundleGroup bundleGroup) throws RuntimeException {
        try {
            BundleGroup results = bundleManager.updateBundleGroup(getSessionSubject(), bundleGroup);
            return SerialUtility.prepare(results, "updateBundleGroup");
        } catch (Throwable t) {
            throw getExceptionToThrowToClient(t);
        }
    }
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        }

        bundleGroupIds = (null != bundleGroupIds) ? bundleGroupIds : new int[0];
        List<BundleGroup> bundleGroups = new ArrayList<BundleGroup>(bundleGroupIds.length);
        for (int bundleGroupId : bundleGroupIds) {
            BundleGroup bundleGroup = entityManager.find(BundleGroup.class, bundleGroupId);
            if (null == bundleGroup) {
                throw new IllegalArgumentException("Invalid bundleGroupId: " + bundleGroupId);
            }
            bundleGroups.add(bundleGroup);
        }

        checkCreateInitialBundleVersionAuthz(subject, bundleGroupIds);

        // create and add the required Repo. the Repo is a detached object which helps in its eventual removal.
        Repo repo = new Repo(name);
        repo.setCandidate(false);
        repo.setSyncSchedule(null);

        // create the repo as overlord, this allows users without MANAGE_INVENTORY permission to create bundles
        repo = repoManager.createRepo(subjectManager.getOverlord(), repo);

        // add the required PackageType. the PackageType is an attached object which helps in cascade removal
        // of packages in the bundle's repo.
        ResourceType resourceType = entityManager.find(ResourceType.class, bundleType.getResourceType().getId());
        PackageType packageType = new PackageType(name, resourceType);
        packageType.setDescription("Package type for content of bundle " + name);
        packageType.setCategory(PackageCategory.BUNDLE);
        packageType.setSupportsArchitecture(false);
        packageType.setDisplayName(StringUtils.deCamelCase(name));
        packageType.setDiscoveryInterval(-1L);
        packageType.setCreationData(false);
        packageType.setDeploymentConfigurationDefinition(null);

        Bundle bundle = new Bundle(name, bundleType, repo, packageType);
        bundle.setDescription(description);
        bundle.setPackageType(packageType);

        LOG.info("Creating bundle: " + bundle);
        entityManager.persist(bundle);

        for (BundleGroup bundleGroup : bundleGroups) {
            bundleGroup.addBundle(bundle);
        }

        return bundle;
    }
View Full Code Here

Examples of org.rhq.core.domain.bundle.BundleGroup

        if (null == bundleGroupIds || null == bundleIds) {
            return;
        }

        for (int bundleGroupId : bundleGroupIds) {
            BundleGroup bundleGroup = entityManager.find(BundleGroup.class, bundleGroupId);
            if (null == bundleGroup) {
                throw new IllegalArgumentException("BundleGroup does not exist for bundleGroupId [" + bundleGroupId
                    + "]");
            }

            checkAssignBundleGroupAuthz(subject, bundleGroupId, bundleIds);

            for (int bundleId : bundleIds) {
                Bundle bundle = entityManager.find(Bundle.class, bundleId);
                if (null == bundle) {
                    throw new IllegalArgumentException("Bundle does not exist for bundleId [" + bundleId + "]");
                }

                bundleGroup.addBundle(bundle);
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.