use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class TestPrincipalProvider method get.
@Override
public Principal get() {
TestPrincipalProviderSetter principalSingleton = TestPrincipalProviderSetter.get();
Principal principal = principalSingleton.getPrincipal();
if (principal == null) {
List<Permission> permissions = new ArrayList<>();
permissions.add(new OwnerPermission(new Owner(OWNER_NAME), Access.ALL));
principal = new UserPrincipal("Default User", permissions, true);
}
return principal;
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method setUp.
@Before
public void setUp() {
standardSystemType = consumerTypeCurator.create(new ConsumerType("standard-system"));
standardSystemTypeDTO = modelTranslator.translate(standardSystemType, ConsumerTypeDTO.class);
personType = consumerTypeCurator.create(new ConsumerType(ConsumerTypeEnum.PERSON));
personTypeDTO = modelTranslator.translate(personType, ConsumerTypeDTO.class);
owner = ownerCurator.create(new Owner("test-owner"));
ownerDTO = modelTranslator.translate(owner, OwnerDTO.class);
owner.setDefaultServiceLevel(DEFAULT_SERVICE_LEVEL);
ownerCurator.create(owner);
someuser = userCurator.create(new User(USER_NAME, "dontcare"));
ownerAdminRole = createAdminRole(owner);
ownerAdminRole.addUser(someuser);
roleCurator.create(ownerAdminRole);
List<Permission> perms = permFactory.createPermissions(someuser, ownerAdminRole.getPermissions());
principal = new UserPrincipal(USER_NAME, perms, false);
setupPrincipal(principal);
consumer = TestUtil.createConsumer(standardSystemType, owner);
consumerCurator.create(consumer);
product = TestUtil.createProduct();
product.setAttribute(Product.Attributes.SUPPORT_LEVEL, DEFAULT_SERVICE_LEVEL);
productCurator.create(product);
pool = createPool(owner, product, 10L, TestDateUtil.date(2010, 1, 1), TestDateUtil.date(2020, 12, 31));
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method userwithEmail.
@Test
public void userwithEmail() {
String username = "(foo)@{baz}.[com]&?";
User u = userCurator.create(new User(username, "dontcare"));
ownerAdminRole.addUser(u);
roleCurator.merge(ownerAdminRole);
Principal emailuser = TestUtil.createPrincipal(username, owner, Access.ALL);
setupPrincipal(emailuser);
ConsumerDTO personal = createConsumerDTO(personTypeDTO, ownerDTO);
personal.setName(((UserPrincipal) emailuser).getUsername());
personal = consumerResource.create(personal, emailuser, username, null, null, true);
// Not sure if this should be hard-coded to default
assertEquals(username, personal.getName());
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientPermissions.
@Test
public void testValidateShareConsumerRequiresRecipientPermissions() {
ConsumerType share = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SHARE));
ConsumerTypeDTO shareDto = this.translator.translate(share, ConsumerTypeDTO.class);
OwnerDTO ownerDto = new OwnerDTO().setDisplayName("Test Owner");
ConsumerDTO c = createConsumerDTO("test-consumer", "test-user", ownerDto, shareDto);
ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, i18n, null, null, null, null, null, mockPoolManager, null, mockOwnerCurator, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, consumerBindUtil, null, null, factValidator, null, consumerEnricher, migrationProvider, translator);
UserPrincipal uap = mock(UserPrincipal.class);
when(uap.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(Boolean.TRUE);
Owner o = mock(Owner.class);
when(mockOwnerCurator.lookupByKey(any(String.class))).thenReturn(o);
Owner o2 = mock(Owner.class);
c.setRecipientOwnerKey("o2");
when(mockOwnerCurator.lookupByKey(eq("o2"))).thenReturn(o2);
when(uap.canAccess(eq(o2), eq(SubResource.ENTITLEMENTS), eq(Access.CREATE))).thenReturn(Boolean.FALSE);
thrown.expect(NotFoundException.class);
thrown.expectMessage("owner with key");
consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
use of org.candlepin.auth.UserPrincipal in project candlepin by candlepin.
the class ConsumerResourceTest method testNullPerson.
@Test(expected = NotFoundException.class)
public void testNullPerson() {
Owner owner = this.createOwner();
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
Consumer consumer = this.createConsumer(owner, ctype);
ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
UserServiceAdapter usa = mock(UserServiceAdapter.class);
UserPrincipal up = mock(UserPrincipal.class);
when(up.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
// usa.findByLogin() will return null by default no need for a when
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, usa, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
cr.create(consumerDto, up, null, owner.getKey(), null, true);
}
Aggregations