Anand Nadar created RANGER-4822:
-----------------------------------
Summary: Policy creation/updation fails when validity period is
added
Key: RANGER-4822
URL: https://issues.apache.org/jira/browse/RANGER-4822
Project: Ranger
Issue Type: Bug
Components: admin
Reporter: Anand Nadar
Assignee: Anand Nadar
When we create/update a policy by addion validity period to it, then it fails
with the below error.
{code:java}
java.lang.UnsupportedOperationException: null
at java.util.AbstractMap.put(AbstractMap.java:209)
at
org.apache.ranger.service.RangerPolicyServiceBase.mapViewToEntityBean(RangerPolicyServiceBase.java:217)
at
org.apache.ranger.service.RangerPolicyService.mapViewToEntityBean(RangerPolicyService.java:37)
at
org.apache.ranger.service.RangerPolicyService.mapViewToEntityBean(RangerPolicyService.java:27)
at
org.apache.ranger.service.RangerBaseModelService.populateEntityBeanForUpdate(RangerBaseModelService.java:192)
at
org.apache.ranger.service.RangerBaseModelService.preUpdate(RangerBaseModelService.java:270)
at
org.apache.ranger.service.RangerBaseModelService.update(RangerBaseModelService.java:252)
at
org.apache.ranger.biz.ServiceDBStore.updatePolicy(ServiceDBStore.java:2300)
at org.apache.ranger.rest.ServiceREST.updatePolicy(ServiceREST.java:1854)
at
org.apache.ranger.rest.ServiceREST$$FastClassBySpringCGLIB$$92dab672.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
{code}
The root cause of this issue is because we have defined options object of
RangerPolicy as immutable using nullSafeMap (default as NullSafeSupplierV2)
which uses Collections.emptyMap to initialise options if its null or empty.
But when validity period is being added to a policy then this options map is
being modified in RangerPolicyServiceBase -> mapViewToEntityBean() as below.
{code:java}
Map<String, Object> options = vObj.getOptions();
if (options == null) {
options = new HashMap<>();
}
if (StringUtils.isNotBlank(validitySchedules)) {
options.put(OPTION_POLICY_VALIDITY_SCHEDULES,
validitySchedules); } else {
options.remove(OPTION_POLICY_VALIDITY_SCHEDULES);
} {code}
To fix this we would need to intitialise options object with a modifiable map
by using getUpdatableMap of RangerBaseModelObject.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)