Example usage for org.springframework.security.oauth.provider.token OAuthProviderTokenImpl setTimestamp

List of usage examples for org.springframework.security.oauth.provider.token OAuthProviderTokenImpl setTimestamp

Introduction

In this page you can find the example usage for org.springframework.security.oauth.provider.token OAuthProviderTokenImpl setTimestamp.

Prototype

public void setTimestamp(long timestamp) 

Source Link

Document

Timestamp associated with this token.

Usage

From source file:org.springframework.security.oauth.provider.token.RandomValueProviderTokenServices.java

public OAuthProviderToken createUnauthorizedRequestToken(String consumerKey, String callbackUrl)
        throws AuthenticationException {
    String tokenValue = UUID.randomUUID().toString();
    byte[] secretBytes = new byte[getTokenSecretLengthBytes()];
    getRandom().nextBytes(secretBytes);//from   w w  w . j a va  2s .c o m
    String secret = new String(Base64.encodeBase64(secretBytes));
    OAuthProviderTokenImpl token = new OAuthProviderTokenImpl();
    token.setAccessToken(false);
    token.setConsumerKey(consumerKey);
    token.setCallbackUrl(callbackUrl);
    token.setUserAuthentication(null);
    token.setSecret(secret);
    token.setValue(tokenValue);
    token.setTimestamp(System.currentTimeMillis());
    onTokenCreated(token);
    storeToken(tokenValue, token);
    return token;
}

From source file:org.springframework.security.oauth.provider.token.RandomValueProviderTokenServices.java

public void authorizeRequestToken(String requestToken, String verifier, Authentication authentication)
        throws AuthenticationException {
    OAuthProviderTokenImpl tokenImpl = readToken(requestToken);

    if (tokenImpl == null) {
        throw new InvalidOAuthTokenException("Invalid token: " + requestToken);
    } else if (isExpired(tokenImpl)) {
        removeToken(requestToken);/*from  w  ww  .j  av  a2  s . c  o  m*/
        onTokenRemoved(tokenImpl);
        throw new ExpiredOAuthTokenException("Expired token.");
    } else if (tokenImpl.isAccessToken()) {
        throw new InvalidOAuthTokenException("Request to authorize an access token.");
    }

    tokenImpl.setUserAuthentication(authentication);
    tokenImpl.setTimestamp(System.currentTimeMillis());//reset the expiration.
    tokenImpl.setVerifier(verifier);
    storeToken(requestToken, tokenImpl);
}

From source file:org.springframework.security.oauth.provider.token.RandomValueProviderTokenServices.java

public OAuthAccessProviderToken createAccessToken(String requestToken) throws AuthenticationException {
    OAuthProviderTokenImpl tokenImpl = readToken(requestToken);

    if (tokenImpl == null) {
        throw new InvalidOAuthTokenException("Invalid token: " + requestToken);
    } else if (isExpired(tokenImpl)) {
        removeToken(requestToken);//from w  ww.  j a  v a  2  s.  com
        onTokenRemoved(tokenImpl);
        throw new ExpiredOAuthTokenException("Expired token.");
    } else if (tokenImpl.isAccessToken()) {
        throw new InvalidOAuthTokenException("Not a request token.");
    } else if (tokenImpl.getUserAuthentication() == null) {
        throw new InvalidOAuthTokenException("Request token has not been authorized.");
    }

    OAuthProviderTokenImpl requestTokenImpl = removeToken(requestToken);
    if (requestTokenImpl != null) {
        onTokenRemoved(requestTokenImpl);
    }

    String tokenValue = UUID.randomUUID().toString();
    byte[] secretBytes = new byte[getTokenSecretLengthBytes()];
    getRandom().nextBytes(secretBytes);
    String secret = new String(Base64.encodeBase64(secretBytes));
    OAuthProviderTokenImpl token = new OAuthProviderTokenImpl();
    token.setAccessToken(true);
    token.setConsumerKey(tokenImpl.getConsumerKey());
    token.setUserAuthentication(tokenImpl.getUserAuthentication());
    token.setSecret(secret);
    token.setValue(tokenValue);
    token.setTimestamp(System.currentTimeMillis());
    onTokenCreated(token);
    storeToken(tokenValue, token);
    return token;
}