Class PersistentServiceProviderTokenStore
- java.lang.Object
-
- com.atlassian.bitbucket.jenkins.internal.applink.oauth.serviceprovider.AbstractPersistentStore<ServiceProviderToken>
-
- com.atlassian.bitbucket.jenkins.internal.applink.oauth.serviceprovider.token.PersistentServiceProviderTokenStore
-
- All Implemented Interfaces:
ServiceProviderTokenStore
,Saveable
,OnMaster
@Singleton public class PersistentServiceProviderTokenStore extends AbstractPersistentStore<ServiceProviderToken> implements ServiceProviderTokenStore
AServiceProviderTokenStore
implementation that persists thetokens
to an XML fileOnly one instance of this class must be created per Jenkins instance.
-
-
Field Summary
-
Fields inherited from class com.atlassian.bitbucket.jenkins.internal.applink.oauth.serviceprovider.AbstractPersistentStore
entityMap, xStream
-
-
Constructor Summary
Constructors Constructor Description PersistentServiceProviderTokenStore(ServiceProviderConsumerStore consumerStore)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<ServiceProviderToken>
get(String token)
Retrieve aServiceProviderToken
from the store whosetoken
attribute is equal to thetoken
parameter.Iterable<ServiceProviderToken>
getAccessTokensForUser(String username)
Retrieves all the access tokens the user has approved.protected Class<ServiceProviderToken>
getEntityClass()
protected String
getStoreEntryName()
protected String
getStoreKeyName()
protected String
getStoreValueName()
ServiceProviderToken
put(ServiceProviderToken token)
Put the token in the store.void
remove(String token)
Remove aServiceProviderToken
from the store whosetoken
attribute value is equal to thetoken
parameter.void
removeByConsumer(String consumerKey)
Remove all theServiceProviderToken
s created by the consumer.void
removeExpiredSessions()
Remove all sessions andServiceProviderToken
s from the store whosesession
has expired.void
removeExpiredTokens()
Remove allServiceProviderToken
s from the store that do not have sessions and whosetimeToLive
has been exceeded.-
Methods inherited from class com.atlassian.bitbucket.jenkins.internal.applink.oauth.serviceprovider.AbstractPersistentStore
decrypt, encrypt, getConfigFile, load, save
-
-
-
-
Constructor Detail
-
PersistentServiceProviderTokenStore
@Inject public PersistentServiceProviderTokenStore(ServiceProviderConsumerStore consumerStore)
-
-
Method Detail
-
get
public Optional<ServiceProviderToken> get(String token)
Description copied from interface:ServiceProviderTokenStore
Retrieve aServiceProviderToken
from the store whosetoken
attribute is equal to thetoken
parameter.- Specified by:
get
in interfaceServiceProviderTokenStore
- Parameters:
token
- token value of theServiceProviderToken
to retrieve- Returns:
- Optional of
ServiceProviderToken
whose value istoken
,Optional.absent()
if there is noServiceProviderToken
instance matching thetoken
parameter
-
getAccessTokensForUser
public Iterable<ServiceProviderToken> getAccessTokensForUser(String username)
Description copied from interface:ServiceProviderTokenStore
Retrieves all the access tokens the user has approved.- Specified by:
getAccessTokensForUser
in interfaceServiceProviderTokenStore
- Parameters:
username
- the user that approved the access tokens to retrieve- Returns:
- all the access tokens the user has approved
-
put
public ServiceProviderToken put(ServiceProviderToken token)
Description copied from interface:ServiceProviderTokenStore
Put the token in the store.- Specified by:
put
in interfaceServiceProviderTokenStore
- Parameters:
token
-ServiceProviderToken
to store- Returns:
- the
ServiceProviderToken
that was stored
-
remove
public void remove(String token)
Description copied from interface:ServiceProviderTokenStore
Remove aServiceProviderToken
from the store whosetoken
attribute value is equal to thetoken
parameter.- Specified by:
remove
in interfaceServiceProviderTokenStore
- Parameters:
token
- token value of theServiceProviderToken
to remove
-
removeExpiredTokens
public void removeExpiredTokens()
Description copied from interface:ServiceProviderTokenStore
Remove allServiceProviderToken
s from the store that do not have sessions and whosetimeToLive
has been exceeded.ServiceProviderToken
s with session information should be left as-is, to be removed by theServiceProviderTokenStore.removeExpiredSessions()
method when the session expires.Note: In 1.4.0 support for OAuth sessions was implemented. Rather than create an entirely separate entity, session information is carried along with access tokens. This means that if we remove expired tokens that have sessions, we will also be removing the session information. Consequently, we don't want to remove an expired token until the session has expired and the token cannot be renewed. To remove expired sessions and the tokens associated with them, use
ServiceProviderTokenStore.removeExpiredSessions()
instead.- Specified by:
removeExpiredTokens
in interfaceServiceProviderTokenStore
-
removeExpiredSessions
public void removeExpiredSessions()
Description copied from interface:ServiceProviderTokenStore
Remove all sessions andServiceProviderToken
s from the store whosesession
has expired.- Specified by:
removeExpiredSessions
in interfaceServiceProviderTokenStore
-
removeByConsumer
public void removeByConsumer(String consumerKey)
Description copied from interface:ServiceProviderTokenStore
Remove all theServiceProviderToken
s created by the consumer.- Specified by:
removeByConsumer
in interfaceServiceProviderTokenStore
- Parameters:
consumerKey
- key of the consumer that created the tokens which are to be removed
-
getEntityClass
protected Class<ServiceProviderToken> getEntityClass()
- Specified by:
getEntityClass
in classAbstractPersistentStore<ServiceProviderToken>
-
getStoreValueName
protected String getStoreValueName()
- Specified by:
getStoreValueName
in classAbstractPersistentStore<ServiceProviderToken>
-
getStoreKeyName
protected String getStoreKeyName()
- Specified by:
getStoreKeyName
in classAbstractPersistentStore<ServiceProviderToken>
-
getStoreEntryName
protected String getStoreEntryName()
- Specified by:
getStoreEntryName
in classAbstractPersistentStore<ServiceProviderToken>
-
-