Skip to content

Commit

Permalink
Added all resource validators
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnjau committed Oct 30, 2024
1 parent 3f4e465 commit 57deacf
Show file tree
Hide file tree
Showing 10 changed files with 768 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.google.fhir.gateway.resource_validators;

import com.google.fhir.gateway.ApiServiceImpl;
import com.google.fhir.gateway.FormatterClass;
import com.google.fhir.gateway.OpenChanjoRoles;
import com.google.fhir.gateway.interfaces.*;
import com.google.fhir.gateway.validators.ResourceRoleValidator;
import jakarta.servlet.http.HttpServletRequest;
import retrofit2.Call;

import java.util.Set;

public class AdverseEventResourceValidator implements AccessChecker, ResourceValidator {

private final ApiServiceImpl apiService = new ApiServiceImpl();
private final FormatterClass formatter = new FormatterClass();

// Define allowed roles for different operations
private final Set<String> createAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name()
);
private final Set<String> updateAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name()
);
private final Set<String> deleteAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name()
);
private final Set<String> getAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name(),
OpenChanjoRoles.ADMINISTRATOR.name(),
OpenChanjoRoles.NATIONAL_SYSTEM_ADMINISTRATOR.name()
);

private final Set<String> testAllowedRoles = Set.of(OpenChanjoRoles.FACILITY_SYSTEM_ADMINISTRATOR.name());

// Instantiate role validators dynamically
private final RoleValidator createResourceRoleValidator = new ResourceRoleValidator(createAllowedRoles);
private final RoleValidator updateResourceRoleValidator = new ResourceRoleValidator(updateAllowedRoles);
private final RoleValidator deleteResourceRoleValidator = new ResourceRoleValidator(deleteAllowedRoles);
private final RoleValidator getResourceRoleValidator = new ResourceRoleValidator(getAllowedRoles);
private final RoleValidator testResourceRoleValidator = new ResourceRoleValidator(testAllowedRoles);



@Override
public AccessDecision checkAccess(RequestDetailsReader requestDetails) {
return null;
}

@Override
public Call<Object> getResource(String role, String targetUrl) {
if (!getResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.getResource(targetUrl);
}

@Override
public Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!createResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.createResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> updateResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!updateResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.updateResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> deleteResource(String role, String targetUrl) {
if (!deleteResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.deleteResource(targetUrl);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.google.fhir.gateway.resource_validators;

import com.google.fhir.gateway.ApiServiceImpl;
import com.google.fhir.gateway.FormatterClass;
import com.google.fhir.gateway.OpenChanjoRoles;
import com.google.fhir.gateway.interfaces.*;
import com.google.fhir.gateway.validators.ResourceRoleValidator;
import jakarta.servlet.http.HttpServletRequest;
import retrofit2.Call;

import java.util.Set;

public class AppointmentResourceValidator implements AccessChecker, ResourceValidator {

private final ApiServiceImpl apiService = new ApiServiceImpl();
private final FormatterClass formatter = new FormatterClass();

// Define allowed roles for different operations
private final Set<String> createAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name()
);
private final Set<String> updateAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name()
);
private final Set<String> deleteAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name()
);
private final Set<String> getAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name(),
OpenChanjoRoles.ADMINISTRATOR.name(),
OpenChanjoRoles.NATIONAL_SYSTEM_ADMINISTRATOR.name()
);

private final Set<String> testAllowedRoles = Set.of(OpenChanjoRoles.FACILITY_SYSTEM_ADMINISTRATOR.name());

// Instantiate role validators dynamically
private final RoleValidator createResourceRoleValidator = new ResourceRoleValidator(createAllowedRoles);
private final RoleValidator updateResourceRoleValidator = new ResourceRoleValidator(updateAllowedRoles);
private final RoleValidator deleteResourceRoleValidator = new ResourceRoleValidator(deleteAllowedRoles);
private final RoleValidator getResourceRoleValidator = new ResourceRoleValidator(getAllowedRoles);
private final RoleValidator testResourceRoleValidator = new ResourceRoleValidator(testAllowedRoles);



@Override
public AccessDecision checkAccess(RequestDetailsReader requestDetails) {
return null;
}

