Enterprise Java Development@TOPIC@

Chapter 116. JAX-RS Resource Security

116.1. Web Security Setup
116.1.1. Assign WAR security-domain: jboss-web.xml
116.1.2. Assign WAR auth-method: web.xml
116.2. JAX-RS Resource Class
116.2.1. JAX-RS Debug Methods
116.3. JAX-RS Client Authentication
116.3.1. Authorization Header
116.3.2. JAX-RS Client Authorization Filter
116.3.3. JAX-RS Client Authorization Filter Registration
116.3.4. Protect BASIC Credentials with HTTPS
116.4. Declarative Access Control
116.4.1. Two intermediate contexts defined to access Nested Pinger Resource
116.4.2. Same Nested Pinger Resource Exposed
116.4.3. Declarative Access Control Constraints
116.4.4. Nested Resource Called from Two URIs
116.5. Summary
$ jar tf target/securePingJaxRsWAR-5.0.0-SNAPSHOT.war
...
WEB-INF/beans.xml
WEB-INF/web.xml
WEB-INF/jboss-web.xml
  • BASIC - username and password passed in "Authentication" header Base64 encoded

  • FORM - credentials submitted as part of a form response

  • CLIENT-CERT - client public key authenticated as part of HTTPS connection

  • DIGEST - an encyrpted form of BASIC

  • EXTERNAL


# web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  version="4.0">
    ...
</web-app>

# web.xml
<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>ApplicationRealm</realm-name>
</login-config>
  • May need separate WARs for mixed solutions using BASIC (API) and FORM

  • Wildfly legacy security offers the following option


# web.xml
  <!-- if mixing JAX-RS BASIC with HTML FORM
  http://undertow.io/undertow-docs/undertow-docs-1.3.0/index.html#servlet-security
   -->
  <auth-method>BASIC?silent=true,FORM</auth-method>
  • API will silently accept BASIC Authorization header if supplied

  • API will not provide any response codes or headers making browser believe it accepts BASIC

  • Web UI will act as if it only uses FORM

@ApplicationPath("api")

public class SecurePingJaxRsApplication extends Application {
@Path("ping")

public class SecurePingResource {
    //this injection requires CDI, which requires a WEB-INF/beans.xml file be in place to activate
    @EJB(beanName="SecurePingEJB", beanInterface=SecurePingLocal.class)
    private SecurePing secureService;
    
    @Context
    private SecurityContext ctx;