aboutsummaryrefslogtreecommitdiff
path: root/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java')
-rw-r--r--id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java248
1 files changed, 124 insertions, 124 deletions
diff --git a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java
index eb885eea9..b421dce8c 100644
--- a/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java
+++ b/id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java
@@ -44,130 +44,130 @@ import org.w3c.dom.Element;
* The Class SSETestUtils.
*/
public final class SSETestUtils {
-
-
- /** The Constant LOG. */
- private static final Logger LOG = LoggerFactory
- .getLogger(SSETestUtils.class.getName());
-
- /**
- * Instantiates a new sSE test utils.
- */
- private SSETestUtils() {
- }
-
- /**
- * Prints the tree DOM.
- *
- * @param samlToken the SAML token
- * @param isIndent the is indent
- *
- * @return the string
- * @throws TransformerException the exception
- */
- public static String printTreeDOM(final Element samlToken, final boolean isIndent) throws TransformerException {
- // set up a transformer
- final TransformerFactory transfac = TransformerFactory.newInstance();
- final Transformer trans = transfac.newTransformer();
- trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- trans.setOutputProperty(OutputKeys.INDENT, String.valueOf(isIndent));
-
- // create string from XML tree
- final StringWriter stringWriter = new StringWriter();
- final StreamResult result = new StreamResult(stringWriter);
- final DOMSource source = new DOMSource(samlToken);
- trans.transform(source, result);
- final String xmlString = stringWriter.toString();
-
- return xmlString;
- }
-
- /**
- * Marshall.
- *
- * @param samlToken the SAML token
- *
- * @return the byte[]
- *
- * @throws MarshallingException the marshalling exception
- * @throws ParserConfigurationException the parser configuration exception
- * @throws TransformerException the transformer exception
- */
- public static byte[] marshall(final XMLObject samlToken)
- throws MarshallingException, ParserConfigurationException,
- TransformerException {
-
- final javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
- .newInstance();
- dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
- dbf.setNamespaceAware(true);
- dbf.setIgnoringComments(true);
- final javax.xml.parsers.DocumentBuilder docBuild = dbf
- .newDocumentBuilder();
-
- // Get the marshaller factory
- final MarshallerFactory marshallerFactory = Configuration
- .getMarshallerFactory();
-
- // Get the Subject marshaller
- final Marshaller marshaller = marshallerFactory
- .getMarshaller(samlToken);
-
- final Document doc = docBuild.newDocument();
-
- // Marshall the SAML token
- marshaller.marshall(samlToken, doc);
-
- // Obtain a byte array representation of the marshalled SAML object
- final DOMSource domSource = new DOMSource(doc);
- final StringWriter writer = new StringWriter();
- final StreamResult result = new StreamResult(writer);
- final TransformerFactory transFact = TransformerFactory.newInstance();
- final Transformer transformer = transFact.newTransformer();
- transformer.transform(domSource, result);
-
- return writer.toString().getBytes();
- }
-
- /**
- * Encode SAML token.
- *
- * @param samlToken the SAML token
- *
- * @return the string
- */
- public static String encodeSAMLToken(final byte[] samlToken) {
- return new String(Base64.encode(samlToken));
- }
-
- /**
- * Read stork SAML from file.
- *
- * @param resource the resource
- *
- * @return the byte[]
- * @throws IOException the exception
- *
- */
- public static byte[] readStorkSamlFromFile(final String resource)
- throws IOException {
- InputStream inputStream = null;
- byte[] bytes;
-
- try {
- inputStream = StorkAuthRequestTest.class
- .getResourceAsStream(resource);
-
- // Create the byte array to hold the data
- bytes = new byte[(int) inputStream.available()];
- inputStream.read(bytes);
- } catch (IOException e) {
- LOG.error("Error read from file: " + resource);
- throw e;
- } finally {
- IOUtils.closeQuietly(inputStream);
+
+ /** The Constant LOG. */
+ private static final Logger LOG = LoggerFactory.getLogger(SSETestUtils.class.getName());
+
+ /**
+ * Instantiates a new sSE test utils.
+ */
+ private SSETestUtils() {
+ }
+
+ /**
+ * Prints the tree DOM.
+ *
+ * @param samlToken
+ * the SAML token
+ * @param isIndent
+ * the is indent
+ *
+ * @return the string
+ * @throws TransformerException
+ * the exception
+ */
+ public static String printTreeDOM(final Element samlToken, final boolean isIndent) throws TransformerException {
+ // set up a transformer
+ final TransformerFactory transfac = TransformerFactory.newInstance();
+ final Transformer trans = transfac.newTransformer();
+ trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ trans.setOutputProperty(OutputKeys.INDENT, String.valueOf(isIndent));
+
+ // create string from XML tree
+ final StringWriter stringWriter = new StringWriter();
+ final StreamResult result = new StreamResult(stringWriter);
+ final DOMSource source = new DOMSource(samlToken);
+ trans.transform(source, result);
+ final String xmlString = stringWriter.toString();
+
+ return xmlString;
+ }
+
+ /**
+ * Marshall.
+ *
+ * @param samlToken
+ * the SAML token
+ *
+ * @return the byte[]
+ *
+ * @throws MarshallingException
+ * the marshalling exception
+ * @throws ParserConfigurationException
+ * the parser configuration exception
+ * @throws TransformerException
+ * the transformer exception
+ */
+ public static byte[] marshall(final XMLObject samlToken) throws MarshallingException, ParserConfigurationException, TransformerException {
+
+ final javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
+ dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ dbf.setNamespaceAware(true);
+ dbf.setIgnoringComments(true);
+ final javax.xml.parsers.DocumentBuilder docBuild = dbf.newDocumentBuilder();
+
+ // Get the marshaller factory
+ final MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory();
+
+ // Get the Subject marshaller
+ final Marshaller marshaller = marshallerFactory.getMarshaller(samlToken);
+
+ final Document doc = docBuild.newDocument();
+
+ // Marshall the SAML token
+ marshaller.marshall(samlToken, doc);
+
+ // Obtain a byte array representation of the marshalled SAML object
+ final DOMSource domSource = new DOMSource(doc);
+ final StringWriter writer = new StringWriter();
+ final StreamResult result = new StreamResult(writer);
+ final TransformerFactory transFact = TransformerFactory.newInstance();
+ final Transformer transformer = transFact.newTransformer();
+ transformer.transform(domSource, result);
+
+ return writer.toString().getBytes();
+ }
+
+ /**
+ * Encode SAML token.
+ *
+ * @param samlToken
+ * the SAML token
+ *
+ * @return the string
+ */
+ public static String encodeSAMLToken(final byte[] samlToken) {
+ return new String(Base64.encode(samlToken));
}
- return bytes;
- }
+ /**
+ * Read stork SAML from file.
+ *
+ * @param resource
+ * the resource
+ *
+ * @return the byte[]
+ * @throws IOException
+ * the exception
+ *
+ */
+ public static byte[] readStorkSamlFromFile(final String resource) throws IOException {
+ InputStream inputStream = null;
+ byte[] bytes;
+
+ try {
+ inputStream = StorkAuthRequestTest.class.getResourceAsStream(resource);
+
+ // Create the byte array to hold the data
+ bytes = new byte[(int) inputStream.available()];
+ inputStream.read(bytes);
+ } catch (IOException e) {
+ LOG.error("Error read from file: " + resource);
+ throw e;
+ } finally {
+ IOUtils.closeQuietly(inputStream);
+ }
+ return bytes;
+
+ }
}