Search in sources :

Example 1 with ConsumerPrincipal

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

the class ConsumerCheckInFilter method filter.

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    ResourceInfo resourceInfo = ResteasyProviderFactory.getContextData(ResourceInfo.class);
    Method method = resourceInfo.getResourceMethod();
    Principal principal = ResteasyProviderFactory.getContextData(Principal.class);
    if (principal instanceof ConsumerPrincipal && method.getAnnotation(UpdateConsumerCheckIn.class) != null) {
        ConsumerPrincipal p = (ConsumerPrincipal) principal;
        consumerCurator.updateLastCheckin(p.getConsumer());
    }
}
Also used : ResourceInfo(javax.ws.rs.container.ResourceInfo) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Method(java.lang.reflect.Method) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Principal(org.candlepin.auth.Principal)

Example 2 with ConsumerPrincipal

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

the class ConsumerCheckInFilterTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Class clazz = FakeResource.class;
    when(mockInfo.getResourceClass()).thenReturn(clazz);
    mockReq = MockHttpRequest.create("GET", "http://localhost/candlepin/status");
    Owner owner = createOwner();
    this.consumer = createConsumer(owner);
    this.principal = new ConsumerPrincipal(consumer, owner);
    ResteasyProviderFactory.pushContext(ResourceInfo.class, mockInfo);
    ResteasyProviderFactory.pushContext(Principal.class, this.principal);
    interceptor = new ConsumerCheckInFilter(consumerCurator);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Before(org.junit.Before)

Example 3 with ConsumerPrincipal

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

the class ConsumerCheckInFilterTest method testNoCheckinWithoutAnnotation.

@Test
public void testNoCheckinWithoutAnnotation() throws Exception {
    Date lastCheckin = this.consumer.getLastCheckin();
    Thread.sleep(1000);
    Method method = FakeResource.class.getMethod("someMethod", String.class);
    mockResourceMethod(method);
    interceptor.filter(getContext());
    ConsumerPrincipal p = (ConsumerPrincipal) ResteasyProviderFactory.getContextData(Principal.class);
    this.consumerCurator.refresh(this.consumer);
    Date updatedLastCheckin = p.getConsumer().getLastCheckin();
    assertEquals(lastCheckin, updatedLastCheckin);
}
Also used : ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Method(java.lang.reflect.Method) Date(java.util.Date) Principal(org.candlepin.auth.Principal) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 4 with ConsumerPrincipal

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

the class OwnerResourceTest method testConsumerRoleCannotGetOwner.

@Test(expected = ForbiddenException.class)
public void testConsumerRoleCannotGetOwner() {
    Consumer c = createConsumer(owner);
    setupPrincipal(new ConsumerPrincipal(c, owner));
    securityInterceptor.enable();
    ownerResource.getOwner(owner.getKey());
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 5 with ConsumerPrincipal

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

the class PoolResourceTest method testListConsumerFiltering.

@Test
public void testListConsumerFiltering() {
    setupPrincipal(new ConsumerPrincipal(passConsumer, owner1));
    List<PoolDTO> pools = poolResource.list(null, passConsumer.getUuid(), null, false, null, adminPrincipal, null);
    assertEquals(2, pools.size());
    verify(attrUtil, times(1)).setCalculatedAttributes((List<Pool>) argThat(IsCollectionWithSize.hasSize(2)), any(Date.class));
}
Also used : PoolDTO(org.candlepin.dto.api.v1.PoolDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Pool(org.candlepin.model.Pool) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)27 Test (org.junit.Test)25 Consumer (org.candlepin.model.Consumer)11 Principal (org.candlepin.auth.Principal)9 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 Date (java.util.Date)4 Method (java.lang.reflect.Method)3 UserPrincipal (org.candlepin.auth.UserPrincipal)3 PoolDTO (org.candlepin.dto.api.v1.PoolDTO)3 Pool (org.candlepin.model.Pool)3 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)3 Product (org.candlepin.model.Product)2 ResourceInfo (javax.ws.rs.container.ResourceInfo)1 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1 IdentityCertificate (org.candlepin.model.IdentityCertificate)1 Owner (org.candlepin.model.Owner)1 Before (org.junit.Before)1