Skip to content

Commit c20bf73

Browse files
committed
Added test for Servlet client-cert authentication
1 parent cbd30dc commit c20bf73

File tree

8 files changed

+575
-1
lines changed

8 files changed

+575
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
<dependency>
239239
<groupId>net.sourceforge.htmlunit</groupId>
240240
<artifactId>htmlunit</artifactId>
241-
<version>2.13</version>
241+
<version>2.31</version>
242242
<scope>test</scope>
243243
</dependency>
244244
<dependency>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/clientKeyStore.jks
2+
/clientTrustStore.jks
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.javaee7</groupId>
8+
<artifactId>servlet</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>servlet-security-clientcert</artifactId>
13+
<packaging>war</packaging>
14+
15+
<name>Java EE 7 Sample: servlet - security-clientcert</name>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.bouncycastle</groupId>
20+
<artifactId>bcprov-jdk15on</artifactId>
21+
<version>1.59</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.bouncycastle</groupId>
26+
<artifactId>bcpkix-jdk15on</artifactId>
27+
<version>1.59</version>
28+
</dependency>
29+
</dependencies>
30+
31+
<profiles>
32+
<profile>
33+
<id>payara-micro-managed</id>
34+
<build>
35+
<testResources>
36+
<testResource>
37+
<directory>src/test/resources</directory>
38+
<filtering>true</filtering>
39+
</testResource>
40+
</testResources>
41+
<plugins>
42+
<plugin>
43+
<artifactId>maven-surefire-plugin</artifactId>
44+
<configuration>
45+
<systemProperties>
46+
<payara.extraMicroOptions>--postdeploycommandfile ${project.build.directory}/test-classes/addUsersPayara.txt</payara.extraMicroOptions>
47+
</systemProperties>
48+
</configuration>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</profile>
53+
</profiles>
54+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee7.servlet.security.clientcert;
3+
4+
import java.io.IOException;
5+
6+
import javax.servlet.ServletException;
7+
import javax.servlet.annotation.WebServlet;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
/**
13+
* @author Arjan Tijms
14+
*/
15+
@WebServlet(urlPatterns = { "/SecureServlet" })
16+
public class SecureServlet extends HttpServlet {
17+
18+
private static final long serialVersionUID = 1L;
19+
20+
@Override
21+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
22+
response.getWriter().print("principal " + request.getUserPrincipal() + " in role g1:" + request.isUserInRole("g1"));
23+
}
24+
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/** Copyright Payara Services Limited **/
4+
-->
5+
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
6+
<glassfish-web-app>
7+
8+
<security-role-mapping>
9+
<role-name>g1</role-name>
10+
<group-name>g1</group-name>
11+
<principal-name>C=UK, ST=lak, L=zak, O=kaz, OU=bar, CN=lfoo</principal-name>
12+
</security-role-mapping>
13+
14+
</glassfish-web-app>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/** Copyright Payara Services Limited **/
4+
-->
5+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
8+
version="3.1">
9+
10+
<security-constraint>
11+
<web-resource-collection>
12+
<web-resource-name>SecureServlet</web-resource-name>
13+
<url-pattern>/SecureServlet</url-pattern>
14+
<http-method>GET</http-method>
15+
<http-method>POST</http-method>
16+
</web-resource-collection>
17+
<auth-constraint>
18+
<role-name>g1</role-name>
19+
</auth-constraint>
20+
</security-constraint>
21+
22+
<login-config>
23+
<auth-method>CLIENT-CERT</auth-method>
24+
</login-config>
25+
26+
<security-role>
27+
<role-name>g1</role-name>
28+
</security-role>
29+
</web-app>

0 commit comments

Comments
 (0)