1   /*
2    * Copyright 2005-2010 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.springframework.ws.context.MessageContext;
20  import org.springframework.ws.soap.SoapMessage;
21  
22  import org.junit.Test;
23  import org.w3c.dom.Document;
24  
25  public abstract class Wss4jMessageInterceptorUsernameTokenSignatureTestCase extends Wss4jTestCase {
26  
27      @Test
28      public void testAddUsernameTokenSignature() throws Exception {
29          Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
30          interceptor.setSecurementActions("UsernameTokenSignature");
31          interceptor.setSecurementUsername("Bert");
32          interceptor.setSecurementPassword("Ernie");
33          interceptor.afterPropertiesSet();
34          SoapMessage message = loadSoap11Message("empty-soap.xml");
35          MessageContext context = getSoap11MessageContext(message);
36          interceptor.secureMessage(message, context);
37  
38          Document doc = getDocument(message);
39          assertXpathEvaluatesTo("Invalid Username", "Bert",
40                  "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/wsse:UsernameToken/wsse:Username/text()", doc);
41          assertXpathExists("Invalid Password",
42                  "/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()",
43                  doc);
44      }
45  }