@Test void testPrepareSetVariableAssertionNotENVElementNode() { Element setVariableAssertion = document.createElement(SET_VARIABLE); document.appendChild(setVariableAssertion); Element expression = document.createElement(EXPRESSION); expression.appendChild(document.createElement("ashdkjsah")); setVariableAssertion.appendChild(expression); assertThrows(EntityBuilderException.class, () -> setVariableAssertionBuilder.buildAssertionElement(setVariableAssertion, policyBuilderContext)); }
@Override public void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext) throws DocumentParseException { final Document policyDocument = policyBuilderContext.getPolicyDocument(); Element nameElement; try { nameElement = getSingleElement(assertionElement, VARIABLE_TO_SET); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find VariableToSet element in a SetVariable Assertion."); } String variableName = nameElement.getAttribute(STRING_VALUE); if (variableName.startsWith(PREFIX_ENV)) { assertionElement.insertBefore( createElementWithAttribute(policyDocument, BASE_64_EXPRESSION, ENV_PARAM_NAME, insertPrefixToEnvironmentVariable(variableName, policyBuilderContext.getPolicyName())), assertionElement.getFirstChild() ); } else { try{ PolicyAssertionBuilder.prepareBase64Element(policyDocument, assertionElement, EXPRESSION, BASE_64_EXPRESSION); } catch (EntityBuilderException e){ LOGGER.log(Level.WARNING, "Exception " + e.getMessage()); } } }
SetVariableAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext) throws DocumentParseException { final Document policyDocument = policyBuilderContext.getPolicyDocument(); Element nameElement; try { nameElement = getSingleElement(assertionElement, VARIABLE_TO_SET); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find VariableToSet element in a SetVariable Assertion."); } String variableName = nameElement.getAttribute(STRING_VALUE); if (variableName.startsWith(PREFIX_ENV)) { assertionElement.insertBefore( createElementWithAttribute(policyDocument, BASE_64_EXPRESSION, ENV_PARAM_NAME, insertPrefixToEnvironmentVariable(variableName, policyBuilderContext.getPolicyName())), assertionElement.getFirstChild() ); } else { try{ PolicyAssertionBuilder.prepareBase64Element(policyDocument, assertionElement, EXPRESSION, BASE_64_EXPRESSION); } catch (EntityBuilderException e){ LOGGER.log(Level.WARNING, "Exception " + e.getMessage()); } } } }
SetVariableAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext) throws DocumentParseException { final Document policyDocument = policyBuilderContext.getPolicyDocument(); Element nameElement; try { nameElement = getSingleElement(assertionElement, VARIABLE_TO_SET); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find VariableToSet element in a SetVariable Assertion."); } String variableName = nameElement.getAttribute(STRING_VALUE); if (variableName.startsWith(PREFIX_ENV)) { assertionElement.insertBefore( createElementWithAttribute(policyDocument, BASE_64_EXPRESSION, ENV_PARAM_NAME, insertPrefixToEnvironmentVariable(variableName, policyBuilderContext.getPolicyName())), assertionElement.getFirstChild() ); } else { try{ PolicyAssertionBuilder.prepareBase64Element(policyDocument, assertionElement, EXPRESSION, BASE_64_EXPRESSION); } catch (EntityBuilderException e){ LOGGER.log(Level.WARNING, "Exception " + e.getMessage()); } } }  }
SetVariableAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext) throws DocumentParseException { final Document policyDocument = policyBuilderContext.getPolicyDocument(); Element nameElement; try { nameElement = getSingleElement(assertionElement, VARIABLE_TO_SET); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find VariableToSet element in a SetVariable Assertion."); } String variableName = nameElement.getAttribute(STRING_VALUE); if (variableName.startsWith(PREFIX_ENV)) { assertionElement.insertBefore( createElementWithAttribute(policyDocument, BASE_64_EXPRESSION, ENV_PARAM_NAME, insertPrefixToEnvironmentVariable(variableName, policyBuilderContext.getPolicyName())), assertionElement.getFirstChild() ); } else { try{ PolicyAssertionBuilder.prepareBase64Element(policyDocument, assertionElement, EXPRESSION, BASE_64_EXPRESSION); } catch (EntityBuilderException e){ LOGGER.log(Level.WARNING, "Exception " + e.getMessage()); } } }  @Override void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext); @Override String getAssertionTagName(); }
SetVariableAssertionBuilder implements PolicyAssertionBuilder { @Override public void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext) throws DocumentParseException { final Document policyDocument = policyBuilderContext.getPolicyDocument(); Element nameElement; try { nameElement = getSingleElement(assertionElement, VARIABLE_TO_SET); } catch (DocumentParseException e) { throw new EntityBuilderException("Could not find VariableToSet element in a SetVariable Assertion."); } String variableName = nameElement.getAttribute(STRING_VALUE); if (variableName.startsWith(PREFIX_ENV)) { assertionElement.insertBefore( createElementWithAttribute(policyDocument, BASE_64_EXPRESSION, ENV_PARAM_NAME, insertPrefixToEnvironmentVariable(variableName, policyBuilderContext.getPolicyName())), assertionElement.getFirstChild() ); } else { try{ PolicyAssertionBuilder.prepareBase64Element(policyDocument, assertionElement, EXPRESSION, BASE_64_EXPRESSION); } catch (EntityBuilderException e){ LOGGER.log(Level.WARNING, "Exception " + e.getMessage()); } } }  @Override void buildAssertionElement(Element assertionElement, PolicyBuilderContext policyBuilderContext); @Override String getAssertionTagName();  }