Class DocumentServerTokens
java.lang.Object
org.exoplatform.onlyoffice.DocumentServerTokens
Signs the tokens the addon sends to ONLYOFFICE Docs and validates the tokens
the Document Server sends back, with the shared secret. Every token carries
its purpose in the root
operation claim
(DocumentServerOperation): ONLYOFFICE Docs 10.0 refuses a token sent
to a service of another purpose, and this class refuses a token received on
an endpoint of another purpose. Without a usable secret nothing is signed and
every received token is refused.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe minimum length of the secret, in bytes: HMAC-SHA256 needs 256 bits. -
Constructor Summary
ConstructorsConstructorDescriptionDocumentServerTokens(String secret) Reports a missing or too short secret as an ERROR, once. -
Method Summary
Modifier and TypeMethodDescriptionsign(Map<String, ?> claims, DocumentServerOperation operation) Signs a token for a request to the Document Server.sign(Map<String, ?> claims, DocumentServerOperation operation, Date expiresAt) Signs a token that expires, for a URL the addon hands out and validates itself.booleanvalidate(String token, String key, DocumentServerOperation expected) Validates a token the Document Server sent to an addon endpoint.booleanvalidateCallback(String token, String key, String body) Validates a save or status callback: its token, and the callback the addon acts on.
-
Field Details
-
MIN_SECRET_BYTES
public static final int MIN_SECRET_BYTESThe minimum length of the secret, in bytes: HMAC-SHA256 needs 256 bits.- See Also:
-
-
Constructor Details
-
DocumentServerTokens
Reports a missing or too short secret as an ERROR, once.- Parameters:
secret- the secret shared with the Document Server, may be null
-
-
Method Details
-
getSecretProblem
- Returns:
- why the secret cannot be used, or null when it can
-
sign
Signs a token for a request to the Document Server.- Parameters:
claims- the claims of the request, left unchangedoperation- the service the token is for- Returns:
- the signed token
- Throws:
IllegalStateException- when the secret is missing or too short
-
sign
Signs a token that expires, for a URL the addon hands out and validates itself.- Parameters:
claims- the claims of the request, left unchangedoperation- the service the token is forexpiresAt- when the token expires, none when null- Returns:
- the signed token
- Throws:
IllegalStateException- when the secret is missing or too short
-
validate
Validates a token the Document Server sent to an addon endpoint.- Parameters:
token- the token, may be nullkey- the document key the endpoint was called for, may be nullexpected- the purpose of the endpoint,DocumentServerOperation.DOWNLOADfor a file fetch. This checks the token only: a callback, whose body the addon acts on, is validated byvalidateCallback(String, String, String)- Returns:
- true when the token is signed with the secret, carries an expiry
not yet reached and the expected purpose, and is for that key: for a callback its
payload.keyequals the key; for a download itspayload.keyequals the key or itspayload.urlends with it
-
validateCallback
Validates a save or status callback: its token, and the callback the addon acts on. ONLYOFFICE Docs signs the whole callback in the token'spayload, so the body must be that payload, its owntokenfield aside. Both sides are read into the same form, where anullvalue and an absent one are alike, as they are to the addon.- Parameters:
token- the token of the Authorization header, may be nullkey- the document key the endpoint was called for, may be nullbody- the callback body, may be null- Returns:
- true when the token is a valid callback token whose
payload.keyequals the key and whose payload equals the body
-