@Test void testPrepareSetVariableAssertionENV() throws DocumentParseException { Element setVariableAssertionElement = createSetVariableAssertion(document, "ENV.my-var", "base64Text"); document.appendChild(setVariableAssertionElement); String prefix = "path.xml"; setVariableAssertionBuilder.buildAssertionElement(setVariableAssertionElement, policyBuilderContext); Element nameElement = getSingleElement(setVariableAssertionElement, VARIABLE_TO_SET); assertEquals("ENV.my-var", nameElement.getAttribute(PolicyEntityBuilder.STRING_VALUE)); Element expressionElement = getSingleElement(setVariableAssertionElement, BASE_64_EXPRESSION); assertEquals(PREFIX_ENV + prefix + ".my-var", expressionElement.getAttribute(SetVariableAssertionBuilder.ENV_PARAM_NAME)); assertFalse(expressionElement.hasAttribute(PolicyEntityBuilder.STRING_VALUE)); }
@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();  }