[[_jboss_adapter]] {% if book.community %} ==== JBoss EAP/Wildfly Adapter {% endif %} {% if book.product %} ==== JBoss EAP Adapter {% endif %} {% if book.community %} To be able to secure WAR apps deployed on JBoss EAP, WildFly or JBoss AS, you must install and configure the {{book.project.name}} adapter subsystem. You then have two options to secure your WARs. {% endif %} {% if book.product %} To be able to secure WAR apps deployed on JBoss EAP, you must install and configure the {{book.project.name}} adapter subsystem. You then have two options to secure your WARs. {% endif %} You can provide an adapter config file in your WAR and change the auth-method to KEYCLOAK within web.xml. Alternatively, you don't have to modify your WAR at all and you can secure it via the {{book.project.name}} adapter subsystem configuration in `standalone.xml`. Both methods are described in this section. [[_jboss_adapter_installation]] ===== Adapter Installation Adapters are available as a separate archive and are also available as Maven artifacts. {% if book.community %} Install on Wildfly 9 or 10: [source, subs="attributes"] ---- $ cd $WILDFLY_HOME $ unzip keycloak-wildfly-adapter-dist-{{book.project.version}}.zip ---- Install on Wildfly 8: [source, subs="attributes"] ---- $ cd $WILDFLY_HOME $ unzip keycloak-wf8-adapter-dist-{{book.project.version}}.zip ---- Install on JBoss EAP 7: [source, subs="attributes"] ---- $ cd $EAP_HOME $ unzip keycloak-eap7-adapter-dist-{{book.project.version}}.zip ---- Install on JBoss EAP 6: [source, subs="attributes"] ---- $ cd $EAP_HOME $ unzip keycloak-eap6-adapter-dist-{{book.project.version}}.zip ---- Install on JBoss AS 7.1: [source, subs="attributes"] ---- $ cd $JBOSS_HOME $ unzip keycloak-as7-adapter-dist-{{book.project.version}}.zip ---- {% endif %} {% if book.product %} Install on JBoss EAP 7: [source, subs="attributes"] ---- $ cd $EAP_HOME $ unzip rh-sso-{{book.project.version}}-eap7-adapter.zip ---- Install on JBoss EAP 6: [source, subs="attributes"] ---- $ cd $EAP_HOME $ unzip rh-sso-{{book.project.version}}-eap6-adapter.zip ---- {% endif %} This ZIP archive contains JBoss Modules specific to the {{book.project.name}} adapter. It also contains JBoss CLI scripts to install and configure the adapter. Once the ZIP archive is extracted you have to enable the {{book.project.name}} subystem in the server configuration (i.e. `standalone.xml`). The easiest way to do this is to use the supplied JBoss CLI scripts. To install and configure the adapter, first start the server and then run the JBoss CLI installation script : [source] ---- $ ./bin/jboss-cli.sh -c --file=adapter-install.cli ---- The script will add the required configuration to the server configuration file. {% if book.community %} For JBoss EAP 7 and WildFly 9+ there is also an offline CLI script that can be used to install the adapter while the server is not running: {% endif %} {% if book.product %} For JBoss EAP 7 there is also an offline CLI script that can be used to install the adapter while the server is not running: {% endif %} [source] ---- $ ./bin/jboss-cli.sh --file=adapter-install-offline.cli ---- If you are planning to add it manually you need to add the extension and subsystem definition to the server configuration: [source,xml] ---- ... ... ---- If you need to be able to propagate the security context from the web tier to the EJB tier you also need to add the `keycloak` security domain: [source,xml] ---- ... ... ---- For example, if you have a JAX-RS service that is an EJB within your WEB-INF/classes directory, you'll want to annotate it with the @SecurityDomain annotation as follows: [source] ---- import org.jboss.ejb3.annotation.SecurityDomain; import org.jboss.resteasy.annotations.cache.NoCache; import javax.annotation.security.RolesAllowed; import javax.ejb.EJB; import javax.ejb.Stateless; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import java.util.ArrayList; import java.util.List; @Path("customers") @Stateless @SecurityDomain("keycloak") public class CustomerService { @EJB CustomerDB db; @GET @Produces("application/json") @NoCache @RolesAllowed("db_user") public List getCustomers() { return db.getCustomers(); } } ---- ===== Required Per WAR Configuration This section describes how to secure a WAR directly by adding config and editing files within your WAR package. The first thing you must do is create a `keycloak.json` adapter config file within the `WEB-INF` directory of your WAR. The format of this config file is describe in the <> section. Next you must set the `auth-method` to `KEYCLOAK` in `web.xml`. You also have to use standard servlet security to specify role-base constraints on your URLs. Here's an example: [source,xml] ---- application Admins /admin/* admin CONFIDENTIAL Customers /customers/* user CONFIDENTIAL KEYCLOAK this is ignored currently admin user ---- ===== Securing WARs via Adapter Subsystem You do not have to modify your WAR to secure it with {{book.project.name}}. Instead you can externally secure it via the {{book.project.name}} Adapter Subsystem. While you don't have to specify KEYCLOAK as an `auth-method`, you still have to define the `security-constraints` in `web.xml`. You do not, however, have to create a `WEB-INF/keycloak.json` file. This metadata is instead defined within server configuration (i.e. `standalone.xml`) in the {{book.project.name}} subsystem definition. [source,xml] ---- demo MIGfMA0GCSqGSIb3DQEBAQUAA http://localhost:8081/auth external customer-portal password ---- The `secure-deployment` `name` attribute identifies the WAR you want to secure. Its value is the `module-name` defined in `web.xml` with `.war` appended. The rest of the configuration corresponds pretty much one to one with the `keycloak.json` configuration options defined in <>. The exception is the `credential` element. To make it easier for you, you can go to the {{book.project.name}} Administration Console and go to the Client/Installation tab of the application this WAR is aligned with. It provides an example XML file you can cut and paste. If you have multiple deployments secured by the same realm you can share the realm configuration in a separate element. For example: [source,xml] ---- MIGfMA0GCSqGSIb3DQEBA... http://localhost:8080/auth external demo customer-portal password demo product-portal password demo database-service true ----