+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi.wsse;\r
-\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-\r
-import javax.xml.stream.XMLStreamException;\r
-\r
-import org.onap.aaf.cadi.BasicCred;\r
-\r
-\r
-/**\r
- * WSSE Parser\r
- * \r
- * Read the User and Password from WSSE Formatted SOAP Messages \r
- * \r
- * This class uses StAX so that processing is stopped as soon as the Security User/Password are read into BasicCred, or the Header Ends\r
- * \r
- * This class is intended to be created once (or very few times) and reused as much as possible.\r
- * \r
- * It is as thread safe as StAX parsing is.\r
- * \r
- */\r
-public class WSSEParser {\r
- private static final String SOAP_NS = "http://schemas.xmlsoap.org/soap/envelope/";\r
- private static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";\r
- private Match<BasicCred> parseTree;\r
- //private XMLInputFactory inputFactory;\r
-\r
- public WSSEParser() {\r
- // soap:Envelope/soap:Header/wsse:Security/wsse:UsernameToken/[wsse:Password&wsse:Username]\r
- parseTree = new Match<BasicCred>(SOAP_NS,"root", // need a root level to start from... Doesn't matter what the tag is\r
- new Match<BasicCred>(SOAP_NS,"Envelope",\r
- new Match<BasicCred>(SOAP_NS,"Header",\r
- new Match<BasicCred>(WSSE_NS,"Security",\r
- new Match<BasicCred>(WSSE_NS,"UsernameToken",\r
- new Match<BasicCred>(WSSE_NS,"Password").set(new Action<BasicCred>() {\r
- public boolean content(BasicCred bc,String text) {\r
- bc.setCred(text.getBytes());\r
- return true;\r
- }\r
- }),\r
- new Match<BasicCred>(WSSE_NS,"Username").set(new Action<BasicCred>() {\r
- public boolean content(BasicCred bc,String text) {\r
- bc.setUser(text);\r
- return true;\r
- }\r
- })\r
- ).stopAfter() // if found, end when UsernameToken ends (no further processing needed)\r
- )\r
- ).stopAfter() // Stop Processing when Header Ends\r
- ).exclusive()// Envelope must match Header, and no other. FYI, Body comes after Header short circuits (see above), so it's ok\r
- ).exclusive(); // root must be Envelope\r
- //inputFactory = XMLInputFactory.newInstance();\r
- }\r
- \r
- public XMLStreamException parse(BasicCred bc, InputStream is) throws IOException {\r
- try {\r
- parseTree.onMatch(bc, new XReader(is));\r
- return null;\r
- } catch (XMLStreamException e) {\r
- return e;\r
- }\r
- }\r
-}\r