Search in sources :

Example 6 with Principal

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);
}
Also used : User(org.candlepin.model.User) Method(java.lang.reflect.Method) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 7 with Principal

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);
}
Also used : User(org.candlepin.model.User) Method(java.lang.reflect.Method) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 8 with Principal

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);
}
Also used : Consumer(org.candlepin.model.Consumer) X500Principal(javax.security.auth.x500.X500Principal) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) X509Certificate(java.security.cert.X509Certificate) X500Principal(javax.security.auth.x500.X500Principal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 9 with Principal

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);
}
Also used : Consumer(org.candlepin.model.Consumer) X500Principal(javax.security.auth.x500.X500Principal) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) X509Certificate(java.security.cert.X509Certificate) X500Principal(javax.security.auth.x500.X500Principal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 10 with Principal

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);
}
Also used : EntitlementCurator(org.candlepin.model.EntitlementCurator) OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) UeberCertificate(org.candlepin.model.UeberCertificate) ProductCurator(org.candlepin.model.ProductCurator) UeberCertificateCurator(org.candlepin.model.UeberCertificateCurator) EntitlementCertificateCurator(org.candlepin.model.EntitlementCertificateCurator) UeberCertificateGenerator(org.candlepin.model.UeberCertificateGenerator) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) ConsumerCurator(org.candlepin.model.ConsumerCurator) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) 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