Class GenerateAccessTokenRequestControl
- java.lang.Object
-
- com.unboundid.ldap.sdk.Control
-
- com.unboundid.ldap.sdk.unboundidds.controls.GenerateAccessTokenRequestControl
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class GenerateAccessTokenRequestControl extends Control
This class provides a request control that can be included in a bind request to indicate that if the bind succeeds, the server should generate an access token that can be used in theOAUTHBEARERBindRequest
to authenticate as the user for subsequent authentication attempts. This can be useful for cases in which the initial authentication attempt is made with credentials that cannot be replayed, like a those involving a one-time password (e.g.,UnboundIDTOTPBindRequest
,UnboundIDDeliveredOTPBindRequest
, orUnboundIDYubiKeyOTPBindRequest
).
NOTE: This class, and other classes within the
com.unboundid.ldap.sdk.unboundidds
package structure, are only supported for use against Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 server products. These classes provide support for proprietary functionality or for external specifications that are not considered stable or mature enough to be guaranteed to work in an interoperable way with other types of LDAP servers.
The OID for this control is 1.3.6.1.4.1.30221.2.5.67, the criticality may be eithertrue
orfalse
, and it does not have a value.
Example
The following example demonstrates the process of requesting an access token when performing one bind, and then using that access token to authenticate with subsequent bind operations:// Authenticate with the UNBOUNDID-TOTP SASL mechanism, which uses a // time-based one-time password. Since it's a one-time password, it // can't be reused. If we want to re-authenticate as the same user, // we can request that the server return an access token that we can // use instead. GenerateAccessTokenRequestControl requestControl = new GenerateAccessTokenRequestControl(); SingleUseTOTPBindRequest totpBindRequest = new SingleUseTOTPBindRequest(authenticationID, authorizationID, totpPassword, staticPassword, requestControl); BindResult totpBindResult = connection.bind(totpBindRequest); // Get the access token from the bind result. String accessToken = null; GenerateAccessTokenResponseControl responseControl = GenerateAccessTokenResponseControl.get(totpBindResult); if (responseControl != null) { accessToken = responseControl.getAccessToken(); } // The next time you need to authenticate, you can use the access // token with an OAUTHBEARER SASL mechanism using the access token. if (accessToken != null) { OAUTHBEARERBindRequest tokenBindRequest = new OAUTHBEARERBindRequest(accessToken); BindResult tokenBindResult = connection.bind(tokenBindRequest); }
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
GENERATE_ACCESS_TOKEN_REQUEST_OID
The OID (1.3.6.1.4.1.30221.2.5.67) for the generate access token request control.
-
Constructor Summary
Constructors Constructor Description GenerateAccessTokenRequestControl()
Creates a new generate access token request control.GenerateAccessTokenRequestControl(boolean isCritical)
Creates a new generate access token request control with the specified criticality.GenerateAccessTokenRequestControl(Control control)
Creates a new generate access token request control which is decoded from the provided generic control.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GenerateAccessTokenRequestControl
decodeJSONControl(JSONObject controlObject, boolean strict)
Attempts to decode the provided object as a JSON representation of a generate access token request control.java.lang.String
getControlName()
Retrieves the user-friendly name for this control, if available.JSONObject
toJSONControl()
Retrieves a representation of this generate access token request control as a JSON object.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP control to the provided buffer.-
Methods inherited from class com.unboundid.ldap.sdk.Control
decode, decode, decodeControls, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
-
-
-
-
Field Detail
-
GENERATE_ACCESS_TOKEN_REQUEST_OID
@NotNull public static final java.lang.String GENERATE_ACCESS_TOKEN_REQUEST_OID
The OID (1.3.6.1.4.1.30221.2.5.67) for the generate access token request control.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GenerateAccessTokenRequestControl
public GenerateAccessTokenRequestControl()
Creates a new generate access token request control. It will be marked critical.
-
GenerateAccessTokenRequestControl
public GenerateAccessTokenRequestControl(boolean isCritical)
Creates a new generate access token request control with the specified criticality.- Parameters:
isCritical
- Indicates whether this control should be marked critical.
-
GenerateAccessTokenRequestControl
public GenerateAccessTokenRequestControl(@NotNull Control control) throws LDAPException
Creates a new generate access token request control which is decoded from the provided generic control.- Parameters:
control
- The generic control to be decoded as a generate access token request control.- Throws:
LDAPException
- If the provided control cannot be decoded as a generate access token request control.
-
-
Method Detail
-
getControlName
@NotNull public java.lang.String getControlName()
Retrieves the user-friendly name for this control, if available. If no user-friendly name has been defined, then the OID will be returned.- Overrides:
getControlName
in classControl
- Returns:
- The user-friendly name for this control, or the OID if no user-friendly name is available.
-
toJSONControl
@NotNull public JSONObject toJSONControl()
Retrieves a representation of this generate access token request control as a JSON object. The JSON object uses the following fields (note that since this control does not have a value, neither thevalue-base64
norvalue-json
fields may be present):-
oid
-- A mandatory string field whose value is the object identifier for this control. For the generate access token request control, the OID is "1.3.6.1.4.1.30221.2.5.67". -
control-name
-- An optional string field whose value is a human-readable name for this control. This field is only intended for descriptive purposes, and when decoding a control, theoid
field should be used to identify the type of control. -
criticality
-- A mandatory Boolean field used to indicate whether this control is considered critical.
- Overrides:
toJSONControl
in classControl
- Returns:
- A JSON object that contains a representation of this control.
-
-
decodeJSONControl
@NotNull public static GenerateAccessTokenRequestControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException
Attempts to decode the provided object as a JSON representation of a generate access token request control.- Parameters:
controlObject
- The JSON object to be decoded. It must not benull
.strict
- Indicates whether to use strict mode when decoding the provided JSON object. If this istrue
, then this method will throw an exception if the provided JSON object contains any unrecognized fields. If this isfalse
, then unrecognized fields will be ignored.- Returns:
- The generate access token request control that was decoded from the provided JSON object.
- Throws:
LDAPException
- If the provided JSON object cannot be parsed as a valid generate access token request control.
-
-