diff options
author | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-08-27 12:07:52 +0200 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-08-27 12:07:52 +0200 |
commit | 1051a42329a603821f415383343d253724d4cd65 (patch) | |
tree | f8a0b6e8445b7034dfe38d6ba3a61f1429a75a6e /id/server/stork2-saml-engine/src/test/java/eu/stork/peps/test/simple/SSETestUtils.java | |
parent | bb1b12ac5b240629e16ea1c7a50891e99f4adc14 (diff) | |
parent | eb0cf88708f3d689c2cb6bb0dbf83dd290bee887 (diff) | |
download | moa-id-spss-1051a42329a603821f415383343d253724d4cd65.tar.gz moa-id-spss-1051a42329a603821f415383343d253724d4cd65.tar.bz2 moa-id-spss-1051a42329a603821f415383343d253724d4cd65.zip |
Merge STORK-SAML-Engine 1.5.1 and STORK-Commons 1.5.1
Conflicts:
id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AttributeProviderFactory.java
id/server/stork2-saml-engine/src/main/java/eu/stork/peps/auth/engine/core/validator/CustomAttributeQueryValidator.java
id/server/stork2-saml-engine/src/main/java/eu/stork/peps/auth/engine/core/validator/MultipleAssertionResponseValidator.java
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.java | 248 |
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; + + } } |