use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class AuthenticationFilterTest method securityHoleWithAuth.
@Test
public void securityHoleWithAuth() throws Exception {
Method method = FakeResource.class.getMethod("annotatedMethod", String.class);
mockResourceMethod(method);
mockReq.header("Authorization", "BASIC QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
when(usa.validateUser(eq("Aladdin"), eq("open sesame"))).thenReturn(true);
when(usa.findByLogin(eq("Aladdin"))).thenReturn(new User("Aladdin", "open sesame"));
interceptor.filter(getContext());
Principal p = ResteasyProviderFactory.getContextData(Principal.class);
assertTrue(p instanceof UserPrincipal);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class AuthenticationFilterTest method noSecurityHole.
@Test
public void noSecurityHole() throws Exception {
mockReq.header("Authorization", "BASIC QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
when(usa.validateUser(eq("Aladdin"), eq("open sesame"))).thenReturn(true);
when(usa.findByLogin(eq("Aladdin"))).thenReturn(new User("Aladdin", "open sesame", true));
Method method = FakeResource.class.getMethod("someMethod", String.class);
mockResourceMethod(method);
interceptor.filter(getContext());
Principal p = ResteasyProviderFactory.getContextData(Principal.class);
assertTrue(p instanceof UserPrincipal);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class VerifyAuthorizationFilterTest method noAccessToOtherConsumer.
@Test(expected = ForbiddenException.class)
public void noAccessToOtherConsumer() throws Exception {
mockReq = MockHttpRequest.create("POST", "http://localhost/candlepin/fake/123");
ResteasyProviderFactory.pushContext(HttpRequest.class, mockReq);
mockReq.setAttribute(ResteasyProviderFactory.class.getName(), ResteasyProviderFactory.getInstance());
Consumer c = createConsumer(createOwner());
Consumer c2 = createConsumer(createOwner());
methodInjector.setArguments(new Object[] { c2.getUuid() });
X500Principal dn = new X500Principal("CN=" + c.getUuid() + ", C=US, L=Raleigh");
// create mock certs to trigger SSLAuth provider
X509Certificate[] certs = new X509Certificate[1];
X509Certificate cert = mock(X509Certificate.class);
when(cert.getSubjectX500Principal()).thenReturn(dn);
certs[0] = cert;
mockReq.setAttribute("javax.servlet.request.X509Certificate", certs);
Principal p = sslAuth.getPrincipal(mockReq);
when(mockSecurityContext.getUserPrincipal()).thenReturn(p);
interceptor.filter(mockRequestContext);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class VerifyAuthorizationFilterTest method testAccessToConsumer.
@Test
public void testAccessToConsumer() throws Exception {
mockReq = MockHttpRequest.create("POST", "http://localhost/candlepin/fake/123");
ResteasyProviderFactory.pushContext(HttpRequest.class, mockReq);
mockReq.setAttribute(ResteasyProviderFactory.class.getName(), ResteasyProviderFactory.getInstance());
Consumer c = createConsumer(createOwner());
methodInjector.setArguments(new Object[] { c.getUuid() });
X500Principal dn = new X500Principal("CN=" + c.getUuid() + ", C=US, L=Raleigh");
// create mock certs to trigger SSLAuth provider
X509Certificate[] certs = new X509Certificate[1];
X509Certificate cert = mock(X509Certificate.class);
when(cert.getSubjectX500Principal()).thenReturn(dn);
certs[0] = cert;
mockReq.setAttribute("javax.servlet.request.X509Certificate", certs);
Principal p = sslAuth.getPrincipal(mockReq);
when(mockSecurityContext.getUserPrincipal()).thenReturn(p);
interceptor.filter(mockRequestContext);
}
use of org.candlepin.auth.Principal in project candlepin by candlepin.
the class OwnerResourceTest method testCreateUeberCertificateFromScratch.
@Test
public void testCreateUeberCertificateFromScratch() {
Principal principal = setupPrincipal(owner, Access.ALL);
Owner owner = TestUtil.createOwner();
UeberCertificate entCert = mock(UeberCertificate.class);
OwnerCurator oc = mock(OwnerCurator.class);
ProductCurator pc = mock(ProductCurator.class);
ConsumerCurator cc = mock(ConsumerCurator.class);
EntitlementCurator ec = mock(EntitlementCurator.class);
CandlepinPoolManager cpm = mock(CandlepinPoolManager.class);
EntitlementCertificateCurator ecc = mock(EntitlementCertificateCurator.class);
UeberCertificateCurator uc = mock(UeberCertificateCurator.class);
UeberCertificateGenerator ucg = mock(UeberCertificateGenerator.class);
OwnerResource resource = new OwnerResource(oc, pc, null, cc, i18n, null, null, null, null, null, cpm, null, null, null, null, null, ecc, ec, uc, ucg, null, null, null, null, null, null, null, null, null, this.modelTranslator);
when(oc.lookupByKey(eq("admin"))).thenReturn(owner);
when(ucg.generate(eq(owner.getKey()), eq(principal))).thenReturn(entCert);
UeberCertificate result = resource.createUeberCertificate(principal, owner.getKey());
assertEquals(entCert, result);
}
Aggregations