/** * Returns true if the nonce was generated usig <code>generateNonce</code> and if this is the * first check for that nonce. * * @param nonce the nonce to be checked * @return true if the nonce if the nonce was generated and this is the first check for that nonce */ public boolean isValidNonce(String nonce) { Long time = nonceCache.remove(nonce); if (time == null) { return false; } return System.currentTimeMillis() - time < JiveConstants.MINUTE; }
/** * Generates a new nonce. The <code>isValidNonce</code> method will return true when using nonces * generated by this method. * * @return a unique nonce */ public String generateNonce() { String nonce = String.valueOf(nonceGenerator.nextLong()); nonceCache.put(nonce, System.currentTimeMillis()); return nonce; }