Skip to content

Commit dd04717

Browse files
authored
Merge pull request #444 from jGauravGupta/QA-183
QA-183 Remove BouncyCastle provider from javaee7-samples/security-clientcert-jce after execution
2 parents 446a893 + 66864e0 commit dd04717

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

servlet/security-clientcert-jce/src/main/java/org/javaee7/servlet/security/clientcert/jce/BouncyServlet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
3535
response.getWriter().print("pos:" + pos);
3636
}
3737

38+
@Override
39+
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40+
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
41+
}
42+
3843
}

servlet/security-clientcert-jce/src/test/java/org/javaee7/servlet/security/clientcert/jce/SecureServletTest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.security.cert.CertificateException;
2727
import java.security.cert.X509Certificate;
2828
import java.util.Date;
29+
import static java.util.logging.Level.INFO;
2930
import java.util.logging.Logger;
3031

3132
import org.apache.commons.logging.Log;
@@ -51,8 +52,10 @@
5152
import org.junit.runner.RunWith;
5253
import org.omnifaces.utils.security.Certificates;
5354

55+
import com.gargoylesoftware.htmlunit.HttpMethod;
5456
import com.gargoylesoftware.htmlunit.TextPage;
5557
import com.gargoylesoftware.htmlunit.WebClient;
58+
import com.gargoylesoftware.htmlunit.WebRequest;
5659

5760
/**
5861
* @author Arjan Tijms
@@ -172,29 +175,32 @@ public void setup() throws FileNotFoundException, IOException {
172175
// and sent a reply to the server
173176
webClient.getOptions().setSSLClientCertificate(new File(clientKeyStorePath).toURI().toURL(), "changeit", "jks");
174177

178+
// First do a request to install Bouncy Castle as provider
179+
// This is a normal HTTP request and doesn't use certificate authentication
180+
TextPage pageb = webClient.getPage(base + "BouncyServlet");
181+
log.log(INFO, "Bouncy Castle provider inserted at position: {0}", pageb.getContent());
182+
175183
System.out.println("*********** SETUP DONE ***************************\n");
176184
}
177185

178186
@After
179-
public void tearDown() {
187+
public void tearDown() throws IOException {
188+
// Remove Bouncy Castle as provider
189+
TextPage pageb = webClient.getPage(new WebRequest(new URL(base + "BouncyServlet"), HttpMethod.DELETE));
190+
log.log(INFO, "Bouncy Castle provider removed: {0}", pageb.getContent());
191+
180192
webClient.getCookieManager().clearCookies();
181193
webClient.close();
182194
System.out.println("\n*********** TEST END ***************************\n");
183195
}
184196

185197
@Test
186198
public void testGetWithCorrectCredentials() throws Exception {
187-
199+
188200
System.out.println("\n*********** TEST START ***************************\n");
189-
201+
190202
try {
191-
192-
// First do a request to install Bouncy Castle as provider
193-
// This is a normal HTTP request and doesn't use certificate authentication
194-
TextPage pageb = webClient.getPage(base + "BouncyServlet");
195203

196-
log.info("Bouncy Castle provider inserted at position: " + pageb.getContent());
197-
198204
// With Bouncy Castle installed, do the request via HTTPS to the secured
199205
// Servlet
200206
TextPage page = webClient.getPage(baseHttps + "SecureServlet");

0 commit comments

Comments
 (0)