All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.belladati.sdk.impl.TokenHolder Maven / Gradle / Ivy

Go to download

The BellaDati SDK allows accessing a BellaDati server from 3rd-party applications using Java. This project contains the implementation for Android.

There is a newer version: 0.9.7
Show newest version
package com.belladati.sdk.impl;

import java.io.Serializable;
import java.util.Random;

import oauth.signpost.OAuthConsumer;

import com.belladati.sdk.impl.oauth.BellaDatiOAuthConsumer;

class TokenHolder implements Serializable {

	/** The serialVersionUID */
	private static final long serialVersionUID = 8122702080702303615L;

	private static final Random RANDOM = new Random();

	private final String consumerKey;
	private final String consumerSecret;

	private String token;
	private String tokenSecret;

	TokenHolder(String consumerKey, String consumerSecret) {
		this.consumerKey = consumerKey;
		this.consumerSecret = consumerSecret;
	}

	public OAuthConsumer createConsumer() {
		OAuthConsumer consumer = new BellaDatiOAuthConsumer(consumerKey, consumerSecret) {
			private static final long serialVersionUID = 2077439267247908434L;

			@Override
			protected String generateNonce() {
				// thread-safe nonce generation
				// http://code.google.com/p/oauth-signpost/issues/detail?id=41
				return Long.toString(RANDOM.nextLong());
			}
		};
		consumer.setTokenWithSecret(token, tokenSecret);
		return consumer;
	}

	public String getConsumerKey() {
		return consumerKey;
	}

	public boolean hasToken() {
		return token != null;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token, String tokenSecret) {
		this.token = token;
		this.tokenSecret = tokenSecret;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy