From Dogtag
Jump to: navigation, search


This page describes the process to set up Keycloak as an identity provider for PKI.

Note: This functionality is not yet officially supported.

Building Keycloak

To build Keycloak:

$ git clone
$ cd keycloak
$ mvn install

See also:


To install Keycloak server:

$ wget
$ tar xzvf keycloak-6.0.1.tar.gz
$ cd keycloak-6.0.1/bin

To setup admin user:

$ ./ -u admin -p Secret.123

To start Keycloak server:

$ ./ -b=

Adding a New Realm

To access the Admin Console, open http://$HOSTNAME:8080/auth/admin/.

To access a realm, open http://$HOSTNAME:8080/auth/realms/<realm>/account.

Adding Roles in Realm

Adding Users in Realm

Configuring Tomcat Client

To create a Tomcat server with TLS connector:

$ pki-server create tomcat@pki
$ pki-server http-connector-mod -i tomcat@pki --port 9080 Connector1

To install Keycloak client adapter:

$ curl \
    --output keycloak-tomcat-adapter-dist-7.0.0.tar.gz
$ mkdir lib
$ cd lib
$ tar xzvf ../keycloak-tomcat-adapter-dist-7.0.0.tar.gz
$ mv * /var/lib/tomcats/pki/lib

To enable Keycloak, prepare context.xml for customization:

$ cd /var/lib/tomcats/pki/conf
$ rm context.xml
$ cp /etc/tomcat/context.xml .

Then add the following <Valve> element:

    <Valve className="org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve"/>

To register Tomcat client:

  • Open Keycloak Admin Console
  • Click Clients -> Create

To generate client adapter configuration, click Installation:

  • Format option: Keycloak OIDC JSON

Save the configuration as keycloak.json, then store it in PKI web application's WEB-INF folder (e.g. /usr/share/pki/ca/webapps/ca/WEB-INF/keycloak.json).

  "realm": "demo",
  "auth-server-url": "http://$HOSTNAME:8080/auth",
  "ssl-required": "external",
  "resource": "tomcat",
  "public-client": true,
  "confidential-port": 0

To configure web application, edit the WEB-INF/web.xml:

  • Define security constraints
  • Define login-config with auth-method set to KEYCLOAK
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app 
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:///usr/share/pki/setup/web-app_2_3.dtd">

            <web-resource-name>Account Services</web-resource-name>




To run Tomcat server:

$ pki-server run tomcat@pki

See Also