Search in sources :

Example 1 with PermissionCheckingService

use of org.cloudfoundry.credhub.service.PermissionCheckingService in project credhub by cloudfoundry-incubator.

the class CredentialsHandlerTest method beforeEach.

@Before
public void beforeEach() {
    Encryptor encryptor = mock(Encryptor.class);
    permissionedCredentialService = mock(PermissionedCredentialService.class);
    permissionCheckingService = mock(PermissionCheckingService.class);
    subject = new CredentialsHandler(permissionedCredentialService);
    userContext = mock(UserContext.class);
    when(userContext.getActor()).thenReturn(USER);
    version1 = new SshCredentialVersion(CREDENTIAL_NAME);
    version1.setVersionCreatedAt(VERSION1_CREATED_AT);
    version1.setEncryptor(encryptor);
    version2 = new SshCredentialVersion(CREDENTIAL_NAME);
    version2.setVersionCreatedAt(VERSION2_CREATED_AT);
    version2.setEncryptor(encryptor);
}
Also used : PermissionCheckingService(org.cloudfoundry.credhub.service.PermissionCheckingService) PermissionedCredentialService(org.cloudfoundry.credhub.service.PermissionedCredentialService) UserContext(org.cloudfoundry.credhub.auth.UserContext) Encryptor(org.cloudfoundry.credhub.domain.Encryptor) SshCredentialVersion(org.cloudfoundry.credhub.domain.SshCredentialVersion) Before(org.junit.Before)

Example 2 with PermissionCheckingService

use of org.cloudfoundry.credhub.service.PermissionCheckingService in project credhub by cloudfoundry-incubator.

the class CertificateGeneratorTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    TestHelper.getBouncyCastleProvider();
    keyGenerator = mock(LibcryptoRsaKeyPairGenerator.class);
    signedCertificateGenerator = mock(SignedCertificateGenerator.class);
    certificateAuthorityService = mock(CertificateAuthorityService.class);
    permissionCheckingService = mock(PermissionCheckingService.class);
    userContext = mock(UserContext.class);
    subject = new CertificateGenerator(keyGenerator, signedCertificateGenerator, certificateAuthorityService);
    when(permissionCheckingService.hasPermission(anyString(), anyString(), any())).thenReturn(true);
    fakeKeyPairGenerator = new FakeKeyPairGenerator();
    rootCaDn = new X500Name("O=foo,ST=bar,C=root");
    signeeDn = new X500Name("O=foo,ST=bar,C=mars");
    rootCaKeyPair = fakeKeyPairGenerator.generate();
    X509CertificateHolder caX509CertHolder = makeCert(rootCaKeyPair, rootCaKeyPair.getPrivate(), rootCaDn, rootCaDn, true);
    rootCaX509Certificate = new JcaX509CertificateConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME).getCertificate(caX509CertHolder);
    rootCa = new CertificateCredentialValue(null, CertificateFormatter.pemOf(rootCaX509Certificate), CertificateFormatter.pemOf(rootCaKeyPair.getPrivate()), null);
    generationParameters = new CertificateGenerationRequestParameters();
    generationParameters.setOrganization("foo");
    generationParameters.setState("bar");
    generationParameters.setCaName("my-ca-name");
    generationParameters.setCountry("mars");
    generationParameters.setDuration(365);
    inputParameters = new CertificateGenerationParameters(generationParameters);
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) CertificateAuthorityService(org.cloudfoundry.credhub.data.CertificateAuthorityService) X500Name(org.bouncycastle.asn1.x500.X500Name) CertificateGenerationRequestParameters(org.cloudfoundry.credhub.request.CertificateGenerationRequestParameters) PermissionCheckingService(org.cloudfoundry.credhub.service.PermissionCheckingService) CertificateGenerationParameters(org.cloudfoundry.credhub.domain.CertificateGenerationParameters) JcaX509CertificateConverter(org.bouncycastle.cert.jcajce.JcaX509CertificateConverter) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) X509CertificateHolder(org.bouncycastle.cert.X509CertificateHolder) Before(org.junit.Before)

