use of org.candlepin.auth.NoAuthPrincipal in project candlepin by candlepin.
the class ConsumerResource method checkActivationKeys.
private List<ActivationKey> checkActivationKeys(Principal principal, Owner owner, Set<String> keyStrings) throws BadRequestException {
List<ActivationKey> keys = new ArrayList<>();
for (String keyString : keyStrings) {
ActivationKey key = null;
try {
key = findKey(keyString, owner);
keys.add(key);
} catch (NotFoundException e) {
log.warn(e.getMessage());
}
}
if ((principal instanceof NoAuthPrincipal) && keys.isEmpty()) {
throw new BadRequestException(i18n.tr("None of the activation keys specified exist for this org."));
}
return keys;
}
use of org.candlepin.auth.NoAuthPrincipal in project candlepin by candlepin.
the class ConsumerResourceCreationTest method failIfOnlyActivationKeyDoesNotExistForOrg.
@Test(expected = BadRequestException.class)
public void failIfOnlyActivationKeyDoesNotExistForOrg() {
Principal p = new NoAuthPrincipal();
List<String> keys = new ArrayList<>();
keys.add("NoSuchKey");
ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
resource.create(consumer, p, null, owner.getKey(), createKeysString(keys), true);
}
use of org.candlepin.auth.NoAuthPrincipal in project candlepin by candlepin.
the class ConsumerResourceCreationTest method cannotMixUsernameWithActivationKeys.
@Test(expected = BadRequestException.class)
public void cannotMixUsernameWithActivationKeys() {
Principal p = new NoAuthPrincipal();
List<String> keys = mockActivationKeys();
ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
resource.create(consumer, p, USER, owner.getKey(), createKeysString(keys), true);
}
use of org.candlepin.auth.NoAuthPrincipal in project candlepin by candlepin.
the class ConsumerResourceCreationTest method authRequired.
@Test(expected = ForbiddenException.class)
public void authRequired() {
Principal p = new NoAuthPrincipal();
List<String> empty = Collections.emptyList();
createConsumer("sys.example.com", p, empty);
}
use of org.candlepin.auth.NoAuthPrincipal in project candlepin by candlepin.
the class ConsumerResourceCreationTest method passIfOnlyOneActivationKeyDoesNotExistForOrg.
@Test
public void passIfOnlyOneActivationKeyDoesNotExistForOrg() {
Principal p = new NoAuthPrincipal();
List<String> keys = mockActivationKeys();
keys.add("NoSuchKey");
ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
resource.create(consumer, p, null, owner.getKey(), createKeysString(keys), true);
}
Aggregations