final RequestParameters requestParameters = ParameterHelper.extractRequestParameters(httpServletRequest);
try {
final YangModelCmHandle yangModelCmHandle = getAndValidateYangModelCmHandle(requestParameters);
- checkPermissionForEachPatchItem(requestParameters.fdn(), patchItems, yangModelCmHandle);
+ checkPermissionForEachPatchItem(requestParameters.fdn(), patchItems,
+ yangModelCmHandle, requestParameters.authorization());
final UrlTemplateParameters urlTemplateParameters =
parametersBuilder.createUrlTemplateParametersForWrite(yangModelCmHandle, requestParameters.fdn());
return dmiRestClient.synchronousPatchOperation(DATA, patchItems, urlTemplateParameters,
final YangModelCmHandle yangModelCmHandle = getAndValidateYangModelCmHandle(requestParameters);
final OperationDetails operationDetails =
operationDetailsFactory.buildOperationDetails(CREATE, requestParameters, resource);
- checkPermission(yangModelCmHandle, operationDetails);
+ checkPermission(yangModelCmHandle, operationDetails, requestParameters);
final UrlTemplateParameters urlTemplateParameters =
parametersBuilder.createUrlTemplateParametersForWrite(yangModelCmHandle, requestParameters.fdn());
return dmiRestClient.synchronousPutOperation(DATA, resource, urlTemplateParameters);
final YangModelCmHandle yangModelCmHandle = getAndValidateYangModelCmHandle(requestParameters);
final OperationDetails operationDetails =
operationDetailsFactory.buildOperationDetailsForDelete(requestParameters.fdn());
- checkPermission(yangModelCmHandle, operationDetails);
+ checkPermission(yangModelCmHandle, operationDetails, requestParameters);
final UrlTemplateParameters urlTemplateParameters =
parametersBuilder.createUrlTemplateParametersForWrite(yangModelCmHandle, requestParameters.fdn());
return dmiRestClient.synchronousDeleteOperation(DATA, urlTemplateParameters);
}
private void checkPermission(final YangModelCmHandle yangModelCmHandle,
- final OperationDetails operationDetails) {
+ final OperationDetails operationDetails,
+ final RequestParameters requestParameters) {
final Map<String, List<ClassInstance>> changeRequestAsMap = new HashMap<>(1);
changeRequestAsMap.put(operationDetails.className(), operationDetails.ClassInstances());
final String changeRequestAsJson = jsonObjectMapper.asJsonString(changeRequestAsMap);
final int index = yangModelCmHandle.getAlternateId().length();
final String resourceIdentifier = operationDetails.parentFdn().substring(index);
policyExecutor.checkPermission(yangModelCmHandle, operationDetails.operationType(),
- NO_AUTHORIZATION, resourceIdentifier, changeRequestAsJson);
+ requestParameters.authorization(), resourceIdentifier, changeRequestAsJson);
}
private void checkPermissionForEachPatchItem(final String baseFdn,
final List<PatchItem> patchItems,
- final YangModelCmHandle yangModelCmHandle) {
+ final YangModelCmHandle yangModelCmHandle,
+ final String authorization) {
int patchItemCounter = 0;
for (final PatchItem patchItem : patchItems) {
final String extendedPath = baseFdn + patchItem.getPath();
- final RequestParameters requestParameters = ParameterHelper.createRequestParametersForPatch(extendedPath);
+ final RequestParameters requestParameters =
+ ParameterHelper.createRequestParametersForPatch(extendedPath, authorization);
final OperationDetails operationDetails =
operationDetailsFactory.buildOperationDetails(requestParameters, patchItem);
try {
- checkPermission(yangModelCmHandle, operationDetails);
+ checkPermission(yangModelCmHandle, operationDetails, requestParameters);
patchItemCounter++;
} catch (final Exception exception) {
final String httpMethodName = "PATCH";
mockDmiRestClient.synchronousPatchOperation(*_) >> new ResponseEntity<>('content from DMI', responseStatusFromDmi)
when: 'patch request is performed'
def response = mvc.perform(patch(provmnsUrl)
+ .header('Authorization', 'my authorization')
.contentType(contentMediaType)
.content(jsonBody))
.andReturn().response
and: 'the response contains the expected content'
assert response.contentAsString.contains('content from DMI')
and: 'policy executor was invoked with the expected parameters'
- 1 * mockPolicyExecutor.checkPermission(validCmHandle, OperationType.UPDATE, _, expectedResourceIdForPolicyExecutor, expectedChangeRequest)
+ 1 * mockPolicyExecutor.checkPermission(validCmHandle, OperationType.UPDATE, 'my authorization', expectedResourceIdForPolicyExecutor, expectedChangeRequest)
where: 'following scenarios are applied'
scenario | contentMediaType | jsonBody | responseStatusFromDmi || expectedResponseStatusFromProvMnS
'happy flow 3gpp' | patchMediaType3gpp | patchJsonBody3gpp | OK || OK
def expectedResourceIdentifier = '/myClass=id1/childClass=1'
when: 'patch data resource request is performed'
def response = mvc.perform(patch(url)
+ .header('Authorization', 'my authorization')
.contentType(patchMediaType)
.content('[{"op":"remove","path":"/childClass=1/grandchildClass=1"}]'))
.andReturn().response
then: 'response status is OK'
assert response.status == OK.value()
and: 'Policy Executor was invoked with correct details'
- 1 * mockPolicyExecutor.checkPermission(_, OperationType.DELETE, _, expectedResourceIdentifier, expectedDeleteChangeRequest)
+ 1 * mockPolicyExecutor.checkPermission(validCmHandle, OperationType.DELETE, 'my authorization', expectedResourceIdentifier, expectedDeleteChangeRequest)
}
def 'Patch request with no permission from Coordination Management (aka Policy Executor).'() {
def expectedChangeRequest = '{"grandChildClass":[{"id":"2","attributes":{"attr1":"value1"}}]}'
when: 'put data resource request is performed'
def response = mvc.perform(put(putUrl)
+ .header('Authorization', 'my authorization')
.contentType(MediaType.APPLICATION_JSON)
.content(resourceAsJson))
.andReturn().response
and: 'the content is whatever the DMI returned'
assert response.contentAsString == responseContentFromDmi
and: 'The policy executor was invoked with the expected parameters'
- 1 * mockPolicyExecutor.checkPermission(_, OperationType.CREATE, _, expectedResourceIdentifier, expectedChangeRequest)
+ 1 * mockPolicyExecutor.checkPermission(validCmHandle, OperationType.CREATE, 'my authorization', expectedResourceIdentifier, expectedChangeRequest)
where: 'following responses returned by DMI'
scenario | responseStatusFromDmi | responseContentFromDmi
'happy flow' | OK | 'content from DMI'
and: 'dmi provides a response'
mockDmiRestClient.synchronousDeleteOperation(*_) >> new ResponseEntity<>(responseContentFromDmi, responseStatusFromDmi)
when: 'Delete data resource request is performed'
- def response = mvc.perform(delete(deleteUrl)).andReturn().response
+ def response = mvc.perform(delete(deleteUrl).header('Authorization', 'my authorization')).andReturn().response
then: 'response status is the same as what DMI gave'
assert response.status == responseStatusFromDmi.value()
and: 'the content is whatever the DMI returned'
assert response.contentAsString == responseContentFromDmi
and: 'Policy Executor was invoked with correct resource identifier and almost empty operation details (not used for delete!)'
- 1 * mockPolicyExecutor.checkPermission(_, OperationType.DELETE, _, '/myClass=id1/childClass=1', expectedDeleteChangeRequest)
+ 1 * mockPolicyExecutor.checkPermission(_, OperationType.DELETE, 'my authorization', '/myClass=id1/childClass=1', expectedDeleteChangeRequest)
where: 'following responses returned by DMI'
scenario | responseStatusFromDmi | responseContentFromDmi
'happy flow' | OK | 'content from DMI'
throw createProvMnSException(httpServletRequest.getMethod(), uriPath);
}
final String fdn = "/" + pathVariables[REQUEST_FDN_INDEX];
- return createRequestParameters(httpServletRequest.getMethod(), fdn);
+ return createRequestParameters(httpServletRequest.getMethod(),
+ httpServletRequest.getHeader("Authorization"), fdn);
}
/**
* Create RequestParameters object for PATCH operations.
*
* @param pathWithAttributes the path a fdn possibly with containing attributes
+ * @param authorization HttpServletRequest object
* @return RequestParameters object for PATCH operation
*/
- public static RequestParameters createRequestParametersForPatch(final String pathWithAttributes) {
+ public static RequestParameters createRequestParametersForPatch(
+ final String pathWithAttributes, final String authorization) {
final String fdn = removeTrailingHash(extractFdn(pathWithAttributes));
- return createRequestParameters("PATCH", fdn);
+ return createRequestParameters("PATCH", authorization, fdn);
}
/**
}
private static RequestParameters createRequestParameters(final String httpMethodName,
+ final String authorization,
final String fdn) {
final int lastSlashIndex = fdn.lastIndexOf('/');
final String classNameAndId;
}
final String className = splitClassNameId[0];
final String id = removeTrailingHash(splitClassNameId[1]);
- return new RequestParameters(httpMethodName, fdn, uriLdnFirstPart, className, id);
+ return new RequestParameters(httpMethodName, authorization, fdn, uriLdnFirstPart, className, id);
}
private static ProvMnSException createProvMnSException(final String httpMethodName, final String uriPath) {
public record RequestParameters(
String httpMethodName,
+ String authorization,
String fdn,
String uriLdnFirstPart,
String className,
class OperationDetailsFactorySpec extends Specification {
def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
- def requestPathParameters = new RequestParameters('some method', '/parent=id1/someChild=someId','some uri', 'class from uri', 'id from uri')
+ def requestPathParameters = new RequestParameters('some method', 'some authorization', '/parent=id1/someChild=someId','some uri', 'class from uri', 'id from uri')
OperationDetailsFactory objectUnderTest = new OperationDetailsFactory(jsonObjectMapper)
def 'Extract request parameters for Patch Path with attributes.'() {
when: 'the request parameters are extracted from the path'
- def result = objectUnderTest.createRequestParametersForPatch(path)
+ def result = objectUnderTest.createRequestParametersForPatch(path, 'some authorization')
then: 'the FDN is as expected'
assert result.fdn == expectedFdn
and: 'the class name and id are mapped correctly'
final String accept,
final String authorization) {
log.info("Stub Policy Executor Invoked");
+ log.info("Authorization sent with request: {}", authorization);
log.info("Permission Request: {}", formatPermissionRequest(permissionRequest));
if (permissionRequest.getOperations().isEmpty()) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);