Search in sources :

Example 1 with AccessRequest

use of org.finra.gatekeeper.services.accessrequest.model.AccessRequest in project Gatekeeper by FINRAOS.

the class RevokeAccessServiceTask method execute.

/**
 * @param execution - the request to execute on
 * @throws Exception - if the revocation fails
 */
public void execute(DelegateExecution execution) throws Exception {
    Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    AccessRequest accessRequest = (AccessRequest) execution.getVariable("accessRequest");
    try {
        logger.info("Revoking access for Users, Attempts remaining: " + job.getRetries());
        for (User user : accessRequest.getUsers()) {
            for (UserRole role : accessRequest.getRoles()) {
                databaseConnectionService.revokeAccess(accessRequest.getAwsRdsInstances(), RoleType.valueOf(role.getRole().toUpperCase()), user.getUserId());
            }
        }
    } catch (Exception e) {
        if (job.getRetries() - 1 == 0) {
            logger.error("Maximum attempt limit reached. Notify Ops team for manual removal");
            emailServiceWrapper.notifyOps(accessRequest);
            emailServiceWrapper.notifyAdminsOfFailure(accessRequest, e);
        } else {
            throw e;
        }
    }
}
Also used : User(org.finra.gatekeeper.services.accessrequest.model.User) AccessRequest(org.finra.gatekeeper.services.accessrequest.model.AccessRequest) UserRole(org.finra.gatekeeper.services.accessrequest.model.UserRole) Job(org.activiti.engine.runtime.Job)

Example 2 with AccessRequest

use of org.finra.gatekeeper.services.accessrequest.model.AccessRequest in project Gatekeeper by FINRAOS.

the class GatekeeperAccessRequestHandler method notify.

/**
 * @param delegateTask
 */
public void notify(DelegateTask delegateTask) {
    logger.info("User Task Created");
    AccessRequest obj = (AccessRequest) delegateTask.getExecution().getVariable("accessRequest");
    delegateTask.setOwner(obj.getRequestorId());
}
Also used : AccessRequest(org.finra.gatekeeper.services.accessrequest.model.AccessRequest)

Example 3 with AccessRequest

use of org.finra.gatekeeper.services.accessrequest.model.AccessRequest in project Gatekeeper by FINRAOS.

the class RevokeAccessServiceTests method init.

@Before
public void init() {
    Mockito.when(managementService.createJobQuery()).thenReturn(mockjobQuery);
    Mockito.when(mockjobQuery.processInstanceId(Mockito.anyString())).thenReturn(mockjobQuery);
    Mockito.when(mockjobQuery.singleResult()).thenReturn(mockJobEntity);
    Mockito.when(mockJobEntity.getRetries()).thenReturn(2);
    mockRequest = new AccessRequest().setId(1L).setAccount("test").setRegion("us-east-1").setApproverComments("This is test").setHours(1).setRequestReason("To test this code").setInstances(Arrays.asList(createInstance("i-12345", "numbersInst", "linux", "123.23.3.2", "TST", "Online"), createInstance("i-abcde", "alphasInst", "linux", "123.45.6.7", "TST", "Online"), createInstance("i-123abc", "numbersAlphaInst", "linux", "101.50.4.2", "TST", "Online"), createInstance("i-abc123", "alphaNumbersInst", "linux", "222.34.5,4", "TST", "Online"))).setPlatform("linux").setRequestorEmail("Test@email.com").setRequestorId("reqtest").setRequestorName("Test Requestor").setUsers(Arrays.asList(createUser(1L, "Test Requestor", "reqtest", "Test@email.com")));
    Mockito.when(execution.getVariable(Mockito.any())).thenReturn(mockRequest);
}
Also used : AccessRequest(org.finra.gatekeeper.services.accessrequest.model.AccessRequest) Before(org.junit.Before)

Example 4 with AccessRequest

use of org.finra.gatekeeper.services.accessrequest.model.AccessRequest in project Gatekeeper by FINRAOS.

the class AccessRequestService method updateRequestApproverComments.

/**
 * Updates the request comments for the access request
 *
 * TODO: If more changes needed then we should probably make this more generic.. I Doubt it though.
 * @param requestId
 * @param approverComments
 */
private void updateRequestApproverComments(Long requestId, String approverComments) {
    AccessRequest accessRequest = accessRequestRepository.findOne(requestId);
    accessRequest.setApproverComments(approverComments);
    accessRequestRepository.save(accessRequest);
}
Also used : AccessRequest(org.finra.gatekeeper.services.accessrequest.model.AccessRequest)

