View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.wss4j.dom.components.crypto;
21  
22  import java.security.Security;
23  
24  import org.apache.wss4j.common.crypto.WSProviderConfig;
25  import org.apache.wss4j.dom.engine.WSSConfig;
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertNotNull;
29  import static org.junit.jupiter.api.Assertions.assertNull;
30  
31  /**
32   * Test loading and removing security providers via WSSConfig
33   */
34  public class WSSConfigTest {
35  
36      @Test
37      public void testWSSConfig() {
38          WSSConfig.cleanUp();
39          WSSConfig.init();
40  
41          // Check providers
42          assertNotNull(Security.getProvider("STRTransform"));
43          assertNotNull(Security.getProvider("AttachmentContentSignatureTransform"));
44          assertNotNull(Security.getProvider("AttachmentCompleteSignatureTransform"));
45          assertNotNull(Security.getProvider("ApacheXMLDSig"));
46  
47          WSSConfig.cleanUp();
48  
49          assertNull(Security.getProvider("STRTransform"));
50          assertNull(Security.getProvider("AttachmentContentSignatureTransform"));
51          assertNull(Security.getProvider("AttachmentCompleteSignatureTransform"));
52          assertNull(Security.getProvider("ApacheXMLDSig"));
53  
54      }
55  
56      @Test
57      public void testWSProviderConfig() {
58          WSProviderConfig.cleanUp();
59          WSProviderConfig.init();
60  
61          // Check providers
62          assertNotNull(Security.getProvider("ApacheXMLDSig"));
63  
64          WSProviderConfig.cleanUp();
65  
66          assertNull(Security.getProvider("ApacheXMLDSig"));
67  
68          WSProviderConfig.init(true, true, true);
69          assertNotNull(Security.getProvider("ApacheXMLDSig"));
70          assertNotNull(Security.getProvider("BC"));
71          assertNotNull(Security.getProvider("TLSP"));
72  
73          WSProviderConfig.cleanUp();
74  
75          assertNull(Security.getProvider("ApacheXMLDSig"));
76          assertNull(Security.getProvider("BC"));
77          assertNull(Security.getProvider("TLSP"));
78  
79      }
80  
81  }