@Test void testPrepareSetVariableAssertionUnescaping() throws DocumentParseException { Element setVariableAssertionElement = createSetVariableAssertion(document, "userSession", "&lt;usersession&gt;\n" + " &lt;user&gt;&lt;![CDATA[${current.username}]]&gt;&lt;/user&gt;\n" + " &lt;role&gt;&lt;![CDATA[${current.user.role}]]&gt;&lt;/role&gt;\n" + " &lt;lookupUser&gt;&lt;![CDATA[${lookupUser}]]&gt;&lt;/lookupUser&gt;\n" + " &lt;synchToken&gt;&lt;![CDATA[${xpathSynchToken.result}]]&gt;&lt;/synchToken&gt;\n" + "&lt;/usersession&gt;"); document.appendChild(setVariableAssertionElement); String prefix = "prefix"; setVariableAssertionBuilder.buildAssertionElement(setVariableAssertionElement, policyBuilderContext); Element nameElement = getSingleElement(setVariableAssertionElement, VARIABLE_TO_SET); assertEquals("userSession", nameElement.getAttribute(PolicyEntityBuilder.STRING_VALUE)); Element expressionElement = getSingleElement(setVariableAssertionElement, BASE_64_EXPRESSION); String expectedB64 = "PHVzZXJzZXNzaW9uPgogPHVzZXI+PCFbQ0RBVEFbJHtjdXJyZW50LnVzZXJuYW1lfV1dPjwvdXNlcj4KIDxyb2xlPjwhW0NEQVRBWyR7Y3VycmVudC51c2VyLnJvbGV9XV0+PC9yb2xlPgogPGxvb2t1cFVzZXI+PCFbQ0RBVEFbJHtsb29rdXBVc2VyfV1dPjwvbG9va3VwVXNlcj4KIDxzeW5jaFRva2VuPjwhW0NEQVRBWyR7eHBhdGhTeW5jaFRva2VuLnJlc3VsdH1dXT48L3N5bmNoVG9rZW4+CjwvdXNlcnNlc3Npb24+"; String b64 = expressionElement.getAttribute(PolicyEntityBuilder.STRING_VALUE); assertEquals(expectedB64, b64); String value = new String(decodeBase64(b64)); assertEquals( "<usersession>\n" + " <user><![CDATA[${current.username}]]></user>\n" + " <role><![CDATA[${current.user.role}]]></role>\n" + " <lookupUser><![CDATA[${lookupUser}]]></lookupUser>\n" + " <synchToken><![CDATA[${xpathSynchToken.result}]]></synchToken>\n" + "</usersession>", 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();  }