Author: buildbot
Date: Thu May 26 12:47:35 2016
New Revision: 989184
Log:
Production update by buildbot for cxf
Modified:
websites/production/cxf/content/cache/docs.pageCache
websites/production/cxf/content/docs/jax-rs-oauth2.html
Modified: websites/production/cxf/content/cache/docs.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/cxf/content/docs/jax-rs-oauth2.html
==============================================================================
--- websites/production/cxf/content/docs/jax-rs-oauth2.html (original)
+++ websites/production/cxf/content/docs/jax-rs-oauth2.html Thu May 26 12:47:35
2016
@@ -118,11 +118,11 @@ Apache CXF -- JAX-RS OAuth2
<!-- Content -->
<div class="wiki-content">
<div id="ConfluenceContent"><h1 id="JAX-RSOAuth2-JAX-RS:OAuth2">JAX-RS:
OAuth2</h1><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1464263220130 {padding: 0px;}
-div.rbtoc1464263220130 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1464263220130 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1464266818744 {padding: 0px;}
+div.rbtoc1464266818744 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1464266818744 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1464263220130">
+/*]]>*/</style></p><div class="toc-macro rbtoc1464266818744">
<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-JAX-RS:OAuth2">JAX-RS: OAuth2</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-Introduction">Introduction</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-Mavendependencies">Maven dependencies</a></li><li><a
shape="rect" href="#JAX-RSOAuth2-ClientRegistration">Client
Registration</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-DevelopingOAuth2Servers">Developing OAuth2 Servers</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-AuthorizationService">Authorization Service</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-HowtocreateAuthorizationView">How to create Authorization
View</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-EndUserNameinAuthorizationForm">EndUser Name in
Authorization Form</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-PublicClients(Devices)">Public Clients (Devices)</a>
@@ -130,10 +130,12 @@ div.rbtoc1464263220130 li {margin-left:
</li></ul>
</li><li><a shape="rect"
href="#JAX-RSOAuth2-AccessTokenService">AccessTokenService</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-AccessTokenTypes">Access Token Types</a>
-<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-Bearer">Bearer</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-HAWK">HAWK</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-MAC">MAC</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-Encryptedtokens">Encrypted tokens</a>
-<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-UsingSecretKeys">Using Secret Keys</a></li><li><a
shape="rect" href="#JAX-RSOAuth2-UsingCertificates">Using
Certificates</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-UsingCertificatesandSecretKeys">Using Certificates and
Secret Keys</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-EncryptedJWTTokens">Encrypted JWT Tokens</a></li></ul>
+<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-Bearer">Bearer</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-HAWK">HAWK</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-MAC">MAC</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-EncryptedandSignedTokens">Encrypted and Signed Tokens</a>
+<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-EncryptedandSignedJWTTokens">Encrypted and Signed JWT
Tokens</a></li></ul>
</li><li><a shape="rect" href="#JAX-RSOAuth2-Customtokens">Custom
tokens</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-SimpleTokensandAudience">Simple Tokens and
Audience</a></li></ul>
-</li><li><a shape="rect"
href="#JAX-RSOAuth2-OAuthJSONProvider">OAuthJSONProvider</a></li><li><a
shape="rect"
href="#JAX-RSOAuth2-AccessTokenValidatorService">AccessTokenValidatorService</a></li><li><a
shape="rect"
href="#JAX-RSOAuth2-TokenIntrospectionService">TokenIntrospectionService</a></li></ul>
+</li><li><a shape="rect"
href="#JAX-RSOAuth2-OAuthJSONProvider">OAuthJSONProvider</a></li></ul>
+</li><li><a shape="rect"
href="#JAX-RSOAuth2-AccessTokenValidationService">Access Token Validation
Service</a>
+<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-AccessTokenValidatorService">AccessTokenValidatorService</a></li><li><a
shape="rect"
href="#JAX-RSOAuth2-TokenIntrospectionService">TokenIntrospectionService</a></li></ul>
</li><li><a shape="rect"
href="#JAX-RSOAuth2-TokenRevocationService">TokenRevocationService</a></li><li><a
shape="rect" href="#JAX-RSOAuth2-SupportedGrants">Supported Grants</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#JAX-RSOAuth2-AuthorizationCode">Authorization Code</a></li><li><a
shape="rect" href="#JAX-RSOAuth2-Implicit">Implicit</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-ClientCredentials">Client Credentials</a></li><li><a
shape="rect" href="#JAX-RSOAuth2-ResourceOwnerPasswordCredentials">Resource
Owner Password Credentials</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-RefreshToken">Refresh Token</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-Assertions">Assertions</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-CustomGrants">Custom Grants</a></li></ul>
</li><li><a shape="rect"
href="#JAX-RSOAuth2-RedirectionFlowFilters">Redirection Flow
Filters</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-AccessTokenResponseFilters">AccessTokenResponse
Filters</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-PreAuthorizedaccesstokens">PreAuthorized access
tokens</a></li><li><a shape="rect"
href="#JAX-RSOAuth2-Pre-registeredscopes">Pre-registered scopes</a></li><li><a
shape="rect" href="#JAX-RSOAuth2-WritingOAuthDataProvider">Writing
OAuthDataProvider</a>
@@ -221,7 +223,7 @@ Cookie=[JSESSIONID=1c289vha0cxfe],
<pre>GET
http://localhost:8080/services/social/authorize?client_id=mobileClient&response_type=code
</pre>
-</div></div><p>Assuming the 'mobileClient' has been registered as public one
with no secret and the service has been set up to support such clients, the end
user will get a chance to authorize this client the same way it can do
confidential clients, and after this user gets back a code (delivered directly
in the response HTML page by default) the user will enter the code securely
into the device which will then replace it for a time-scoped access token by
contacting AccessTokenService.</p><h4
id="JAX-RSOAuth2-SecurecodeacquisitionwithredirectURI">Secure code acquisition
with redirect URI</h4><p>The following <a shape="rect" class="external-link"
href="https://tools.ietf.org/html/draft-ietf-oauth-spop-15"
rel="nofollow">extension</a> is supported to help public clients with redirect
URIs to accept the code securely.</p><p>The public (mobile) client will include
a 'code_verifier' value when requesting the authorization code and it will be
saved by Authorization service, with the help
of the registered AuthorizationCodeDataProvider into an instance of
ServerAuthorizationCodeGrant. The client will next request a token providing
the 'code' and 'code_challenge' - the latter will be compared by
AuthorizationCodeGrantHandler with the original 'code_verifier'. By default,
the 'code_challenge' is expected to be equal to the original 'code_verifier',
but the grant handler can be registered with the custom
org.apache.cxf.rs.security.oauth2.grants.code.CodeVerifierTransformer - CXF
ships a DigestCodeVerifier which implements a transformation mentioned in the
extension.</p><p> </p><h2
id="JAX-RSOAuth2-AccessTokenService">AccessTokenService</h2><p>The role of
AccessTokenService is to exchange a token grant for a new access token which
will be used by the client to access the end user's resources. <br
clear="none"> Here is an example request log:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>Assuming the 'mobileClient' has been registered as public one
with no secret and the service has been set up to support such clients, the end
user will get a chance to authorize this client the same way it can do
confidential clients, and after this user gets back a code (delivered directly
in the response HTML page by default) the user will enter the code securely
into the device which will then replace it for a time-scoped access token by
contacting AccessTokenService.</p><h4
id="JAX-RSOAuth2-SecurecodeacquisitionwithredirectURI">Secure code acquisition
with redirect URI</h4><p>The following <a shape="rect" class="external-link"
href="https://tools.ietf.org/html/draft-ietf-oauth-spop-15"
rel="nofollow">extension</a> is supported to help public clients with redirect
URIs to accept the code securely.</p><p>The public (mobile) client will include
a 'code_verifier' value when requesting the authorization code and it will be
saved by Authorization service, with the help
of the registered AuthorizationCodeDataProvider into an instance of
ServerAuthorizationCodeGrant. The client will next request a token providing
the 'code' and 'code_challenge' - the latter will be compared by
AuthorizationCodeGrantHandler with the original 'code_verifier'. By default,
the 'code_challenge' is expected to be equal to the original 'code_verifier',
but the grant handler can be registered with the custom
org.apache.cxf.rs.security.oauth2.grants.code.CodeVerifierTransformer - CXF
ships a DigestCodeVerifier which implements a transformation mentioned in the
extension.</p><p> </p><h2
id="JAX-RSOAuth2-AccessTokenService">AccessTokenService</h2><p>The role of <a
shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java"
rel="nofollow">AccessTokenService</a> is to exchange a token grant for a new
access token which will be used by t
he client to access the end user's resources. <br clear="none"> Here is an
example request log:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;">Address: http://localhost:8080/services/oauth/token
Http-Method: POST
@@ -235,7 +237,7 @@ Payload:
grant_type=authorization_code&code=5c993144b910bccd5977131f7d2629ab
&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fservices%2Freservations%2Freserve%2Fcomplete
</pre>
-</div></div><p>This request contains a client_id and client_secret
(Authorization header), the grant_type, the grant value (code) plus the
redirect URI the authorization grant was returned to which is needed for the
additional validation. Note that the alternative client authentication methods
are also possible, in this case the token service will expect a mapping between
the client credentials and the client_id representing the client registration
available.</p><p>After validating the request, the service will find a matching
<a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenGrantHandler.java">AccessTokenGrantHandler</a>
and request to create a <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/ServerAccessToken.java">Serv
erAccessToken</a> which is a server-side representation of the access
token.<br clear="none"> The grant handlers, such as <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrantHandler.java">AuthorizationCodeGrantHandler</a>
may delegate the creation of the actual access token to data providers, which
may create Bearer or MAC tokens with the help of utility classes shipped with
CXF or depend on other 3rd party token libraries.</p><p>The data providers do
not strictly required to persist the data such as access tokens, instead the
token key may act as an encrypted bag capturing all the relevant
information.</p><p>Now that the token has been created, it is mapped by the
service to a <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/securi
ty/oauth2/common/ClientAccessToken.java">client representation</a> and is
returned back as a JSON payload:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>This request contains a client_id and client_secret
(Authorization header), the grant_type, the grant value (code) plus the
redirect URI the authorization grant was returned to which is needed for the
additional validation. Note that the alternative client authentication methods
are also possible, in this case the token service will expect a mapping between
the client credentials and the client_id representing the client registration
available.</p><p>After validating the request, the service will find a matching
<a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenGrantHandler.java"
rel="nofollow">AccessTokenGrantHandler</a> and request to create a <a
shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/ServerAccessT
oken.java" rel="nofollow">ServerAccessToken</a> which is a server-side
representation of the access token.<br clear="none"> The grant handlers, such
as <a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrantHandler.java"
rel="nofollow">AuthorizationCodeGrantHandler</a> may delegate the creation of
the actual access token to data providers, which will create access tokens with
the help of utility classes shipped with CXF or depend on other 3rd party token
libraries.</p><p>The data providers do not strictly required to persist the
data such as access tokens, instead the token key may act as an encrypted bag
capturing all the relevant information.</p><p>Note that AccessTokenService may
not need to have <a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/a
pache/cxf/rs/security/oauth2/provider/AccessTokenGrantHandler.java"
rel="nofollow">AccessTokenGrantHandler</a> injected - if it finds out that the
data provider is AuthorizationCodeDataProvider then it will create <a
shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrantHandler.java"
rel="nofollow">AuthorizationCodeGrantHandler</a> itself. This will work well
unless <a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrantHandler.java"
rel="nofollow">AuthorizationCodeGrantHandler</a> itself needs to be customized
and thus directly injected into AccessTokenService.</p><p>Now that the token
has been created, it is mapped by the service to a <a shape="rect"
class="external-link" href="http://svn.apa
che.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/ClientAccessToken.java">client
access token representation</a> and is returned back as a JSON
payload:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;">Response-Code: 200
Content-Type: application/json
Headers: {
@@ -258,7 +260,7 @@ Headers:
Accept=[application/xml]
}
</pre>
-</div></div><p>Note that the access token key is passed as the Bearer scheme
value. Other token types such as MAC ones, etc, can be represented
differently.</p><h3 id="JAX-RSOAuth2-AccessTokenTypes">Access Token
Types</h3><p>As mentioned above, AccessTokenService can work with whatever
token is created by a given data provider. This section provides more
information on how CXF may help with supporting Bearer and MAC tokens.</p><h4
id="JAX-RSOAuth2-Bearer">Bearer</h4><p>The following code fragment shows how a
<a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/tokens/bearer/BearerAccessToken.java">BearerAccessToken</a>
utility class can be used to create Bearer tokens:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>Note that the access token key is passed as the Bearer scheme
value. Other token types such as MAC ones, etc, can be represented
differently.</p><h3 id="JAX-RSOAuth2-AccessTokenTypes">Access Token
Types</h3><p>As mentioned above, AccessTokenService can work with whatever
token is created by a given data provider. This section provides more
information on how CXF may help with supporting Bearer and other token
types.</p><h4 id="JAX-RSOAuth2-Bearer">Bearer</h4><p>The following code
fragment shows how a <a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/tokens/bearer/BearerAccessToken.java"
rel="nofollow">BearerAccessToken</a> utility class can be used to create
Bearer tokens:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">import
org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration;
import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
import org.apache.cxf.rs.security.oauth2.tokens.bearer.BearerAccessToken;
@@ -283,7 +285,7 @@ public class CustomOAuthDataProvider imp
// other methods are not shown
}
</pre>
-</div></div><p>CustomOAuthDataProvider will also be asked by
OAuthRequestFilter to validate the incoming Bearer tokens given that they
typically act as database key or key alias, if no Bearer token validator is
registered.</p><h4 id="JAX-RSOAuth2-HAWK">HAWK</h4><p>Starting from CXF
3.0.0-milestone2 the <a shape="rect" class="external-link"
href="https://github.com/hueniverse/hawk" rel="nofollow">Hawk</a> scheme is
supported instead of MAC (described in the next section). The way it is
supported is identical to the way MAC scheme is supported in earlier CXF
versions. The only differences are: 'Hawk' replaces 'Mac' in the Authorization
header, the Hawk token returned by the server will have 'secret' and
'algorithm' parameters instead of 'mac_key' and 'mac_algorithm'
parameters.</p><h4 id="JAX-RSOAuth2-MAC">MAC</h4><p>The text below applies to
CXF up to 3.0.0-milestone2. Starting from 3.0.0-milestone2 MAC scheme is not
supported, see above about the Hawk scheme. Support for the MAC sch
eme will be re-introduced once the OAuth2 working group finishes <a
shape="rect" class="external-link"
href="http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-05"
rel="nofollow">this effort</a>.</p><p>CXF 2.6.2 supports MAC tokens as
specified in the latest <a shape="rect" class="external-link"
href="http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-05"
rel="nofollow">MAC Access Authentication draft</a> created by Eran Hammer and
others. MAC tokens offer an option for clients to demonstrate they 'hold' the
token secret issued to them by AccessTokenService.<br clear="none"> It is
recommended that AccessTokenService endpoint issuing MAC tokens enforces a
two-way TLS for an extra protection of the MAC token data returned to
clients.</p><p>The following code fragment shows how a <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/branches/2.7.x//rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/tokens/mac/MacAccess
Token.java">MacAccessToken</a> utility class can be used to create MAC
tokens:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>CustomOAuthDataProvider will also be asked by
OAuthRequestFilter to validate the incoming Bearer tokens given that they
typically act as database key or key alias, if no Bearer token validator is
registered.</p><p>Note that all the default providers shipped with CXF create
and persist Bearer access tokens themselves.</p><h4
id="JAX-RSOAuth2-HAWK">HAWK</h4><p>Starting from CXF 3.0.0-milestone2 the <a
shape="rect" class="external-link" href="https://github.com/hueniverse/hawk"
rel="nofollow">Hawk</a> scheme is supported instead of MAC (described in the
next section). The way it is supported is identical to the way MAC scheme is
supported in earlier CXF versions. The only differences are: 'Hawk' replaces
'Mac' in the Authorization header, the Hawk token returned by the server will
have 'secret' and 'algorithm' parameters instead of 'mac_key' and
'mac_algorithm' parameters.</p><h4 id="JAX-RSOAuth2-MAC">MAC</h4><p>The text
below applies to CXF up to 3.0.0-milestone2. Start
ing from 3.0.0-milestone2 MAC scheme is not supported, see above about the
Hawk scheme. See also <a shape="rect" class="external-link"
href="https://tools.ietf.org/html/rfc7800" rel="nofollow">OAuth2 Proof Of
Possession Tokens</a> which will be supported in CXF in the future.</p><p>CXF
2.6.2 supports MAC tokens as specified in the latest <a shape="rect"
class="external-link"
href="http://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-05"
rel="nofollow">MAC Access Authentication draft</a> created by Eran Hammer and
others. MAC tokens offer an option for clients to demonstrate they 'hold' the
token secret issued to them by AccessTokenService.<br clear="none"> It is
recommended that AccessTokenService endpoint issuing MAC tokens enforces a
two-way TLS for an extra protection of the MAC token data returned to
clients.</p><p>The following code fragment shows how a <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/branches/2.7.x//rt/rs/security/oauth-parent
/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/tokens/mac/MacAccessToken.java">MacAccessToken</a>
utility class can be used to create MAC tokens:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">import
org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration;
import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
import org.apache.cxf.rs.security.oauth2.tokens.mac.HmacAlgorithm;
@@ -346,8 +348,8 @@ Authorization: MAC id="5b5c8e677413277c4
mac="W7bdMZbv9UWOTadASIQHagZyirA="
ts="12345678"
</pre>
-</div></div><p>where 'ts' attribute is used to pass a timestamp value.</p><h4
id="JAX-RSOAuth2-Encryptedtokens">Encrypted tokens</h4><p>Typically, the tokens
are persisted in the storage. The alternative approach is to completely encrypt
the token state and return the encrypted representation back to a client: the
processing time to do with the encryption and decryption might increase but the
server wins on avoiding the DB / storage lookups.    </p><p>CXF
3.0.0-milestone2 introduces the utility support for encrypting the state of
BearerAccessToken and RefreshToken.</p><p>The tokens can be encrypted and
decrypted with symmetric (secret) keys or certificates (public and private
keys) and the combination of certificates and secret keys.</p><p><a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/ModelEncryptionSupport.java">ModelEncryptionSupport</a>
c
an be used to encrypt the tokens using the custom serialization format. <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtils.java">EncryptionUtils</a>
can be used directly if the alternative serialization format is preferred.
 </p><p>Note that ServerAuthorizationGrant and Client can also be
