use of org.candlepin.model.User in project candlepin by candlepin.
the class UsernameConsumersPermissionTest method init.
@Before
public void init() {
User u = new User(username, "dontcare");
owner = new Owner("ownerkey", "My Org");
owner.setId(TestUtil.randomString());
perm = new UsernameConsumersPermission(u, owner);
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class DefaultUserServiceAdapter method validateUser.
@Override
public boolean validateUser(String username, String password) {
User user = this.userCurator.findByLogin(username);
String hashedPassword = Util.hash(password);
if (user != null && password != null && hashedPassword != null) {
return hashedPassword.equals(user.getHashedPassword());
}
return false;
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class ConsumerCuratorPermissionsTest method testFindByUuidPermissionFiltering.
@Test
public void testFindByUuidPermissionFiltering() {
User u = setupOnlyMyConsumersPrincipal();
Consumer c1 = new Consumer("c1", u.getUsername(), owner, consumerType);
consumerCurator.create(c1);
Consumer c2 = new Consumer("c2", "anotheruser", owner, consumerType);
consumerCurator.create(c2);
assertEquals(c1, consumerCurator.findByUuid(c1.getUuid()));
assertNull(consumerCurator.findByUuid(c2.getUuid()));
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class ConsumerCuratorPermissionsTest method testListForOwnerEditMineViewAllPermissionFiltering.
@Test
public void testListForOwnerEditMineViewAllPermissionFiltering() {
User u = setupEditMyConsumersViewAllPrincipal();
Consumer c1 = new Consumer("c1", u.getUsername(), owner, consumerType);
consumerCurator.create(c1);
Consumer c2 = new Consumer("c2", "anotheruser", owner, consumerType);
consumerCurator.create(c2);
List<Consumer> results = consumerCurator.listByOwner(owner).list();
assertEquals(2, results.size());
}
use of org.candlepin.model.User in project candlepin by candlepin.
the class ConsumerResource method verifyPersonConsumer.
private void verifyPersonConsumer(ConsumerDTO consumer, ConsumerType type, Owner owner, String username, Principal principal) {
User user = null;
try {
user = userService.findByLogin(username);
} catch (UnsupportedOperationException e) {
log.warn("User service does not allow user lookups, cannot verify person consumer.");
}
if (user == null) {
throw new NotFoundException(i18n.tr("User with ID \"{0}\" could not be found."));
}
// has some association with the owner the consumer is destined for:
if (!principal.canAccess(owner, SubResource.NONE, Access.ALL) && !principal.hasFullAccess()) {
throw new ForbiddenException(i18n.tr("User \"{0}\" has no roles for organization \"{1}\"", user.getUsername(), owner.getKey()));
}
// TODO: Refactor out type specific checks?
if (type.isType(ConsumerTypeEnum.PERSON)) {
Consumer existing = consumerCurator.findByUser(user);
if (existing != null && this.consumerTypeCurator.getConsumerType(existing).isType(ConsumerTypeEnum.PERSON)) {
// TODO: This is not the correct error code for this situation!
throw new BadRequestException(i18n.tr("User \"{0}\" has already registered a personal consumer", user.getUsername()));
}
consumer.setName(user.getUsername());
}
}
Aggregations