Search in sources :

Example 6 with UserPrincipal

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

the class DatabaseTestFixture method setupPrincipal.

protected Principal setupPrincipal(String username, Owner owner, Access verb) {
    OwnerPermission p = new OwnerPermission(owner, verb);
    // Only need a detached owner permission here:
    Principal ownerAdmin = new UserPrincipal(username, Arrays.asList(new Permission[] { p }), false);
    setupPrincipal(ownerAdmin);
    return ownerAdmin;
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal)

Example 7 with UserPrincipal

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

the class DatabaseTestFixture method setupAdminPrincipal.

protected Principal setupAdminPrincipal(String username) {
    UserPrincipal principal = new UserPrincipal(username, null, true);
    setupPrincipal(principal);
    return principal;
}
Also used : UserPrincipal(org.candlepin.auth.UserPrincipal)

Example 8 with UserPrincipal

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

the class ManifestManagerTest method ensureEventSentWhenManifestGeneratedAndStored.

@Test
public void ensureEventSentWhenManifestGeneratedAndStored() throws Exception {
    Consumer consumer = this.createMockConsumer(true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Event event = mock(Event.class);
    when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
    UserPrincipal principal = TestUtil.createOwnerPrincipal();
    when(principalProvider.get()).thenReturn(principal);
    ManifestFile manifest = mock(ManifestFile.class);
    when(fileService.store(eq(ManifestFileType.EXPORT), any(File.class), eq(principal.getName()), any(String.class))).thenReturn(manifest);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    manager.generateAndStoreManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, new HashMap<>());
    verify(eventFactory).exportCreated(eq(consumer));
    verify(eventSink).queueEvent(eq(event));
}
Also used : Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) UserPrincipal(org.candlepin.auth.UserPrincipal) ManifestFile(org.candlepin.sync.file.ManifestFile) Test(org.junit.Test)

Example 9 with UserPrincipal

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

the class ConsumerCuratorPermissionsTest method setupOnlyMyConsumersPrincipal.

private User setupOnlyMyConsumersPrincipal() {
    Set<Permission> perms = new HashSet<>();
    User u = new User("fakeuser", "dontcare");
    perms.add(new UsernameConsumersPermission(u, owner));
    Principal p = new UserPrincipal(u.getUsername(), perms, false);
    setupPrincipal(p);
    return u;
}
Also used : User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) UserPrincipal(org.candlepin.auth.UserPrincipal) HashSet(java.util.HashSet)

Example 10 with UserPrincipal

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

the class OwnerCuratorPermissionsTest method setUpTestObjects.

@Before
public void setUpTestObjects() {
    owner1 = new Owner("Example Corporation");
    owner2 = new Owner("Example Corporation 2");
    owner3 = new Owner("Example Corporation 3");
    ownerCurator.create(owner1);
    ownerCurator.create(owner2);
    ownerCurator.create(owner3);
    // Setup a principal with access to org 1 and 2, but not 3.
    Set<Permission> perms = new HashSet<>();
    User u = new User("fakeuser", "dontcare");
    perms.add(new UsernameConsumersPermission(u, owner1));
    perms.add(new OwnerPermission(owner1, Access.ALL));
    // just read for org 2
    perms.add(new OwnerPermission(owner2, Access.READ_ONLY));
    principal = new UserPrincipal(u.getUsername(), perms, false);
    setupPrincipal(principal);
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) UserPrincipal(org.candlepin.auth.UserPrincipal) HashSet(java.util.HashSet) Before(org.junit.Before)

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