forked from javaee-samples/javaee7-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for Servlet client-cert authentication
- Loading branch information
1 parent
cbd30dc
commit c20bf73
Showing
8 changed files
with
575 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/clientKeyStore.jks | ||
/clientTrustStore.jks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.javaee7</groupId> | ||
<artifactId>servlet</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>servlet-security-clientcert</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<name>Java EE 7 Sample: servlet - security-clientcert</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk15on</artifactId> | ||
<version>1.59</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcpkix-jdk15on</artifactId> | ||
<version>1.59</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>payara-micro-managed</id> | ||
<build> | ||
<testResources> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
<filtering>true</filtering> | ||
</testResource> | ||
</testResources> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemProperties> | ||
<payara.extraMicroOptions>--postdeploycommandfile ${project.build.directory}/test-classes/addUsersPayara.txt</payara.extraMicroOptions> | ||
</systemProperties> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
25 changes: 25 additions & 0 deletions
25
...urity-clientcert/src/main/java/org/javaee7/servlet/security/clientcert/SecureServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** Copyright Payara Services Limited **/ | ||
package org.javaee7.servlet.security.clientcert; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* @author Arjan Tijms | ||
*/ | ||
@WebServlet(urlPatterns = { "/SecureServlet" }) | ||
public class SecureServlet extends HttpServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
response.getWriter().print("principal " + request.getUserPrincipal() + " in role g1:" + request.isUserInRole("g1")); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
servlet/security-clientcert/src/main/webapp/WEB-INF/glassfish-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** Copyright Payara Services Limited **/ | ||
--> | ||
<!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"> | ||
<glassfish-web-app> | ||
|
||
<security-role-mapping> | ||
<role-name>g1</role-name> | ||
<group-name>g1</group-name> | ||
<principal-name>C=UK, ST=lak, L=zak, O=kaz, OU=bar, CN=lfoo</principal-name> | ||
</security-role-mapping> | ||
|
||
</glassfish-web-app> |
29 changes: 29 additions & 0 deletions
29
servlet/security-clientcert/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** Copyright Payara Services Limited **/ | ||
--> | ||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
version="3.1"> | ||
|
||
<security-constraint> | ||
<web-resource-collection> | ||
<web-resource-name>SecureServlet</web-resource-name> | ||
<url-pattern>/SecureServlet</url-pattern> | ||
<http-method>GET</http-method> | ||
<http-method>POST</http-method> | ||
</web-resource-collection> | ||
<auth-constraint> | ||
<role-name>g1</role-name> | ||
</auth-constraint> | ||
</security-constraint> | ||
|
||
<login-config> | ||
<auth-method>CLIENT-CERT</auth-method> | ||
</login-config> | ||
|
||
<security-role> | ||
<role-name>g1</role-name> | ||
</security-role> | ||
</web-app> |
Oops, something went wrong.