Search in sources :

Example 1 with UserContextHolder

use of org.cloudfoundry.credhub.auth.UserContextHolder in project credhub by cloudfoundry-incubator.

the class PermissionCheckingServiceTest method beforeEach.

@Before
public void beforeEach() {
    userContext = mock(UserContext.class);
    when(userContext.getActor()).thenReturn("test-actor");
    permissionDataService = mock(PermissionDataService.class);
    UserContextHolder userContextHolder = new UserContextHolder();
    userContextHolder.setUserContext(userContext);
    subject = new PermissionCheckingService(permissionDataService, userContextHolder);
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) PermissionDataService(org.cloudfoundry.credhub.data.PermissionDataService) Before(org.junit.Before)

Example 2 with UserContextHolder

use of org.cloudfoundry.credhub.auth.UserContextHolder in project credhub by cloudfoundry-incubator.

the class UserContextInterceptorTest method setup.

@Before
public void setup() {
    userContextFactory = mock(UserContextFactory.class);
    userContext = mock(UserContext.class);
    userContextHolder = new UserContextHolder();
    subject = new UserContextInterceptor(userContextFactory, userContextHolder);
    when(userContextFactory.createUserContext(any())).thenReturn(userContext);
    request = mock(HttpServletRequest.class);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextFactory(org.cloudfoundry.credhub.auth.UserContextFactory) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) Before(org.junit.Before)

Example 3 with UserContextHolder

use of org.cloudfoundry.credhub.auth.UserContextHolder in project credhub by cloudfoundry-incubator.

the class CertificateServiceTest method setup.

@Before
public void setup() {
    initMocks(this);
    auditRecordParameters = new ArrayList<>();
    userContext = mock(UserContext.class);
    userContextHolder = new UserContextHolder();
    userContextHolder.setUserContext(userContext);
    subject = new CertificateService(certificateVersionDataService, permissionCheckingService, userContextHolder);
    credentialVersion.createName(credentialName);
    when(userContext.getActor()).thenReturn(actor);
    when(certificateVersionDataService.findByCredentialUUID(credentialUuid)).thenReturn(credentialVersion);
}
Also used : UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) Before(org.junit.Before)

Example 4 with UserContextHolder

use of org.cloudfoundry.credhub.auth.UserContextHolder in project credhub by cloudfoundry-incubator.

the class PermissionServiceTest method beforeEach.

@Before
public void beforeEach() {
    userContext = mock(UserContext.class);
    when(userContext.getActor()).thenReturn(USER_NAME);
    expectedCredential = new Credential(CREDENTIAL_NAME);
    expectedCredentialVersion = new PasswordCredentialVersion(CREDENTIAL_NAME);
    permissionDataService = mock(PermissionDataService.class);
    permissionCheckingService = mock(PermissionCheckingService.class);
    when(permissionCheckingService.hasPermission(anyString(), anyString(), any(PermissionOperation.class))).thenReturn(true);
    auditRecordParameters = newArrayList();
    UserContextHolder userContextHolder = new UserContextHolder();
    userContextHolder.setUserContext(userContext);
    subject = new PermissionService(permissionDataService, permissionCheckingService, userContextHolder);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) PermissionOperation(org.cloudfoundry.credhub.request.PermissionOperation) UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) PermissionDataService(org.cloudfoundry.credhub.data.PermissionDataService) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) Before(org.junit.Before)

Example 5 with UserContextHolder

use of org.cloudfoundry.credhub.auth.UserContextHolder in project credhub by cloudfoundry-incubator.

the class PermissionedCredentialServiceTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    userContext = mock(UserContext.class);
    UserContextHolder userContextHolder = new UserContextHolder();
    userContextHolder.setUserContext(userContext);
    subject = new PermissionedCredentialService(credentialVersionDataService, credentialFactory, permissionCheckingService, certificateAuthorityService, userContextHolder, credentialDataService);
    auditRecordParameters = new ArrayList<>();
    generationParameters = mock(StringGenerationParameters.class);
    credentialValue = mock(CredentialValue.class);
    credential = new Credential(CREDENTIAL_NAME);
    accessControlEntries = new ArrayList<>();
    when(userContext.getActor()).thenReturn(USER);
    existingCredentialVersion = new PasswordCredentialVersion(CREDENTIAL_NAME);
    existingCredentialVersion.setEncryptor(encryptor);
    when(permissionCheckingService.hasPermission(USER, CREDENTIAL_NAME, READ)).thenReturn(true);
    when(permissionCheckingService.hasPermission(USER, CREDENTIAL_NAME, WRITE)).thenReturn(true);
    when(credentialDataService.findByUUID(CREDENTIAL_UUID)).thenReturn(credential);
    when(credentialVersionDataService.findByUuid(VERSION_UUID_STRING)).thenReturn(existingCredentialVersion);
    when(request.getName()).thenReturn(CREDENTIAL_NAME);
    when(request.getGenerationParameters()).thenReturn(generationParameters);
    when(request.getAdditionalPermissions()).thenReturn(accessControlEntries);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) CredentialValue(org.cloudfoundry.credhub.credential.CredentialValue) UserContext(org.cloudfoundry.credhub.auth.UserContext) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters) Before(org.junit.Before)

Aggregations

UserContext (org.cloudfoundry.credhub.auth.UserContext)7 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)7 Before (org.junit.Before)7 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)3 PermissionDataService (org.cloudfoundry.credhub.data.PermissionDataService)2 Credential (org.cloudfoundry.credhub.entity.Credential)2 StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 UserContextFactory (org.cloudfoundry.credhub.auth.UserContextFactory)1 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)1 CredentialValue (org.cloudfoundry.credhub.credential.CredentialValue)1 CertificateAuthorityService (org.cloudfoundry.credhub.data.CertificateAuthorityService)1 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)1 PermissionOperation (org.cloudfoundry.credhub.request.PermissionOperation)1 PermissionCheckingService (org.cloudfoundry.credhub.service.PermissionCheckingService)1 PermissionService (org.cloudfoundry.credhub.service.PermissionService)1 PermissionedCredentialService (org.cloudfoundry.credhub.service.PermissionedCredentialService)1