Example 3 with PermissionCheckingService

use of org.cloudfoundry.credhub.service.PermissionCheckingService in project credhub by cloudfoundry-incubator.

the class CertificateAuthorityServiceTest method beforeEach.

@Before
public void beforeEach() {
    certificate = new CertificateCredentialValue(null, CertificateStringConstants.SELF_SIGNED_CA_CERT, "my-key", null);
    certificateCredential = mock(CertificateCredentialVersion.class);
    permissionCheckingService = mock(PermissionCheckingService.class);
    userContext = mock(UserContext.class);
    when(userContext.getActor()).thenReturn(USER_NAME);
    when(certificateCredential.getName()).thenReturn(CREDENTIAL_NAME);
    when(permissionCheckingService.hasPermission(USER_NAME, CREDENTIAL_NAME, PermissionOperation.READ)).thenReturn(true);
    certificateVersionDataService = mock(CertificateVersionDataService.class);
    UserContextHolder userContextHolder = new UserContextHolder();
    userContextHolder.setUserContext(userContext);
    certificateAuthorityService = new CertificateAuthorityService(certificateVersionDataService, permissionCheckingService, userContextHolder);
}
Also used : PermissionCheckingService(org.cloudfoundry.credhub.service.PermissionCheckingService) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Before(org.junit.Before)

Example 4 with PermissionCheckingService

use of org.cloudfoundry.credhub.service.PermissionCheckingService in project credhub by cloudfoundry-incubator.

the class CertificatesHandlerTest method beforeEach.

@Before
public void beforeEach() {
    Encryptor encryptor = mock(Encryptor.class);
    permissionedCertificateService = mock(PermissionedCertificateService.class);
    permissionCheckingService = mock(PermissionCheckingService.class);
    certificateService = mock(CertificateService.class);
    universalCredentialGenerator = mock(UniversalCredentialGenerator.class);
    generationRequestGenerator = mock(GenerationRequestGenerator.class);
    subject = new CertificatesHandler(permissionedCertificateService, certificateService, universalCredentialGenerator, generationRequestGenerator);
    userContext = mock(UserContext.class);
    when(userContext.getActor()).thenReturn(USER);
}
Also used : PermissionCheckingService(org.cloudfoundry.credhub.service.PermissionCheckingService) PermissionedCertificateService(org.cloudfoundry.credhub.service.PermissionedCertificateService) UserContext(org.cloudfoundry.credhub.auth.UserContext) PermissionedCertificateService(org.cloudfoundry.credhub.service.PermissionedCertificateService) CertificateService(org.cloudfoundry.credhub.service.CertificateService) Encryptor(org.cloudfoundry.credhub.domain.Encryptor) Before(org.junit.Before)

Aggregations

UserContext (org.cloudfoundry.credhub.auth.UserContext)4 PermissionCheckingService (org.cloudfoundry.credhub.service.PermissionCheckingService)4 Before (org.junit.Before)4 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)2 Encryptor (org.cloudfoundry.credhub.domain.Encryptor)2 X500Name (org.bouncycastle.asn1.x500.X500Name)1 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)1 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)1 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)1 CertificateAuthorityService (org.cloudfoundry.credhub.data.CertificateAuthorityService)1 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)1 CertificateGenerationParameters (org.cloudfoundry.credhub.domain.CertificateGenerationParameters)1 SshCredentialVersion (org.cloudfoundry.credhub.domain.SshCredentialVersion)1 CertificateGenerationRequestParameters (org.cloudfoundry.credhub.request.CertificateGenerationRequestParameters)1 CertificateService (org.cloudfoundry.credhub.service.CertificateService)1 PermissionedCertificateService (org.cloudfoundry.credhub.service.PermissionedCertificateService)1 PermissionedCredentialService (org.cloudfoundry.credhub.service.PermissionedCredentialService)1