Search in sources :

Example 11 with UserPrincipal

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;
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Owner(org.candlepin.model.Owner) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) ArrayList(java.util.ArrayList) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal)

Example 12 with UserPrincipal

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));
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Before(org.junit.Before)

Example 13 with UserPrincipal

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());
}
Also used : User(org.candlepin.model.User) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 14 with UserPrincipal

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);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 15 with UserPrincipal

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);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) UserServiceAdapter(org.candlepin.service.UserServiceAdapter) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

UserPrincipal (org.candlepin.auth.UserPrincipal)30 Test (org.junit.Test)18 Owner (org.candlepin.model.Owner)16 Principal (org.candlepin.auth.Principal)14 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)10 User (org.candlepin.model.User)10 Permission (org.candlepin.auth.permissions.Permission)9 HashSet (java.util.HashSet)7 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)7 ConsumerType (org.candlepin.model.ConsumerType)6 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)5 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)4 Consumer (org.candlepin.model.Consumer)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)3 UsernameConsumersPermission (org.candlepin.auth.permissions.UsernameConsumersPermission)3 Role (org.candlepin.model.Role)3 ManifestFile (org.candlepin.sync.file.ManifestFile)3 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)3