Search in sources :

Example 26 with Principal

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

the class PinsetterJobListenerTest method bug863518ToBeExecuted.

@Test
public void bug863518ToBeExecuted() {
    Principal principal = mock(Principal.class);
    JobDataMap map = new JobDataMap();
    JobDetail detail = mock(JobDetail.class);
    map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
    when(ctx.getMergedJobDataMap()).thenReturn(map);
    when(detail.getKey()).thenReturn(jobKey("foo"));
    when(ctx.getJobDetail()).thenReturn(detail);
    when(jcurator.find(any(String.class))).thenThrow(new RuntimeException());
    try {
        listener.jobToBeExecuted(ctx);
    } catch (RuntimeException re) {
    // do nothing, we're really trying to verify end is called
    }
    verify(unitOfWork, atLeastOnce()).end();
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 27 with Principal

use of org.candlepin.auth.Principal 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 28 with Principal

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

the class ConsumerResourceCreationTest method orgRequiredWithActivationKeys.

@Test(expected = BadRequestException.class)
public void orgRequiredWithActivationKeys() {
    Principal p = new NoAuthPrincipal();
    List<String> keys = mockActivationKeys();
    ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
    resource.create(consumer, p, null, null, createKeysString(keys), true);
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 29 with Principal

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

the class ConsumerResourceCreationTest method oauthRegistrationSupported.

@Test
public void oauthRegistrationSupported() {
    // Should be able to register successfully with as a trusted user principal:
    Principal p = new TrustedUserPrincipal("anyuser");
    ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
    resource.create(consumer, p, null, owner.getKey(), null, true);
}
Also used : TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) Test(org.junit.Test)

Example 30 with Principal

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

the class ConsumerResourceCreationTest method registerWithKeys.

@Test
public void registerWithKeys() {
    // No auth should be required for registering with keys:
    Principal p = new NoAuthPrincipal();
    List<String> keys = mockActivationKeys();
    ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, systemDto);
    resource.create(consumer, p, null, owner.getKey(), createKeysString(keys), true);
    for (String keyName : keys) {
        verify(activationKeyCurator).lookupForOwner(keyName, owner);
    }
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) 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