@Override
public Call<Object> getResource(String role, String targetUrl) {
if (!getResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.getResource(targetUrl);
}

@Override
public Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!createResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.createResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> updateResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!updateResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.updateResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> deleteResource(String role, String targetUrl) {
if (!deleteResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.deleteResource(targetUrl);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.google.fhir.gateway.resource_validators;

import com.google.fhir.gateway.ApiServiceImpl;
import com.google.fhir.gateway.FormatterClass;
import com.google.fhir.gateway.OpenChanjoRoles;
import com.google.fhir.gateway.interfaces.*;
import com.google.fhir.gateway.validators.ResourceRoleValidator;
import jakarta.servlet.http.HttpServletRequest;
import retrofit2.Call;

import java.util.Set;

public class CarePlanResourceValidator implements AccessChecker, ResourceValidator {

private final ApiServiceImpl apiService = new ApiServiceImpl();
private final FormatterClass formatter = new FormatterClass();

// Define allowed roles for different operations
private final Set<String> createAllowedRoles = Set.of(

);
private final Set<String> updateAllowedRoles = Set.of(

);
private final Set<String> deleteAllowedRoles = Set.of(

);
private final Set<String> getAllowedRoles = Set.of(
OpenChanjoRoles.NURSE.name(),
OpenChanjoRoles.ADMINISTRATOR.name(),
OpenChanjoRoles.NATIONAL_SYSTEM_ADMINISTRATOR.name(),
OpenChanjoRoles.SUB_COUNTY_SYSTEM_ADMINISTRATOR.name()
);

private final Set<String> testAllowedRoles = Set.of(OpenChanjoRoles.FACILITY_SYSTEM_ADMINISTRATOR.name());

// Instantiate role validators dynamically
private final RoleValidator createResourceRoleValidator = new ResourceRoleValidator(createAllowedRoles);
private final RoleValidator updateResourceRoleValidator = new ResourceRoleValidator(updateAllowedRoles);
private final RoleValidator deleteResourceRoleValidator = new ResourceRoleValidator(deleteAllowedRoles);
private final RoleValidator getResourceRoleValidator = new ResourceRoleValidator(getAllowedRoles);
private final RoleValidator testResourceRoleValidator = new ResourceRoleValidator(testAllowedRoles);



@Override
public AccessDecision checkAccess(RequestDetailsReader requestDetails) {
return null;
}

@Override
public Call<Object> getResource(String role, String targetUrl) {
if (!getResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.getResource(targetUrl);
}

@Override
public Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!createResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.createResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> updateResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!updateResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.updateResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> deleteResource(String role, String targetUrl) {
if (!deleteResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.deleteResource(targetUrl);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.google.fhir.gateway.resource_validators;

import com.google.fhir.gateway.ApiServiceImpl;
import com.google.fhir.gateway.FormatterClass;
import com.google.fhir.gateway.OpenChanjoRoles;
import com.google.fhir.gateway.interfaces.*;
import com.google.fhir.gateway.validators.ResourceRoleValidator;
import jakarta.servlet.http.HttpServletRequest;
import retrofit2.Call;

import java.util.Set;

public class LocationResourceValidator implements AccessChecker, ResourceValidator {

private final ApiServiceImpl apiService = new ApiServiceImpl();
private final FormatterClass formatter = new FormatterClass();

// Define allowed roles for different operations
private final Set<String> createAllowedRoles = Set.of(

);
private final Set<String> updateAllowedRoles = Set.of(
OpenChanjoRoles.ADMINISTRATOR.name(),
OpenChanjoRoles.NATIONAL_SYSTEM_ADMINISTRATOR.name()
);
private final Set<String> deleteAllowedRoles = Set.of(

);
private final Set<String> getAllowedRoles = Set.of(
OpenChanjoRoles.SUB_COUNTY_SYSTEM_ADMINISTRATOR.name(),
OpenChanjoRoles.ADMINISTRATOR.name(),
OpenChanjoRoles.NATIONAL_SYSTEM_ADMINISTRATOR.name()
);

private final Set<String> testAllowedRoles = Set.of(OpenChanjoRoles.FACILITY_SYSTEM_ADMINISTRATOR.name());

// Instantiate role validators dynamically
private final RoleValidator createResourceRoleValidator = new ResourceRoleValidator(createAllowedRoles);
private final RoleValidator updateResourceRoleValidator = new ResourceRoleValidator(updateAllowedRoles);
private final RoleValidator deleteResourceRoleValidator = new ResourceRoleValidator(deleteAllowedRoles);
private final RoleValidator getResourceRoleValidator = new ResourceRoleValidator(getAllowedRoles);
private final RoleValidator testResourceRoleValidator = new ResourceRoleValidator(testAllowedRoles);



@Override
public AccessDecision checkAccess(RequestDetailsReader requestDetails) {
return null;
}

@Override
public Call<Object> getResource(String role, String targetUrl) {
if (!getResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.getResource(targetUrl);
}

@Override
public Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!createResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.createResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> updateResource(String role, String targetUrl, HttpServletRequest requestBody) {
if (!updateResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.updateResource(targetUrl, formatter.readRequestBody(requestBody));
}

@Override
public Call<Object> deleteResource(String role, String targetUrl) {
if (!deleteResourceRoleValidator.hasAccess(role)) {
return null; // Return null if access is denied
}
return apiService.deleteResource(targetUrl);
}

}
Loading

0 comments on commit 57deacf

Please sign in to comment.