Search in sources :

Example 11 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class OwnerResourceTest method ownerAdminCannotAccessAnotherOwnersPools.

@Test(expected = NotFoundException.class)
public void ownerAdminCannotAccessAnotherOwnersPools() {
    Owner evilOwner = new Owner("evilowner");
    ownerCurator.create(evilOwner);
    Principal principal = setupPrincipal(evilOwner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    Pool pool2 = TestUtil.createPool(owner, p);
    poolCurator.create(pool1);
    poolCurator.create(pool2);
    securityInterceptor.enable();
    // Filtering should just cause this to return no results:
    ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 12 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PoolResourceTest method consumerCannotListPoolsForAnotherOwner.

@Test(expected = NotFoundException.class)
public void consumerCannotListPoolsForAnotherOwner() {
    Principal p = setupPrincipal(new ConsumerPrincipal(foreignConsumer, owner2));
    securityInterceptor.enable();
    poolResource.list(owner1.getId(), null, null, false, null, p, null);
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 13 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class PoolResourceTest method ownerAdminCannotListAnotherOwnersPools.

@Test(expected = NotFoundException.class)
public void ownerAdminCannotListAnotherOwnersPools() {
    List<PoolDTO> pools = poolResource.list(owner1.getId(), null, null, false, null, adminPrincipal, null);
    assertEquals(2, pools.size());
    Principal anotherPrincipal = setupPrincipal(owner2, Access.ALL);
    securityInterceptor.enable();
    poolResource.list(owner1.getId(), null, null, false, null, anotherPrincipal, null);
}
Also used : PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 14 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class UserResourceTest method testListOwnersForMySystemsAdmin.

@Test
public void testListOwnersForMySystemsAdmin() {
    User user = new User();
    user.setUsername("dummyuser" + TestUtil.randomInt());
    user.setPassword("password");
    userResource.createUser(user);
    Owner owner1 = createOwner();
    Role owner1Role = new Role(owner1.getKey() + " role");
    owner1Role.addPermission(new PermissionBlueprint(PermissionType.USERNAME_CONSUMERS, owner1, Access.ALL));
    owner1Role.addUser(user);
    roleCurator.create(owner1Role);
    Set<Permission> perms = new HashSet<>();
    perms.add(new UsernameConsumersPermission(user, owner1));
    Principal userPrincipal = new UserPrincipal(user.getUsername(), perms, false);
    Iterable<Owner> response = userResource.listUsersOwners(user.getUsername(), userPrincipal);
    List<Owner> owners = new LinkedList<>();
    for (Object entity : response) {
        owners.add((Owner) entity);
    }
    assertEquals(1, owners.size());
    assertEquals(owner1.getKey(), owners.get(0).getKey());
}
Also used : Owner(org.candlepin.model.Owner) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) LinkedList(java.util.LinkedList) Role(org.candlepin.model.Role) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) UsernameConsumersPermission(org.candlepin.auth.permissions.UsernameConsumersPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with Principal

use of org.candlepin.auth.Principal in project candlepin by candlepin.

the class ExporterTest method exportConsumer.

@Test
public void exportConsumer() throws ExportCreationException, IOException {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
    config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
    Rules mrules = mock(Rules.class);
    Consumer consumer = mock(Consumer.class);
    Principal principal = mock(Principal.class);
    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");
    // specific to this test
    IdentityCertificate idcert = new IdentityCertificate();
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype");
    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
    when(consumer.getUuid()).thenReturn("8auuid");
    when(consumer.getName()).thenReturn("consumer_name");
    when(consumer.getContentAccessMode()).thenReturn("access_mode");
    when(consumer.getTypeId()).thenReturn(ctype.getId());
    when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
    when(ctc.listAll()).thenReturn(cqmock);
    CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
    when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
    when(cdnc.listAll()).thenReturn(emptyIteratorMock);
    // FINALLY test this badboy
    Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
    File export = e.getFullExport(consumer);
    verifyContent(export, "export/consumer.json", new VerifyConsumer("consumer.json"));
}
Also used : KeyPair(org.candlepin.model.KeyPair) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CertificateSerial(org.candlepin.model.CertificateSerial) CandlepinQuery(org.candlepin.model.CandlepinQuery) Rules(org.candlepin.model.Rules) ExportRules(org.candlepin.policy.js.export.ExportRules) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) File(java.io.File) Principal(org.candlepin.auth.Principal) IdentityCertificate(org.candlepin.model.IdentityCertificate) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Aggregations

Principal (org.candlepin.auth.Principal)74 Test (org.junit.Test)54 UserPrincipal (org.candlepin.auth.UserPrincipal)40 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)20 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)17 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)15 Consumer (org.candlepin.model.Consumer)15 Owner (org.candlepin.model.Owner)15 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)14 Date (java.util.Date)12 ConsumerType (org.candlepin.model.ConsumerType)11 HashSet (java.util.HashSet)10 Pool (org.candlepin.model.Pool)10 JobDetail (org.quartz.JobDetail)10 Method (java.lang.reflect.Method)9 Permission (org.candlepin.auth.permissions.Permission)9 JobDataMap (org.quartz.JobDataMap)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)8 File (java.io.File)7 FileInputStream (java.io.FileInputStream)7