-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bearer tokens #74
Merged
Merged
Bearer tokens #74
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
7a919aa
pause commit on this branch (broken)
ryanrdoherty a9f222e
Checkpoint commit; not working
ryanrdoherty e49e138
checkpoint commit
ryanrdoherty bd98c6c
Merge branch 'master' into bearer-tokens
ryanrdoherty 628eb6a
checkpoint refactor commit
ryanrdoherty 36e3778
Merge branch 'master' into bearer-tokens
ryanrdoherty ddd0f25
Complete separation of user prefs from user
ryanrdoherty 42625c2
Remove incorrect documentation
ryanrdoherty 72be5ba
Add signature back into OAuth API (not deprectated after all)
ryanrdoherty 01a27b9
Merge branch 'master' into bearer-tokens
ryanrdoherty cf0c5d3
Make names more consistent
ryanrdoherty ffff175
Changes to support bearer tokens and remove accountdb access from WDK
ryanrdoherty ac484d9
Merge branch 'master' into bearer-tokens
ryanrdoherty 23c59fc
checkpoint commit
ryanrdoherty 95bc896
Fix up user-related services and clean out code a bit
ryanrdoherty fa8c778
Comply with OAuth upgrade in install
ryanrdoherty 54d7c3c
Merge WdkOAuthClientWrapper into UserFactory, but split off managemen…
ryanrdoherty 1ad6449
Convert session to temporary user data store
ryanrdoherty cc2fe2c
Stop using SessionProxy interface
ryanrdoherty 6c7777a
Switch to ConcurrentHashMap in case user has multiple requests going …
ryanrdoherty 72c89a8
Merge pull request #81 from VEuPathDB/temporary-data
ryanrdoherty 5b5cd90
ditch accountdb
ryanrdoherty ba94756
Merge branch 'master' into bearer-tokens
ryanrdoherty 3105dce
Remove accountDb from RNG
ryanrdoherty 16bca8d
Produce user factories on demand vs keeping one around
ryanrdoherty 6882f15
Remove acctdb references
ryanrdoherty af09d25
why is there an NPE?
ryanrdoherty 5afa814
Fix NPE
ryanrdoherty facb734
Comply with new oauth API and try to return better errors
ryanrdoherty 0baf925
Handle expired tokens better + some cleanup
ryanrdoherty 1db781c
Merge branch 'master' into bearer-tokens
ryanrdoherty efb5c29
Just a little cleanup
ryanrdoherty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
Model/src/main/java/org/gusdb/wdk/cache/TemporaryUserDataStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.gusdb.wdk.cache; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import com.github.benmanes.caffeine.cache.RemovalListener; | ||
import com.github.benmanes.caffeine.cache.stats.CacheStats; | ||
|
||
/** | ||
* Manages a map of user-scoped short-term information. Traditionally, | ||
* this data was stored in the user's session object; instead, we store | ||
* it now in a userId-keyed map, whose values time out some duration | ||
* after last access (currently 60 minutes). If instance() is called | ||
* within the application, shutDown() should also be called to clean | ||
* up the expiration thread threadpool. | ||
*/ | ||
public class TemporaryUserDataStore { | ||
|
||
private static final Logger LOG = Logger.getLogger(TemporaryUserDataStore.class); | ||
|
||
public static class TemporaryUserData extends ConcurrentHashMap<String,Object> { | ||
|
||
private final TemporaryUserDataStore _parent; | ||
private final Long _owner; | ||
|
||
private TemporaryUserData(TemporaryUserDataStore parent, Long owner) { | ||
_parent = parent; | ||
_owner = owner; | ||
} | ||
|
||
public void invalidate() { | ||
clear(); | ||
_parent.remove(_owner); | ||
} | ||
|
||
} | ||
|
||
// singleton pattern | ||
private static TemporaryUserDataStore _instance; | ||
|
||
public static synchronized TemporaryUserDataStore instance() { | ||
return _instance == null ? (_instance = new TemporaryUserDataStore()) : _instance; | ||
} | ||
|
||
public static void shutDown() { | ||
if (_instance != null) | ||
_instance._threadPool.shutdown(); | ||
_instance = null; | ||
} | ||
|
||
private static final RemovalListener<Long,Map<String,Object>> LISTENER = | ||
(k,v,cause) -> LOG.info("User " + k + "'s temporary user data store has expired with " + v.size() + " entries; Reason: " + cause); | ||
|
||
private final ExecutorService _threadPool; | ||
private final Cache<Long,TemporaryUserData> _data; | ||
|
||
private TemporaryUserDataStore() { | ||
_threadPool = Executors.newCachedThreadPool(); | ||
_data = Caffeine.newBuilder() | ||
.executor(_threadPool) | ||
.recordStats() | ||
.removalListener(LISTENER) | ||
.expireAfterAccess(60, TimeUnit.MINUTES) | ||
.build(); | ||
} | ||
|
||
public TemporaryUserData get(Long userId) { | ||
return _data.get(userId, id -> new TemporaryUserData(this, id)); | ||
} | ||
|
||
public void remove(Long userId) { | ||
_data.invalidate(userId); | ||
} | ||
|
||
public CacheStats getStats() { | ||
return _data.stats(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking now this is probably not a good idea because it could break other requests. What we want is for the map to be removed from the store but maybe not clear the map. Eventually the whole thing will be garbage collected.