- obligation.setObligationId(comboDictValue);
- obligation.setFulfillOn(EffectType.PERMIT);
-
- // Add Action Assignment:
- AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
- assignment1.setAttributeId(PERFORMER_ATTRIBUTEID);
- assignment1.setCategory(CATEGORY_RECIPIENT_SUBJECT);
-
- AttributeValueType actionNameAttributeValue = new AttributeValueType();
- actionNameAttributeValue.setDataType(STRING_DATATYPE);
- actionNameAttributeValue.getContent().add(performer.get(policyAdapter.getActionPerformer()));
-
- assignment1.setExpression(new ObjectFactory().createAttributeValue(actionNameAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignment1);
-
- // Add Type Assignment:
- AttributeAssignmentExpressionType assignmentType = new AttributeAssignmentExpressionType();
- assignmentType.setAttributeId(TYPE_ATTRIBUTEID);
- assignmentType.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType typeAttributeValue = new AttributeValueType();
- typeAttributeValue.setDataType(STRING_DATATYPE);
- String actionDictType = getActionPolicyDict(comboDictValue).getType();
- typeAttributeValue.getContent().add(actionDictType);
-
- assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentType);
-
- // Add Rest_URL Assignment:
- AttributeAssignmentExpressionType assignmentURL = new AttributeAssignmentExpressionType();
- assignmentURL.setAttributeId(URL_ATTRIBUTEID);
- assignmentURL.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType actionURLAttributeValue = new AttributeValueType();
- actionURLAttributeValue.setDataType(URI_DATATYPE);
- String actionDictUrl = getActionPolicyDict(comboDictValue).getUrl();
- actionURLAttributeValue.getContent().add(actionDictUrl);
-
- assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentURL);
-
- // Add Method Assignment:
- AttributeAssignmentExpressionType assignmentMethod = new AttributeAssignmentExpressionType();
- assignmentMethod.setAttributeId(METHOD_ATTRIBUTEID);
- assignmentMethod.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType methodAttributeValue = new AttributeValueType();
- methodAttributeValue.setDataType(STRING_DATATYPE);
- String actionDictMethod = getActionPolicyDict(comboDictValue).getMethod();
- methodAttributeValue.getContent().add(actionDictMethod);
-
- assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentMethod);
-
- // Add JSON_URL Assignment:
- String actionBody = getActionPolicyDict(comboDictValue).getBody();
- if (actionBody != null) {
- AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType();
- assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID);
- assignmentJsonURL.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType jsonURLAttributeValue = new AttributeValueType();
- jsonURLAttributeValue.setDataType(URI_DATATYPE);
- jsonURLAttributeValue.getContent().add(CONFIG_URL + "/Action/" + policyName + ".json");
-
- assignmentJsonURL.setExpression(new ObjectFactory().createAttributeValue(jsonURLAttributeValue));
- obligation.getAttributeAssignmentExpression().add(assignmentJsonURL);
- }
-
- if(getActionPolicyDict(comboDictValue).getHeader() != null){
- String headerVal = getActionPolicyDict(comboDictValue).getHeader();
- if(headerVal != null && !headerVal.equals("")){
- // parse it on : to get number of headers
- String[] result = headerVal.split(":");
- for (String eachString : result){
- // parse each value on =
- String[] textFieldVals = eachString.split("=");
- obligation.getAttributeAssignmentExpression().add(addDynamicHeaders(textFieldVals[0], textFieldVals[1]));
- }
- }
-
- }
-
- obligations.getObligationExpression().add(obligation);
- return obligations;
- }
-
-
- // if compound setting the inner apply here
- protected ApplyType getInnerActionApply(String value1Label) {
- ApplyType actionApply = new ApplyType();
- int index = 0;
- // check the index for the label.
- for (String labelAttr : dynamicLabelRuleAlgorithms) {
- if (labelAttr.equals(value1Label)) {
- String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
- // check if the row contains label again
- for (String labelValue : dynamicLabelRuleAlgorithms) {
- if (labelValue.equals(value1)) {
- return getCompoundApply(index);
- }
- }
-
- // Getting the values from the form.
- String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
- String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
- actionApply.setFunctionId(dropDownMap.get(functionKey));
- // if two text field are rule attributes.
- if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
- ApplyType innerActionApply1 = new ApplyType();
- ApplyType innerActionApply2 = new ApplyType();
- AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
- AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
- // If selected function is Integer function set integer functionID
- if (functionKey.toLowerCase().contains("integer")) {
- innerActionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
- innerActionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
- attributeDesignator1.setDataType(INTEGER_DATATYPE);
- attributeDesignator2.setDataType(INTEGER_DATATYPE);
- } else {
- // If selected function is not a Integer function
- // set String functionID
- innerActionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
- innerActionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
- attributeDesignator1.setDataType(STRING_DATATYPE);
- attributeDesignator2.setDataType(STRING_DATATYPE);
- }
- attributeDesignator1.setCategory(CATEGORY_RESOURCE);
- attributeDesignator2.setCategory(CATEGORY_RESOURCE);
-
- // Here set actual field values
- attributeDesignator1.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
- attributeDesignator2.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8));
-
- innerActionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator1));
- innerActionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator2));
-
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply1));
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply2));
-
- } else {// if either of one text field is rule attribute.
- ApplyType innerActionApply = new ApplyType();
- AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
- AttributeValueType actionConditionAttributeValue = new AttributeValueType();
-
- if (functionKey.toLowerCase().contains("integer")) {
- innerActionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
- actionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
- attributeDesignator.setDataType(INTEGER_DATATYPE);
- } else {
- innerActionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
- actionConditionAttributeValue.setDataType(STRING_DATATYPE);
- attributeDesignator.setDataType(STRING_DATATYPE);
- }
-
- String attributeId = null;
- String attributeValue = null;
-
- // Find which textField has rule attribute and set it as
- attributeId = value1;
- attributeValue = value2;
-
- if (attributeId != null) {
- attributeDesignator.setCategory(CATEGORY_RESOURCE);
- attributeDesignator.setAttributeId(attributeId);
- }
- actionConditionAttributeValue.getContent().add(attributeValue);
- innerActionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
- // Decide the order of element based the values.
- if (attributeId.equals(value1)) {
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
- actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
- } else {
- actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
- actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
- }
- }
- }
- index++;
- }
- return actionApply;
- }
-
- // if the rule algorithm is multiple compound one setting the apply
- protected ApplyType getCompoundApply(int index) {
- ApplyType actionApply = new ApplyType();
- String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString();
- String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString();
- String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString();
- actionApply.setFunctionId(dropDownMap.get(selectedFunction));
- actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
- actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
- return actionApply;
- }
-
- // Adding the dynamic headers if any
- private AttributeAssignmentExpressionType addDynamicHeaders(String header, String value) {
- AttributeAssignmentExpressionType assignmentHeaders = new AttributeAssignmentExpressionType();
- assignmentHeaders.setAttributeId("headers:" + header);
- assignmentHeaders.setCategory(CATEGORY_RESOURCE);
-
- AttributeValueType headersAttributeValue = new AttributeValueType();
- headersAttributeValue.setDataType(STRING_DATATYPE);
- headersAttributeValue.getContent().add(value);
-
- assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue));
- return assignmentHeaders;
- }
-
- private Map<String,String> createDropDownMap(){
- JPAUtils jpaUtils = null;
- Map<String, String> dropDownMap = new HashMap<>();
- try {
- jpaUtils = JPAUtils.getJPAUtilsInstance(XACMLPapServlet.getEmf());
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- }
- if(jpaUtils != null){
- Map<Datatype, List<FunctionDefinition>> functionMap = jpaUtils.getFunctionDatatypeMap();
-
- for (Datatype id : functionMap.keySet()) {
- List<FunctionDefinition> functionDefinitions = (List<FunctionDefinition>) functionMap
- .get(id);
- for (FunctionDefinition functionDef : functionDefinitions) {
- dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid());
- }
- }
- }
- return dropDownMap;
- }
-
- private ActionPolicyDict getActionPolicyDict(String attributeName){
- ActionPolicyDict retObj = new ActionPolicyDict();
- EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
- Query getActionPolicyDicts = em.createNamedQuery("ActionPolicyDict.findAll");
- List<?> actionPolicyDicts = getActionPolicyDicts.getResultList();
-
- for (Object id : actionPolicyDicts) {
- ActionPolicyDict actionPolicy = (ActionPolicyDict) id;
- if(attributeName.equals(actionPolicy.getAttributeName())){
- setAttribute(true);
- retObj = actionPolicy;
- break;
- }
- }
- em.close();
- return retObj;
- }
-
- @Override
- public Object getCorrectPolicyDataObject() {
- return policyAdapter.getPolicyData();
- }
+ obligation.setObligationId(comboDictValue);
+ obligation.setFulfillOn(EffectType.PERMIT);
+
+ // Add Action Assignment:
+ AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+ assignment1.setAttributeId(PERFORMER_ATTRIBUTEID);
+ assignment1.setCategory(CATEGORY_RECIPIENT_SUBJECT);
+
+ AttributeValueType actionNameAttributeValue = new AttributeValueType();
+ actionNameAttributeValue.setDataType(STRING_DATATYPE);
+ actionNameAttributeValue.getContent().add(performer.get(policyAdapter.getActionPerformer()));
+
+ assignment1.setExpression(new ObjectFactory().createAttributeValue(actionNameAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignment1);
+
+ // Add Type Assignment:
+ AttributeAssignmentExpressionType assignmentType = new AttributeAssignmentExpressionType();
+ assignmentType.setAttributeId(TYPE_ATTRIBUTEID);
+ assignmentType.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType typeAttributeValue = new AttributeValueType();
+ typeAttributeValue.setDataType(STRING_DATATYPE);
+ String actionDictType = policyAdapter.getActionDictType();
+ typeAttributeValue.getContent().add(actionDictType);
+
+ assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentType);
+
+ // Add Rest_URL Assignment:
+ AttributeAssignmentExpressionType assignmentURL = new AttributeAssignmentExpressionType();
+ assignmentURL.setAttributeId(URL_ATTRIBUTEID);
+ assignmentURL.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType actionURLAttributeValue = new AttributeValueType();
+ actionURLAttributeValue.setDataType(URI_DATATYPE);
+ String actionDictUrl = policyAdapter.getActionDictUrl();
+ actionURLAttributeValue.getContent().add(actionDictUrl);
+
+ assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentURL);
+
+ // Add Method Assignment:
+ AttributeAssignmentExpressionType assignmentMethod = new AttributeAssignmentExpressionType();
+ assignmentMethod.setAttributeId(METHOD_ATTRIBUTEID);
+ assignmentMethod.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType methodAttributeValue = new AttributeValueType();
+ methodAttributeValue.setDataType(STRING_DATATYPE);
+ String actionDictMethod = policyAdapter.getActionDictMethod();
+ methodAttributeValue.getContent().add(actionDictMethod);
+
+ assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentMethod);
+
+ // Add JSON_URL Assignment:
+ String actionBody = policyAdapter.getActionBody();
+ if (actionBody != null) {
+ AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType();
+ assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID);
+ assignmentJsonURL.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType jsonURLAttributeValue = new AttributeValueType();
+ jsonURLAttributeValue.setDataType(URI_DATATYPE);
+ jsonURLAttributeValue.getContent().add(CONFIG_URL + "/Action/" + policyName + ".json");
+
+ assignmentJsonURL.setExpression(new ObjectFactory().createAttributeValue(jsonURLAttributeValue));
+ obligation.getAttributeAssignmentExpression().add(assignmentJsonURL);
+ }
+
+ String headerVal = policyAdapter.getActionDictHeader();
+ if (headerVal != null && !headerVal.trim().isEmpty()) {
+ // parse it on : to get number of headers
+ String[] result = headerVal.split(":");
+ for (String eachString : result) {
+ // parse each value on =
+ String[] textFieldVals = eachString.split("=");
+ obligation.getAttributeAssignmentExpression()
+ .add(addDynamicHeaders(textFieldVals[0], textFieldVals[1]));
+ }
+ }
+
+ obligations.getObligationExpression().add(obligation);
+ return obligations;
+ }
+
+ // if compound setting the inner apply here
+ protected ApplyType getInnerActionApply(String value1Label) {
+ ApplyType actionApply = new ApplyType();
+ int index = 0;
+ // check the index for the label.
+ for (String labelAttr : dynamicLabelRuleAlgorithms) {
+ if (labelAttr.equals(value1Label)) {
+ String value1 = dynamicFieldOneRuleAlgorithms.get(index);
+ // check if the row contains label again
+ for (String labelValue : dynamicLabelRuleAlgorithms) {
+ if (labelValue.equals(value1)) {
+ return getCompoundApply(index);
+ }
+ }
+
+ // Getting the values from the form.
+ String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index);
+ String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
+ actionApply.setFunctionId(getFunctionDefinitionId(functionKey));
+ // if two text field are rule attributes.
+ if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
+ ApplyType innerActionApply1 = new ApplyType();
+ ApplyType innerActionApply2 = new ApplyType();
+ AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType();
+ AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType();
+ // If selected function is Integer function set integer functionID
+ if (functionKey.toLowerCase().contains("integer")) {
+ innerActionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+ innerActionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+ attributeDesignator1.setDataType(INTEGER_DATATYPE);
+ attributeDesignator2.setDataType(INTEGER_DATATYPE);
+ } else {
+ // If selected function is not a Integer function
+ // set String functionID
+ innerActionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+ innerActionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+ attributeDesignator1.setDataType(STRING_DATATYPE);
+ attributeDesignator2.setDataType(STRING_DATATYPE);
+ }
+ attributeDesignator1.setCategory(CATEGORY_RESOURCE);
+ attributeDesignator2.setCategory(CATEGORY_RESOURCE);
+
+ // Here set actual field values
+ attributeDesignator1
+ .setAttributeId(value1.contains("resource:") ? value1.substring(9) : value1.substring(8));
+ attributeDesignator2
+ .setAttributeId(value1.contains("resource:") ? value1.substring(9) : value1.substring(8));
+
+ innerActionApply1.getExpression()
+ .add(new ObjectFactory().createAttributeDesignator(attributeDesignator1));
+ innerActionApply2.getExpression()
+ .add(new ObjectFactory().createAttributeDesignator(attributeDesignator2));
+
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply1));
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply2));
+
+ } else {// if either of one text field is rule attribute.
+ ApplyType innerActionApply = new ApplyType();
+ AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
+ AttributeValueType actionConditionAttributeValue = new AttributeValueType();
+
+ if (functionKey.toLowerCase().contains("integer")) {
+ innerActionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+ actionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
+ attributeDesignator.setDataType(INTEGER_DATATYPE);
+ } else {
+ innerActionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+ actionConditionAttributeValue.setDataType(STRING_DATATYPE);
+ attributeDesignator.setDataType(STRING_DATATYPE);
+ }
+
+ String attributeId = null;
+ String attributeValue = null;
+
+ // Find which textField has rule attribute and set it as
+ attributeId = value1;
+ attributeValue = value2;
+
+ if (attributeId != null) {
+ attributeDesignator.setCategory(CATEGORY_RESOURCE);
+ attributeDesignator.setAttributeId(attributeId);
+ }
+ actionConditionAttributeValue.getContent().add(attributeValue);
+ innerActionApply.getExpression()
+ .add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
+ // Decide the order of element based the values.
+ if (attributeId.equals(value1)) {
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
+ actionApply.getExpression()
+ .add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
+ } else {
+ actionApply.getExpression()
+ .add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue));
+ actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply));
+ }
+ }
+ }
+ index++;
+ }
+ return actionApply;
+ }
+
+ // if the rule algorithm is multiple compound one setting the apply
+ protected ApplyType getCompoundApply(int index) {
+ ApplyType actionApply = new ApplyType();
+ String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index);
+ String value1 = dynamicFieldOneRuleAlgorithms.get(index);
+ String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
+ actionApply.setFunctionId(getFunctionDefinitionId(selectedFunction));
+ actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1)));
+ actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2)));
+ return actionApply;
+ }
+
+ // Adding the dynamic headers if any
+ private AttributeAssignmentExpressionType addDynamicHeaders(String header, String value) {
+ AttributeAssignmentExpressionType assignmentHeaders = new AttributeAssignmentExpressionType();
+ assignmentHeaders.setAttributeId("headers:" + header);
+ assignmentHeaders.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType headersAttributeValue = new AttributeValueType();
+ headersAttributeValue.setDataType(STRING_DATATYPE);
+ headersAttributeValue.getContent().add(value);
+
+ assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue));
+ return assignmentHeaders;
+ }
+
+ @Override
+ public Object getCorrectPolicyDataObject() {
+ return policyAdapter.getPolicyData();
+ }
+
+ public String getFunctionDefinitionId(String key) {
+ FunctionDefinition object =
+ (FunctionDefinition) commonClassDao.getEntityItem(FunctionDefinition.class, "short_name", key);
+ if (object != null) {
+ return object.getXacmlid();
+ }
+ return null;
+ }