Example 5 with AccessRequest

use of org.finra.gatekeeper.services.accessrequest.model.AccessRequest in project Gatekeeper by FINRAOS.

the class AccessRequestService method updateInstanceStatus.

public AccessRequest updateInstanceStatus(AccessRequest accessRequest) {
    AWSEnvironment environment = new AWSEnvironment(accessRequest.getAccount(), accessRequest.getRegion());
    List<AWSInstance> requestedInstances = accessRequest.getInstances();
    List<String> instanceIds = requestedInstances.stream().map(instance -> instance.getInstanceId()).collect(Collectors.toList());
    Map<String, String> instances = ssmService.checkInstancesWithSsm(environment, instanceIds);
    requestedInstances.forEach(instance -> instance.setStatus(instances.get(instance.getInstanceId()) != null ? instances.get(instance.getInstanceId()) : "Unknown"));
    accessRequest.setInstances(requestedInstances);
    accessRequestRepository.save(accessRequest);
    return accessRequest;
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) GatekeeperRoleService(org.finra.gatekeeper.services.auth.GatekeeperRoleService) AccessRequestWrapper(org.finra.gatekeeper.controllers.wrappers.AccessRequestWrapper) AccessRequest(org.finra.gatekeeper.services.accessrequest.model.AccessRequest) java.util(java.util) TaskService(org.activiti.engine.TaskService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveAccessRequestWrapper(org.finra.gatekeeper.controllers.wrappers.ActiveAccessRequestWrapper) GatekeeperApprovalProperties(org.finra.gatekeeper.configuration.properties.GatekeeperApprovalProperties) GatekeeperUserEntry(org.finra.gatekeeper.common.services.user.model.GatekeeperUserEntry) AWSInstance(org.finra.gatekeeper.services.accessrequest.model.AWSInstance) Account(org.finra.gatekeeper.common.services.account.model.Account) CompletedAccessRequestWrapper(org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper) HistoryService(org.activiti.engine.HistoryService) Task(org.activiti.engine.task.Task) AccessRequestRepository(org.finra.gatekeeper.services.accessrequest.model.AccessRequestRepository) Logger(org.slf4j.Logger) GatekeeperException(org.finra.gatekeeper.exception.GatekeeperException) Collectors(java.util.stream.Collectors) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) AccountInformationService(org.finra.gatekeeper.common.services.account.AccountInformationService) RequestStatus(org.finra.gatekeeper.services.accessrequest.model.RequestStatus) Component(org.springframework.stereotype.Component) AccessRequestController(org.finra.gatekeeper.controllers.AccessRequestController) SsmService(org.finra.gatekeeper.services.aws.SsmService) GatekeeperRole(org.finra.gatekeeper.services.auth.GatekeeperRole) AWSEnvironment(org.finra.gatekeeper.services.aws.model.AWSEnvironment) AWSInstance(org.finra.gatekeeper.services.accessrequest.model.AWSInstance) AWSEnvironment(org.finra.gatekeeper.services.aws.model.AWSEnvironment)

Aggregations

AccessRequest (org.finra.gatekeeper.services.accessrequest.model.AccessRequest)5 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 HistoryService (org.activiti.engine.HistoryService)1 RuntimeService (org.activiti.engine.RuntimeService)1 TaskService (org.activiti.engine.TaskService)1 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)1 Job (org.activiti.engine.runtime.Job)1 Task (org.activiti.engine.task.Task)1 AccountInformationService (org.finra.gatekeeper.common.services.account.AccountInformationService)1 Account (org.finra.gatekeeper.common.services.account.model.Account)1 GatekeeperUserEntry (org.finra.gatekeeper.common.services.user.model.GatekeeperUserEntry)1 GatekeeperApprovalProperties (org.finra.gatekeeper.configuration.properties.GatekeeperApprovalProperties)1 AccessRequestController (org.finra.gatekeeper.controllers.AccessRequestController)1 AccessRequestWrapper (org.finra.gatekeeper.controllers.wrappers.AccessRequestWrapper)1 ActiveAccessRequestWrapper (org.finra.gatekeeper.controllers.wrappers.ActiveAccessRequestWrapper)1 CompletedAccessRequestWrapper (org.finra.gatekeeper.controllers.wrappers.CompletedAccessRequestWrapper)1 GatekeeperException (org.finra.gatekeeper.exception.GatekeeperException)1 AWSInstance (org.finra.gatekeeper.services.accessrequest.model.AWSInstance)1 AccessRequestRepository (org.finra.gatekeeper.services.accessrequest.model.AccessRequestRepository)1