Class NonceManager
java.lang.Object
org.glassfish.jersey.server.oauth1.NonceManager
Tracks the nonces for a given consumer key and/or token. Automagically
ensures timestamp is monotonically increasing and tracks all nonces
for a given timestamp.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Counts number of verification requests performed to schedule garbage collection.private final int
Verifications to perform on average before performing garbage collection.private long
private final long
The maximum valid age of a nonce timestamp, in milliseconds.private final long
private final TimeUnit
Maps timestamps to key-nonce pairs. -
Constructor Summary
ConstructorsConstructorDescriptionNonceManager
(long maxAge, int gcPeriod, TimeUnit timestampUnit, long maximumCacheSize) Create a new nonce manager configured with maximum age, old nonce cleaning period and a time unit of timestamps. -
Method Summary
Modifier and TypeMethodDescription(package private) long
Returns number of currently tracked timestamp-key-nonce tuples.(package private) void
gc
(long now) Deletes all nonces older than maxAge.private static long
boolean
Evaluates the timestamp/nonce combination for validity, storing and/or clearing nonces as required.(package private) boolean
Evaluates the timestamp/nonce combination for validity, storing and/or clearing nonces as required.
-
Field Details
-
maxAge
private final long maxAgeThe maximum valid age of a nonce timestamp, in milliseconds. -
gcPeriod
private final int gcPeriodVerifications to perform on average before performing garbage collection. -
gcCounter
private int gcCounterCounts number of verification requests performed to schedule garbage collection. -
timestampUnit
-
maximumMapSize
private final long maximumMapSize -
tsToKeyNoncePairs
Maps timestamps to key-nonce pairs. -
mapSize
private volatile long mapSize
-
-
Constructor Details
-
NonceManager
Create a new nonce manager configured with maximum age, old nonce cleaning period and a time unit of timestamps.- Parameters:
maxAge
- the maximum valid age of a nonce timestamp, in milliseconds.gcPeriod
- number of verifications to be performed on average before performing garbage collection of old nonces.timestampUnit
- unit in which timestamps are passed toverify(String, String, String)
method.maximumCacheSize
- maximum size of the cache that keeps nonces. If the cache exceeds the methodverify(String, String, String)
will returnfalse
.
-
-
Method Details
-
verify
Evaluates the timestamp/nonce combination for validity, storing and/or clearing nonces as required.The method is package private in order to be used in unit tests only.
- Parameters:
key
- the oauth_consumer_key value for a given consumer requesttimestamp
- the oauth_timestamp value for a given consumer request (in milliseconds).nonce
- the oauth_nonce value for a given consumer request.now
- current time in milliseconds- Returns:
- true if the timestamp/nonce are valid.
-
verify
Evaluates the timestamp/nonce combination for validity, storing and/or clearing nonces as required.- Parameters:
key
- the oauth_consumer_key value for a given consumer requesttimestamp
- the oauth_timestamp value for a given consumer request (in milliseconds).nonce
- the oauth_nonce value for a given consumer request.- Returns:
- true if the timestamp/nonce are valid.
-
gc
void gc(long now) Deletes all nonces older than maxAge. This method is package private (instead of private) for testability purposes.- Parameters:
now
- milliseconds since epoch representing "now"
-
checkAndGetSize
long checkAndGetSize()Returns number of currently tracked timestamp-key-nonce tuples. The method should be used by tests only.- Returns:
- number of currently tracked timestamp-key-nonce tuples.
-
longValue
-