encrypted.</p><h5 id="JAX-RSOAuth2-UsingSecretKeys">Using Secret
Keys</h5><p>The simplest strategy is to encrypt and decrypt the tokens with the
symmetric/secret keys. Every new token can be encrypted with a unique secret
key or all of them can be encrypted with a single secret key. The utilities
provide few methods for creating secret keys with the default and advanced
properties, in addition there are many examples around on how to create the
keys with the specific properties.</p><p>For example, see
org.apache.cxf.rs.security.oauth2.grants.code.DefaultEn
cryptingCodeDataProvider
and org.apache.cxf.rs.security.oauth2.provider.DefaultEncryptingOAuthDataProvider
which are shipped starting from CXF 3.0.2.</p><p>Here is a typical code
demonstrating how the encryption/decryption works:</p><p> </p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">SecretKey key = EncryptionUtils.getSecretKey();
+</div></div><p>where 'ts' attribute is used to pass a timestamp value.</p><h4
id="JAX-RSOAuth2-EncryptedandSignedTokens">Encrypted and Signed
Tokens</h4><p>Typically, the tokens are persisted in the storage. The
alternative approach is to completely encrypt the token state and return the
encrypted representation back to a client: the processing time to do with the
encryption and decryption might increase but the server wins on avoiding the DB
/ storage lookups.    </p><p>CXF 3.0.0-milestone2 introduces the
utility support for encrypting the state of BearerAccessToken and
RefreshToken.</p><p>The tokens can be encrypted and decrypted with symmetric
(secret) keys or certificates (public and private keys) and the combination of
certificates and secret keys.</p><p><a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/ModelEncryptionSupport.java"
r
el="nofollow">ModelEncryptionSupport</a> can be used to encrypt the tokens
using the custom serialization format.</p><p>Note that ServerAuthorizationGrant
and Client can also be encrypted.</p><p> </p><p>The simplest strategy is
to encrypt and decrypt the tokens with the symmetric/secret keys. Every new
token can be encrypted with a unique secret key or all of them can be encrypted
with a single secret key. The utilities provide few methods for creating secret
keys with the default and advanced properties, in addition there are many
examples around on how to create the keys with the specific
properties.</p><p>For example, see
org.apache.cxf.rs.security.oauth2.grants.code.DefaultEncryptingCodeDataProvider
and org.apache.cxf.rs.security.oauth2.provider.DefaultEncryptingOAuthDataProvider
which are shipped starting from CXF 3.0.2.</p><p>Here is a typical code
demonstrating how the encryption/decryption works:</p><p> </p><div
class="code panel pdl" style="border-width: 1px;
"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">SecretKey key = CryptoUtils.getSecretKey();
// create a new token, encrypt its state and return
@@ -362,7 +364,7 @@ return token;
// decrypt a token given a token key
ModelEncryptionSupport.decryptAccessToken(this, encryptedToken, key);</pre>
-</div></div><pre> </pre><h5 id="JAX-RSOAuth2-UsingCertificates">Using
Certificates</h5><p>Working with the certificates to encrypt the state is
similar to working with the symmetric keys. Please check the code examples in
<a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtilsTest.java">EncryptionsUtilsTest</a>.</p><p>One
needs to load a Certificate, use its public key to encrypt and the private key
to decrypt. using the certificate to encrypt the whole serialized token
representation might be marginally slower compared to using the symmetric keys,
however given that the sequence is about 300+ characters maximum the
performance can be reasonable.</p><h5
id="JAX-RSOAuth2-UsingCertificatesandSecretKeys">Using Certificates and Secret
Keys</h5><p>The other approach is to generate a secret key, use this key to
encrypt the token and then use the certi
ficate to encrypt the key. The encrypted token and the actual encrypted secret
key can be returned to the client as a token parameter, for example, as a 'key'
parameter. This 'key' parameter will need to be returned to the OAuth2 server,
via the HTTP header or the custom authorization scheme. The data providers
using this mechanism will need to implement AccessTokenValidator and decrypt
the encrypted key with the private certificate key, and decrypt the token with
the decrypted secret key. Please check the code example in <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/test/java/org/apache/cxf/rs/security/oauth2/utils/EncryptionUtilsTest.java">EncryptionsUtilsTest</a>.</p><h5
id="JAX-RSOAuth2-EncryptedJWTTokens">Encrypted JWT Tokens</h5><p>JWT Token can
be JWE-encrypted and the encrypted string passed to ServerAccessToken as access
token id parameter.</p><p>See <a shape="rect" href="jax-rs-jose.html">JAX-RS
Jose</a> wiki page for more information on how to sign and encrypt JSON Web
Tokens.</p><h4 id="JAX-RSOAuth2-Customtokens">Custom tokens</h4><p>If needed,
users can use their own custom token types, with the only restriction that the
custom token type implementations have to extend
org.apache.cxf.rs.security.oauth2.common.ServerAccessToken.</p><h4
id="JAX-RSOAuth2-SimpleTokensandAudience">Simple Tokens and
Audience</h4><p>Starting from CXF 2.7.7 an <a shape="rect"
class="external-link"
href="http://tools.ietf.org/html/draft-tschofenig-oauth-audience-00"
rel="nofollow">audience</a> parameter is supported during the client token
requests.</p><h3
id="JAX-RSOAuth2-OAuthJSONProvider">OAuthJSONProvider</h3><p>org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider
is a JAX-RS MessageBodyWriter which supports returning ClientAccessToken and
OAuthError representations to the client in a JSON format required by OAuth2
spec. It is also a JAX-RS MessageBodyReader that is used by client OA
uthClientUtils (see below) to read the responses from
AccessTokenService.</p><p>Register it as a provider with a JAXRS
AccessTokenService endpoint.</p><p>Alternatively, if you prefer, a custom
MessageBodyWriter implementation can be registered instead.</p><p> </p><h3
id="JAX-RSOAuth2-AccessTokenValidatorService">AccessTokenValidatorService</h3><p>The
<a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenValidator.java">AccessTokenValidatorService</a>
is a CXF specific OAuth2 service for accepting the remote access token
validation requests. OAuthRequestFilter will ask AccessTokenValidatorService to
return the information relevant to the current access token, before setting up
a security context. More on it below.</p><h3
id="JAX-RSOAuth2-TokenIntrospectionService">TokenIntrospectionService</h3><p>The
<a shape="rect" class="external-link" href="ht
tp://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenValidator.java">TokenIntrospectionService</a>
is a standard OAuth2 service for accepting the remote access token
introspection requests. See <a shape="rect" class="external-link"
href="https://tools.ietf.org/html/rfc7662" rel="nofollow">RFC 7662</a>.</p><h2
id="JAX-RSOAuth2-TokenRevocationService">TokenRevocationService</h2><p><a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/TokenRevocationService.java">TokenRevocationService</a>
is a simple OAuth2 service supporting the clients wishing to revoke the access
or refresh tokens they own themselves, please see <a shape="rect"
class="external-link"
href="http://tools.ietf.org/html/draft-ietf-oauth-revocation-09"
rel="nofollow">OAuth2 Token Revocation Draft</a> for more i
nformation.</p><p>TokenRevocationService and AccessTokenService share the same
code which enforces that the clients have been correctly
authenticated.</p><p>Note, OAuthDataProvider implementations processing a
revocation request should simply ignore the invalid tokens as recommended by
the specification which will let TokenRevocationService return HTTP 200 which
is done to minimize a possible attack surface (specifically for bad clients not
to see if their requests failed or succeeded) and throw the exceptions only if
the token revocation feature is not currently supported.</p><h2
id="JAX-RSOAuth2-SupportedGrants">Supported Grants</h2><p>The following
subsections briefly describe how the well-known grant types can be supported on
the server side. Please also check the "Client Side Support" section on how to
use the related <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/
oauth2/common/AccessTokenGrant.java">AccessTokenGrant</a> implementations to
request the access tokens.</p><h3
id="JAX-RSOAuth2-AuthorizationCode">Authorization Code</h3><p>As described
above, <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AuthorizationCodeGrantService.java">AuthorizationCodeGrantService</a>
service and <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeDataProvider.java">AuthorizationCodeDataProvider</a>
data provider can support a redirection-based Authorization Code
flow.</p><p>The code that the client receives in the end of the redirection
process will need to be exchanged for a new access token with
AccessTokenService. CXF-based clients can use a helper <a shape="rect"
class="external-lin
k"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrant.java">AuthorizationCodeGrant</a>
bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-Implicit">Implicit</h3><p>Implicit grant is supported the same
way Authorization Code grant is except that the response to the client running
within a web browser is formatted differently, using URI fragments.</p><p><a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ImplicitGrantService.java">ImplicitGrantService</a>
service and <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeDataProvider.java">AuthorizationCodeDataProvider</a>
data
provider can support a redirection-based Implicit flow.</p><p>Note the only
difference is the use of ImplicitGrantService instead of
AuthorizationCodeGrantService.</p><p>Also note that when an Implicit grant
client (running within a browser) replaces the code grant for a new access
token and tries to access the end user's resource, Cross Origin Resource
Sharing (CORS) support will most likely need to be enabled on the end user's
resource server.<br clear="none"> The simplest approach is to register a CXF <a
shape="rect" href="http://cxf.apache.org/docs/jax-rs-cors.html">CORS
filter</a>, right before OAuth2 filter (see on it below).</p><p>Starting from
CXF 2.7.5 it is possible to request ImplicitGrantService to return a registered
Client id to the browser-hosted client. This is recommended so that the client
can verify that the token is meant to be delivered to this client.</p><h3
id="JAX-RSOAuth2-ClientCredentials">Client Credentials</h3><p>Register <a
shape="rect" class="external-
link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/clientcred/ClientCredentialsGrantHandler.java">ClientCredentialsGrantHandler</a>
handler with AccessTokenService for this grant be supported.</p><p>CXF-based
clients can use a helper <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/clientcred/ClientCredentialsGrant.java">ClientCredentialsGrant</a>
bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-ResourceOwnerPasswordCredentials">Resource Owner Password
Credentials</h3><p>Register <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/owner/ResourceOwnerGrantHandler.java">ResourceOwnerGrantHandler</a>
handler with Ac
cessTokenService for this grant be supported.</p><p>CXF-based clients can use
a helper <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/owner/ResourceOwnerGrant.java">ResourceOwnerGrant</a>
bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-RefreshToken">Refresh Token</h3><p>The client can issue a
refresh token grant if the current access token it owns has expired or been
revoked and the refresh token was issued alongside with the access token which
is now invalid and get the new, 'refreshed' access token. This can allow the
client to avoid seeking a new authorization approval from the end
user.</p><p>Register <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/refresh/RefreshTokenGrantHandler.java">Refres
hTokenGrantHandler</a> handler with AccessTokenService for this grant be
supported. Note this grant handler is only useful for refreshing the existing
access token, so one or more of the other grant handlers (Authorization Code,
Implicit, etc) will also have to be registered with
AccessTokenService.</p><p>CXF-based clients can use a helper <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/refresh/RefreshTokenGrant.java">RefreshTokenGrant</a>
bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-Assertions">Assertions</h3><p>SAML2 Bearer and JWT assertions
can be used as token grants.</p><p>Please see <a shape="rect"
href="jaxrs-oauth2-assertions.html">JAXRS OAuth2 Assertions</a> section for
more information.</p><h3 id="JAX-RSOAuth2-CustomGrants">Custom Grants</h3><p>If
you need to customize the way the well-known grant requests are
handled then consider extending one of the grant handlers listed in the
previous sub-sections.</p><p>Alternatively create a custom <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenGrantHandler.java">AccessTokenGrantHandler</a>
and register it with AccessTokenService. Additionally, consider providing a
related <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/AccessTokenGrant.java">AccessTokenGrant</a>
implementation for making it easy for the client code to request a new access
token with this custom grant.</p><h2
id="JAX-RSOAuth2-RedirectionFlowFilters">Redirection Flow Filters</h2><p><a
shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2
/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AuthorizationCodeRequestFilter.java;h=646861c1ea3f9effad74bd234c0576f638009932;hb=HEAD">AuthorizationCodeRequestFilter</a>
implementations can be registered with AuthorizationCodeService in order to
pre-process code requests. For example, <a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JwtRequestCodeFilter.java;h=a318c2c405c813e9c07f1b22c4b2afbfccd6101e;hb=HEAD">JwtRequestCodeFilter</a>
can be used to process JWS-signed or JWE-encrypted code requests.</p><p><a
shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AuthorizationCodeResponseFilter.java;h=f363a461ed21be5a2b87584271bcce2933402ab6;hb=HEAD">AuthorizationCodeResponseFilter</a>
impleme
ntations can be registered with AuthorizationCodeService in order to
post-process code responses.</p><h2
id="JAX-RSOAuth2-AccessTokenResponseFilters">AccessTokenResponse
Filters</h2><p><a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenResponseFilter.java;h=f6058e6d2d2aa54543514cbfe2d0d9951a30db68;hb=HEAD">AccessTokenResponseFilter</a>
implementations can be registered with AccessTokenService in order to
post-process access token responses. For example,  OIDC id_token can be
added to a response with a <a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoCodeResponseFilter.java;h=42bf9ff41004a32903e6839495d9edde5963c2e3;hb=HEAD">filter</a>.
Filters can also calculate an access token response signa
ture, etc.</p><h2 id="JAX-RSOAuth2-PreAuthorizedaccesstokens">PreAuthorized
access tokens</h2><p>When working with the flows which require the end
users/resource owners explicitly authorizing clients (for example, as in the
case of redirection-based flows), using pre-authorized access tokens is one
option to minimize the need for the end-user intervention. <br clear="none">
OAuthDataProvider is always checked first if the pre-authorized access token
for a given Client exists and if yes then it will be returned immediately,
without starting the authorization process involving the end user (as required
by some flows).</p><p>Consider providing a user interface which will let the
end users/resource owners to pre-authorize specific clients early. Note, a CXF
service for supporting the users pre-authorizing the clients or revoking the
tokens for some of the clients may be introduced in the future.</p><p>Also note
that using a refresh token grant may further help with minimizing the end us
er involvement, in cases when the current access token has expired.</p><h2
id="JAX-RSOAuth2-Pre-registeredscopes">Pre-registered scopes</h2><p>Clients can
register custom scopes they will be expected to use and then avoid specifying
the scopes when requesting the code grants or access tokens.<br clear="none">
Alternatively it makes it easier to support so called wild-card scopes. For
example, a client pre-registers a scope "update" and actually uses an
"update-7" scope: Redirection-based services and access token grants can be
configured to do a partial scope match, in this case, validate that "update-7"
starts from "update"</p><h2 id="JAX-RSOAuth2-WritingOAuthDataProvider">Writing
OAuthDataProvider</h2><p>Using CXF OAuth service implementations will help a
lot with setting up an OAuth server. As you can see from the above sections,
these services rely on a custom <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2
/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java">OAuthDataProvider</a>
implementation.</p><p>The main task of OAuthDataProvider is to persist and
generate access tokens. Additionally, as noted above,
AuthorizationCodeDataProvider needs to persist and remove the code grant
registrations. The way it's done is really application-specific. Consider
starting with a basic memory based implementation and then move on to keeping
the data in some DB.</p><p>Note that OAuthDataProvider supports retrieving <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/Client.java">Client</a>
instances but it has no methods for creating or removing Clients. The reason
for it is that the process of registering third-party clients is very specific
to a particular OAuth2 application, so CXF does not offer a registration
support service and hence OAuthData
Provider has no Client create/update methods. You will likely need to do
something like this:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
+</div></div><pre> </pre><h5
id="JAX-RSOAuth2-EncryptedandSignedJWTTokens">Encrypted and Signed JWT
Tokens</h5><p>JWT Token can be JWE-encrypted and the encrypted string passed to
ServerAccessToken as access token id parameter.</p><p>See <a shape="rect"
href="http://cxf.apache.org/docs/jax-rs-jose.html">JAX-RS JOSE</a> wiki page
for more information on how to sign and encrypt JSON Web Tokens.</p><p><a
shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/tokens/jwt/JwtAccessTokenUtils.java"
rel="nofollow">JwtAccessTokenUtils </a>provides utility method for encrypting
and decrypting an access token represented as JWT.</p><p>Note more support for
JWT access tokens is on the way.</p><h4 id="JAX-RSOAuth2-Customtokens">Custom
tokens</h4><p>If needed, users can use their own custom token types, with the
only restriction that the custom token type implementations have to exte
nd org.apache.cxf.rs.security.oauth2.common.ServerAccessToken.</p><h4
id="JAX-RSOAuth2-SimpleTokensandAudience">Simple Tokens and
Audience</h4><p>Starting from CXF 2.7.7 an <a shape="rect"
class="external-link"
href="http://tools.ietf.org/html/draft-tschofenig-oauth-audience-00"
rel="nofollow">audience</a> parameter is supported during the client token
requests.</p><h3
id="JAX-RSOAuth2-OAuthJSONProvider">OAuthJSONProvider</h3><p>org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider
is a JAX-RS MessageBodyWriter which supports returning ClientAccessToken and
OAuthError representations to the client in a JSON format required by OAuth2
spec. It is also a JAX-RS MessageBodyReader that is used by client
OAuthClientUtils (see below) to read the responses from
AccessTokenService.</p><p>Register it as a provider with a JAXRS
AccessTokenService endpoint.</p><p>Alternatively, if you prefer, a custom
MessageBodyWriter implementation can be registered instead.</p><h2
id="JAX-RSOAuth2-Acc
essTokenValidationService">Access Token Validation Service</h2><h3
id="JAX-RSOAuth2-AccessTokenValidatorService">AccessTokenValidatorService</h3><p>The
<a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenValidatorService.java"
rel="nofollow">AccessTokenValidatorService</a> is a CXF specific OAuth2
service for accepting the remote access token validation requests.
OAuthRequestFilter needs to be injected with <a shape="rect"
class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/AccessTokenValidatorClient.java"
rel="nofollow">AccessTokenValidatorClient</a> which will ask
AccessTokenValidatorService to return the information relevant to the current
access token, before setting up a security context.</p><h3
id="JAX-RSOAuth2-TokenIntrospectionServic
e">TokenIntrospectionService</h3><p>The <a shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/TokenIntrospectionService.java"
rel="nofollow">TokenIntrospectionService</a> is a standard OAuth2 service for
accepting the remote access token introspection requests. See <a shape="rect"
class="external-link" href="https://tools.ietf.org/html/rfc7662"
rel="nofollow">RFC 7662</a>. OAuthRequestFilter needs to be injected with <a
shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/AccessTokenIntrospectionClient.java"
rel="nofollow">AccessTokenIntrospectionClient.</a></p><h2
id="JAX-RSOAuth2-TokenRevocationService">TokenRevocationService</h2><p><a
shape="rect" class="external-link"
href="https://github.com/apache/cxf/blob/master/rt/rs/security/oauth-pa
rent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/TokenRevocationService.java"
rel="nofollow">TokenRevocationService</a> is a simple OAuth2 service
supporting the clients wishing to revoke the access or refresh tokens they own
themselves, please see <a shape="rect" class="external-link"
href="http://tools.ietf.org/html/draft-ietf-oauth-revocation-09"
rel="nofollow">OAuth2 Token Revocation Draft</a> for more
information.</p><p>TokenRevocationService and AccessTokenService share the same
code which enforces that the clients have been correctly
authenticated.</p><p>Note, OAuthDataProvider implementations processing a
revocation request should simply ignore the invalid tokens as recommended by
the specification which will let TokenRevocationService return HTTP 200 which
is done to minimize a possible attack surface (specifically for bad clients not
to see if their requests failed or succeeded) and throw the exceptions only if
the token revocation feature is not curren
tly supported.</p><h2 id="JAX-RSOAuth2-SupportedGrants">Supported
Grants</h2><p>The following subsections briefly describe how the well-known
grant types can be supported on the server side. Please also check the "Client
Side Support" section on how to use the related <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/AccessTokenGrant.java">AccessTokenGrant</a>
implementations to request the access tokens.</p><h3
id="JAX-RSOAuth2-AuthorizationCode">Authorization Code</h3><p>As described
above, <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AuthorizationCodeGrantService.java">AuthorizationCodeGrantService</a>
service and <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent
/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeDataProvider.java">AuthorizationCodeDataProvider</a>
data provider can support a redirection-based Authorization Code
flow.</p><p>The code that the client receives in the end of the redirection
process will need to be exchanged for a new access token with
AccessTokenService. CXF-based clients can use a helper <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeGrant.java">AuthorizationCodeGrant</a>
bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-Implicit">Implicit</h3><p>Implicit grant is supported the same
way Authorization Code grant is except that the response to the client running
within a web browser is formatted differently, using URI fragments.</p><p><a
shape="rect" class="external-link" href="http://svn.apache.org/
repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/ImplicitGrantService.java">ImplicitGrantService</a>
service and <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AuthorizationCodeDataProvider.java">AuthorizationCodeDataProvider</a>
data provider can support a redirection-based Implicit flow.</p><p>Note the
only difference is the use of ImplicitGrantService instead of
AuthorizationCodeGrantService.</p><p>Also note that when an Implicit grant
client (running within a browser) replaces the code grant for a new access
token and tries to access the end user's resource, Cross Origin Resource
Sharing (CORS) support will most likely need to be enabled on the end user's
resource server.<br clear="none"> The simplest approach is to register a CXF <a
shape="rect" href="http://cxf.apache.org/docs/jax-rs
-cors.html">CORS filter</a>, right before OAuth2 filter (see on it
below).</p><p>Starting from CXF 2.7.5 it is possible to request
ImplicitGrantService to return a registered Client id to the browser-hosted
client. This is recommended so that the client can verify that the token is
meant to be delivered to this client.</p><h3
id="JAX-RSOAuth2-ClientCredentials">Client Credentials</h3><p>Register <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/clientcred/ClientCredentialsGrantHandler.java">ClientCredentialsGrantHandler</a>
handler with AccessTokenService for this grant be supported.</p><p>CXF-based
clients can use a helper <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/clientcred/ClientCredentialsGrant.java">ClientCredentialsGrant<
/a> bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-ResourceOwnerPasswordCredentials">Resource Owner Password
Credentials</h3><p>Register <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/owner/ResourceOwnerGrantHandler.java">ResourceOwnerGrantHandler</a>
handler with AccessTokenService for this grant be supported.</p><p>CXF-based
clients can use a helper <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/owner/ResourceOwnerGrant.java">ResourceOwnerGrant</a>
bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-RefreshToken">Refresh Token</h3><p>The client can issue a
refresh token grant if the current access token it owns has expired or been
revoked and the refresh token was
issued alongside with the access token which is now invalid and get the new,
'refreshed' access token. This can allow the client to avoid seeking a new
authorization approval from the end user.</p><p>Register <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/refresh/RefreshTokenGrantHandler.java">RefreshTokenGrantHandler</a>
handler with AccessTokenService for this grant be supported. Note this grant
handler is only useful for refreshing the existing access token, so one or more
of the other grant handlers (Authorization Code, Implicit, etc) will also have
to be registered with AccessTokenService.</p><p>CXF-based clients can use a
helper <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/refresh/RefreshTokenGrant.java">RefreshTokenGran
t</a> bean to request a new access token with OAuthClientUtils.</p><h3
id="JAX-RSOAuth2-Assertions">Assertions</h3><p>SAML2 Bearer and JWT assertions
can be used as token grants.</p><p>Please see <a shape="rect"
href="jaxrs-oauth2-assertions.html">JAXRS OAuth2 Assertions</a> section for
more information.</p><h3 id="JAX-RSOAuth2-CustomGrants">Custom Grants</h3><p>If
you need to customize the way the well-known grant requests are handled then
consider extending one of the grant handlers listed in the previous
sub-sections.</p><p>Alternatively create a custom <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenGrantHandler.java">AccessTokenGrantHandler</a>
and register it with AccessTokenService. Additionally, consider providing a
related <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/
oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/AccessTokenGrant.java">AccessTokenGrant</a>
implementation for making it easy for the client code to request a new access
token with this custom grant.</p><h2
id="JAX-RSOAuth2-RedirectionFlowFilters">Redirection Flow Filters</h2><p><a
shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AuthorizationCodeRequestFilter.java;h=646861c1ea3f9effad74bd234c0576f638009932;hb=HEAD">AuthorizationCodeRequestFilter</a>
implementations can be registered with AuthorizationCodeService in order to
pre-process code requests. For example, <a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/JwtRequestCodeFilter.java;h=a318c2c405c813e9c07f1b22c4b2afbfccd6101e;hb
=HEAD">JwtRequestCodeFilter</a> can be used to process JWS-signed or
JWE-encrypted code requests.</p><p><a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AuthorizationCodeResponseFilter.java;h=f363a461ed21be5a2b87584271bcce2933402ab6;hb=HEAD">AuthorizationCodeResponseFilter</a>
implementations can be registered with AuthorizationCodeService in order to
post-process code responses.</p><h2
id="JAX-RSOAuth2-AccessTokenResponseFilters">AccessTokenResponse
Filters</h2><p><a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenResponseFilter.java;h=f6058e6d2d2aa54543514cbfe2d0d9951a30db68;hb=HEAD">AccessTokenResponseFilter</a>
implementations can be registered with AccessTokenService in order to pos
t-process access token responses. For example,  OIDC id_token can be
added to a response with a <a shape="rect" class="external-link"
href="https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoCodeResponseFilter.java;h=42bf9ff41004a32903e6839495d9edde5963c2e3;hb=HEAD">filter</a>.
Filters can also calculate an access token response signature, etc.</p><h2
id="JAX-RSOAuth2-PreAuthorizedaccesstokens">PreAuthorized access
tokens</h2><p>When working with the flows which require the end users/resource
owners explicitly authorizing clients (for example, as in the case of
redirection-based flows), using pre-authorized access tokens is one option to
minimize the need for the end-user intervention. <br clear="none">
OAuthDataProvider is always checked first if the pre-authorized access token
for a given Client exists and if yes then it will be returned immediately,
without starting the authorization pr
ocess involving the end user (as required by some flows).</p><p>Consider
providing a user interface which will let the end users/resource owners to
pre-authorize specific clients early. Note, a CXF service for supporting the
users pre-authorizing the clients or revoking the tokens for some of the
clients may be introduced in the future.</p><p>Also note that using a refresh
token grant may further help with minimizing the end user involvement, in cases
when the current access token has expired.</p><h2
id="JAX-RSOAuth2-Pre-registeredscopes">Pre-registered scopes</h2><p>Clients can
register custom scopes they will be expected to use and then avoid specifying
the scopes when requesting the code grants or access tokens.<br clear="none">
Alternatively it makes it easier to support so called wild-card scopes. For
example, a client pre-registers a scope "update" and actually uses an
"update-7" scope: Redirection-based services and access token grants can be
configured to do a partial scope
match, in this case, validate that "update-7" starts from "update"</p><h2
id="JAX-RSOAuth2-WritingOAuthDataProvider">Writing
OAuthDataProvider</h2><p>Using CXF OAuth service implementations will help a
lot with setting up an OAuth server. As you can see from the above sections,
these services rely on a custom <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/OAuthDataProvider.java">OAuthDataProvider</a>
implementation.</p><p>The main task of OAuthDataProvider is to persist and
generate access tokens. Additionally, as noted above,
AuthorizationCodeDataProvider needs to persist and remove the code grant
registrations. The way it's done is really application-specific. Consider
starting with a basic memory based implementation and then move on to keeping
the data in some DB.</p><p>Note that OAuthDataProvider supports retrieving <a
shape="rect" class="external-l
ink"
href="http://svn.apache.org/repos/asf/cxf/trunk/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/common/Client.java">Client</a>
instances but it has no methods for creating or removing Clients. The reason
for it is that the process of registering third-party clients is very specific
to a particular OAuth2 application, so CXF does not offer a registration
support service and hence OAuthDataProvider has no Client create/update
methods. You will likely need to do something like this:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public class CustomOAuthProvider implements
OAuthDataProvider {
public Client registerClient(String applicationName, String applicationURI,
...) {}
public void removeClient(String cliendId) {}