-
Notifications
You must be signed in to change notification settings - Fork 31
implement apply access control to /validate endpoints #2401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4c15256
implement apply access control to /validate endpoints
aktaskaan af029cb
Merge branch 'master' into ccd_5344
aktaskaan 0a44089
add case creation support
aktaskaan 7d5631f
Merge remote-tracking branch 'origin/ccd_5344' into ccd_5344
aktaskaan 462c063
add case creation support and fix functional tests
aktaskaan af9ff7a
Merge branch 'master' into ccd_5344
aktaskaan 72bf595
Merge branch 'master' into ccd_5344
danlysiak 5884397
implement Classified to /validate endpoints
aktaskaan 304102f
Merge branch 'master' into ccd_5344
mwallaceHMCTS e566de4
Merge branch 'master' into ccd_5344
aktaskaan 189231a
Merge branch 'master' into ccd_5344
aktaskaan 4b247db
fix unit test
aktaskaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
.../java/uk/gov/hmcts/ccd/domain/service/validate/AuthorisedValidateCaseFieldsOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package uk.gov.hmcts.ccd.domain.service.validate; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.ccd.config.JacksonUtils; | ||
import uk.gov.hmcts.ccd.data.definition.CachedCaseDefinitionRepository; | ||
import uk.gov.hmcts.ccd.data.definition.CaseDefinitionRepository; | ||
import uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol.AccessProfile; | ||
import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; | ||
import uk.gov.hmcts.ccd.domain.model.std.CaseDataContent; | ||
import uk.gov.hmcts.ccd.domain.service.common.AccessControlService; | ||
import uk.gov.hmcts.ccd.domain.service.common.CaseAccessService; | ||
import uk.gov.hmcts.ccd.endpoint.exceptions.ValidationException; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static com.google.common.collect.Maps.newHashMap; | ||
import static uk.gov.hmcts.ccd.domain.service.common.AccessControlService.CAN_READ; | ||
|
||
@Service | ||
@Slf4j | ||
@Qualifier(AuthorisedValidateCaseFieldsOperation.QUALIFIER) | ||
public class AuthorisedValidateCaseFieldsOperation implements ValidateCaseFieldsOperation { | ||
aktaskaan marked this conversation as resolved.
Show resolved
Hide resolved
aktaskaan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static final String QUALIFIER = "authorised"; | ||
|
||
private final AccessControlService accessControlService; | ||
private final CaseDefinitionRepository caseDefinitionRepository; | ||
private final CaseAccessService caseAccessService; | ||
private final ValidateCaseFieldsOperation validateCaseFieldsOperation; | ||
|
||
public AuthorisedValidateCaseFieldsOperation(AccessControlService accessControlService, | ||
@Qualifier(CachedCaseDefinitionRepository.QUALIFIER) | ||
CaseDefinitionRepository caseDefinitionRepository, | ||
CaseAccessService caseAccessService, | ||
@Qualifier(ClassifiedValidateCaseFieldsOperation.QUALIFIER) | ||
ValidateCaseFieldsOperation validateCaseFieldsOperation) { | ||
this.accessControlService = accessControlService; | ||
this.caseDefinitionRepository = caseDefinitionRepository; | ||
this.caseAccessService = caseAccessService; | ||
this.validateCaseFieldsOperation = validateCaseFieldsOperation; | ||
} | ||
|
||
@Override | ||
public Map<String, JsonNode> validateCaseDetails(OperationContext operationContext) { | ||
validateCaseFieldsOperation.validateCaseDetails(operationContext); | ||
|
||
CaseDataContent content = operationContext.content(); | ||
String caseTypeId = operationContext.caseTypeId(); | ||
|
||
String caseReference = content.getCaseReference(); | ||
Set<AccessProfile> accessProfiles = StringUtils.isNotEmpty(caseReference) | ||
? caseAccessService.getAccessProfilesByCaseReference(caseReference) : | ||
caseAccessService.getCaseCreationRoles(caseTypeId); | ||
|
||
verifyReadAccess(caseTypeId, content, accessProfiles); | ||
|
||
return content.getData(); | ||
} | ||
|
||
@Override | ||
public void validateData(Map<String, JsonNode> data, CaseTypeDefinition caseTypeDefinition, | ||
CaseDataContent content) { | ||
validateCaseFieldsOperation.validateData(data, caseTypeDefinition, content); | ||
} | ||
|
||
private void verifyReadAccess(final String caseTypeId, CaseDataContent content, Set<AccessProfile> accessProfiles) { | ||
final CaseTypeDefinition caseTypeDefinition = getCaseDefinitionType(caseTypeId); | ||
|
||
if (content.getData() == null) { | ||
content.setData(newHashMap()); | ||
return; | ||
} | ||
|
||
if (!accessControlService.canAccessCaseTypeWithCriteria( | ||
caseTypeDefinition, | ||
accessProfiles, | ||
CAN_READ)) { | ||
content.setData(newHashMap()); | ||
return; | ||
} | ||
|
||
content.setData(JacksonUtils.convertValueInDataField( | ||
accessControlService.filterCaseFieldsByAccess( | ||
JacksonUtils.convertValueJsonNode(content.getData()), | ||
caseTypeDefinition.getCaseFieldDefinitions(), | ||
accessProfiles, | ||
CAN_READ, | ||
false))); | ||
} | ||
|
||
private CaseTypeDefinition getCaseDefinitionType(String caseTypeId) { | ||
final CaseTypeDefinition caseTypeDefinition = caseDefinitionRepository.getCaseType(caseTypeId); | ||
if (caseTypeDefinition == null) { | ||
throw new ValidationException("Cannot find case type definition for " + caseTypeId); | ||
} | ||
return caseTypeDefinition; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.