1   /*
2    * Copyright 2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.security.wss4j;
18  
19  import org.w3c.dom.Document;
20  
21  import org.springframework.ws.context.MessageContext;
22  import org.springframework.ws.soap.SoapMessage;
23  
24  public abstract class Wss4jMessageInterceptorUsernameTokenSignatureTestCase extends Wss4jTestCase {
25  
26      public void testAddUsernameTokenSignature() throws Exception {
27          Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
28          interceptor.setSecurementActions("UsernameTokenSignature");
29          interceptor.setSecurementUsername("Bert");
30          interceptor.setSecurementPassword("Ernie");
31          interceptor.afterPropertiesSet();
32          SoapMessage message = loadSoap11Message("empty-soap.xml");
33          MessageContext context = getSoap11MessageContext(message);
34          interceptor.secureMessage(message, context);
35  
36          Document doc = getDocument(message);
37          assertXpathEvaluatesTo("Invalid Username", "Bert",
38                  "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()", doc);
39          assertXpathExists("Invalid Password",
40                  "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Password[@Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest']/text()",
41                  doc);
42      }
43  }