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());
}
}
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);
}
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);
}
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());
}
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));
}
Aggregations