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;
}
}
}
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());
}
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);
}
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);
}
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;
}
Aggregations