Package org.candlepin.model

Examples of org.candlepin.model.Owner


        assertEquals(expected, this.auth.getPrincipal(request));
    }

    @Test
    public void correctPrincipalColonPassword() throws Exception {
        Owner owner = new Owner("user", "user");

        setUserAndPassword("user", "1:2");
        when(userService.validateUser("user", "1:2")).thenReturn(true);

View Full Code Here


                new ArrayList<Permission>(permissions), false);
        assertEquals(expected, this.auth.getPrincipal(request));
    }
    @Test
    public void correctPrincipalNoPassword() throws Exception {
        Owner owner = new Owner("user", "user");

        setUserNoPassword("user");
        when(userService.validateUser("user", null)).thenReturn(true);

View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void correctUserName() throws Exception {
        Owner owner = new Owner("test owner");
        Consumer consumer = new Consumer("machine_name", "test user", owner,
                new ConsumerType(ConsumerTypeEnum.SYSTEM));
        ConsumerPrincipal expected = new ConsumerPrincipal(consumer);

        String dn = "CN=453-44423-235";
View Full Code Here

        Access defaultAccess = getAssumedAccessType(method);

        // Need to check after examining all parameters to see if we found any:
        boolean foundVerifiedParameters = false;
        Owner owner = null;

        Annotation[][] annotations = method.getParameterAnnotations();
        for (int i = 0; i < annotations.length; i++) {
            for (Annotation a : annotations[i]) {
                if (a instanceof Verify) {
                    foundVerifiedParameters = true;
                    Access requiredAccess = defaultAccess;

                    @SuppressWarnings("rawtypes")
                    Class verifyType = ((Verify) a).value();
                    if (((Verify) a).require() != Access.NONE) {
                        requiredAccess = ((Verify) a).require();
                    }
                    SubResource subResource = ((Verify) a).subResource();

                    // Use the correct curator (in storeMap) to look up the actual
                    // entity with the annotated argument
                    if (!storeMap.containsKey(verifyType)) {
                        log.error("No store configured to verify: " + verifyType);
                        throw new IseException(i18n.tr("Unable to verify request."));
                    }

                    List entities = new ArrayList();

                    Object argument = parameters[i];

                    // if the argument is null, we don't have to check anything
                    if (argument == null && ((Verify) a).nullable()) {
                        continue;
                    }
                    else if (argument == null) {
                        log.info("null argument is not allowed");
                        throw new NotFoundException(i18n.tr(
                            "{0} with id {1} could not be found.",
                            Util.getClassName(verifyType), null));
                    }
                    if (argument instanceof String) {
                        String verifyParam = (String) argument;
                        log.debug("Verifying " + requiredAccess +
                            " access to " + verifyType + ": " + verifyParam);

                        Object entity = storeMap.get(verifyType).lookup(verifyParam);
                        // If the request is just for a single item, throw an exception
                        // if it is not found.
                        if (entity == null) {
                            // This is bad, we're verifying a parameter with an ID which
                            // doesn't seem to exist in the DB. Error will be thrown in
                            // invoke though.
                            String typeName = Util.getClassName(verifyType);
                            if (typeName.equals("Owner")) {
                                typeName = i18n.tr("Organization");
                            }
                            log.info("No such entity: " + typeName + " id: " +
                                verifyParam);

                            throw new NotFoundException(i18n.tr(
                                "{0} with id {1} could not be found.",
                                typeName, verifyParam));
                        }

                        entities.add(entity);
                    }
                    else {
                        Collection<String> verifyParams = (Collection<String>) argument;
                        log.debug("Verifying " + requiredAccess +
                            " access to collection of {}: {}", verifyType, verifyParams);
                        // If the request is for a list of items, we'll leave it
                        // up to the requester to determine if something is missing or not.
                        if (verifyParams != null && !verifyParams.isEmpty()) {
                            entities = storeMap.get(verifyType).lookup(verifyParams);
                        }
                    }

                    for (Object entity : entities) {
                        if (!principal.canAccess(entity, subResource, requiredAccess)) {
                            denyAccess(principal, method);
                        }
                        else {
                            // Access granted, grab the org key for logging purposes:
                            Owner o = storeMap.get(verifyType).getOwner((Persisted) entity);

                            if (o != null) {
                                if (owner != null && !o.equals(owner)) {
                                    log.warn("Found entities from multiple orgs in " +
                                        "one request.");
                                }
                                owner = o;
                            }
View Full Code Here

     * @param owner object not retrieved from the DB.
     * @param ownerCurator locaion of object in the DB
     * @return the owner from the DB
     */
    public static Owner lookupOwner(Owner owner, OwnerCurator ownerCurator) {
        Owner o = ownerCurator.lookupByKey(owner.getKey());
        if (o == null) {
            if (owner.getKey() == null) {
                throw new NotFoundException(
                    "An owner does not exist for a null org id");
            }
View Full Code Here

        assertEquals("hypervisor", c1.getType().getLabel());
    }

    @Test
    public void hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists() throws Exception {
        Owner owner = new Owner("owner-id", "Owner Id");

        Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
        hostGuestMap.put("test-host", Arrays.asList(new GuestId("GUEST_B")));

        Owner o = new Owner("owner-id", "Owner ID");
        o.setId("owner-id");
        Consumer existing = new Consumer();
        existing.setUuid("test-host");
        existing.setOwner(o);
        existing.addGuestId(new GuestId("GUEST_A"));
View Full Code Here

        assertEquals("GUEST_B", c1.getGuestIds().get(0).getGuestId());
    }

    @Test
    public void hypervisorCheckInReportsFailuresOnCreateFailure() {
        Owner owner = new Owner("admin");

        Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
        String expectedHostVirtId = "test-host-id";
        hostGuestMap.put(expectedHostVirtId, Arrays.asList(new GuestId("GUEST_A"),
            new GuestId("GUEST_B")));

        // Force create.
        when(consumerCurator.getHypervisor(eq(expectedHostVirtId),
            eq(owner))).thenReturn(null);

        String expectedMessage = "Forced Exception.";
        RuntimeException exception = new RuntimeException(expectedMessage);
        // Simulate failure  when checking the owner
        when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
        when(consumerCurator.getHypervisor(eq(expectedHostVirtId),
            eq(owner))).thenThrow(exception);

        HypervisorCheckInResult result = hypervisorResource.hypervisorCheckIn(hostGuestMap,
            principal, owner.getKey(), true);

        Set<String> failures = result.getFailedUpdate();
        assertEquals(1, failures.size());
        assertEquals(expectedHostVirtId + ": " + expectedMessage,
            failures.iterator().next());
View Full Code Here

            failures.iterator().next());
    }

    @Test
    public void hypervisorCheckInReportsFailureWhenGuestIdUpdateFails() throws Exception {
        Owner owner = new Owner("admin", "Admin");

        Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
        String expectedHostVirtId = "test-host";
        hostGuestMap.put(expectedHostVirtId, Arrays.asList(new GuestId("GUEST_B")));

        Consumer existing = new Consumer();
        existing.setUuid(expectedHostVirtId);
        existing.setOwner(owner);
        existing.addGuestId(new GuestId("GUEST_A"));

        when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);

        // Force update
        when(consumerCurator.getHypervisor(eq(expectedHostVirtId),
            eq(owner))).thenReturn(existing);

        String expectedMessage = "Forced Exception.";
        RuntimeException exception = new RuntimeException(expectedMessage);
        // Simulate failure  when checking the owner
        when(consumerCurator.getHost(any(String.class),
            any(Owner.class))).thenThrow(exception);

        HypervisorCheckInResult result = hypervisorResource.hypervisorCheckIn(hostGuestMap,
            principal, owner.getKey(), true);

        Set<String> failures = result.getFailedUpdate();
        assertEquals(1, failures.size());
        assertEquals(expectedHostVirtId + ": " + expectedMessage,
            failures.iterator().next());
View Full Code Here

            failures.iterator().next());
    }

    @Test
    public void checkInCreatesNoNewConsumerWhenCreateIsFalse() throws Exception {
        Owner owner = new Owner("admin");

        Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
        hostGuestMap.put("test-host", Arrays.asList(new GuestId("GUEST_A"),
            new GuestId("GUEST_B")));

        when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
        when(consumerCurator.getHypervisor(eq("test-host"), eq(owner))).thenReturn(null);
        when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
        when(principal.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).
            thenReturn(true);
        when(consumerTypeCurator.lookupByLabel(
            eq(ConsumerTypeEnum.HYPERVISOR.getLabel()))).thenReturn(hypervisorType);
        when(idCertService.generateIdentityCert(any(Consumer.class)))
            .thenReturn(new IdentityCertificate());

        HypervisorCheckInResult result = hypervisorResource.hypervisorCheckIn(hostGuestMap,
            principal, owner.getKey(), false);

        assertEquals(0, result.getCreated().size());
        assertEquals(1, result.getFailedUpdate().size());

        String failed = result.getFailedUpdate().iterator().next();
View Full Code Here

        refresher = new Refresher(poolManager, subAdapter, false);
    }

    @Test
    public void testOwnerOnlyExaminedOnce() {
        Owner owner = mock(Owner.class);

        refresher.add(owner);
        refresher.add(owner);
        refresher.run();
View Full Code Here

TOP

Related Classes of org.candlepin.model.Owner

Copyright © 2018 www.massapicom. 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.