Skip to content
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 32 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
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 Aug 2, 2023
a9f222e
Checkpoint commit; not working
ryanrdoherty Sep 6, 2023
e49e138
checkpoint commit
ryanrdoherty Oct 12, 2023
bd98c6c
Merge branch 'master' into bearer-tokens
ryanrdoherty Oct 12, 2023
628eb6a
checkpoint refactor commit
ryanrdoherty Oct 17, 2023
36e3778
Merge branch 'master' into bearer-tokens
ryanrdoherty Nov 6, 2023
ddd0f25
Complete separation of user prefs from user
ryanrdoherty Dec 6, 2023
42625c2
Remove incorrect documentation
ryanrdoherty Dec 14, 2023
72be5ba
Add signature back into OAuth API (not deprectated after all)
ryanrdoherty Dec 14, 2023
01a27b9
Merge branch 'master' into bearer-tokens
ryanrdoherty Dec 18, 2023
cf0c5d3
Make names more consistent
ryanrdoherty Jan 17, 2024
ffff175
Changes to support bearer tokens and remove accountdb access from WDK
ryanrdoherty Feb 1, 2024
ac484d9
Merge branch 'master' into bearer-tokens
ryanrdoherty Feb 5, 2024
23c59fc
checkpoint commit
ryanrdoherty Feb 8, 2024
95bc896
Fix up user-related services and clean out code a bit
ryanrdoherty Feb 21, 2024
fa8c778
Comply with OAuth upgrade in install
ryanrdoherty Feb 21, 2024
54d7c3c
Merge WdkOAuthClientWrapper into UserFactory, but split off managemen…
ryanrdoherty Feb 22, 2024
1ad6449
Convert session to temporary user data store
ryanrdoherty Feb 22, 2024
cc2fe2c
Stop using SessionProxy interface
ryanrdoherty Feb 23, 2024
6c7777a
Switch to ConcurrentHashMap in case user has multiple requests going …
ryanrdoherty Feb 24, 2024
72c89a8
Merge pull request #81 from VEuPathDB/temporary-data
ryanrdoherty Feb 24, 2024
5b5cd90
ditch accountdb
ryanrdoherty Feb 27, 2024
ba94756
Merge branch 'master' into bearer-tokens
ryanrdoherty Feb 27, 2024
3105dce
Remove accountDb from RNG
ryanrdoherty Feb 27, 2024
16bca8d
Produce user factories on demand vs keeping one around
ryanrdoherty Feb 27, 2024
6882f15
Remove acctdb references
ryanrdoherty Feb 28, 2024
af09d25
why is there an NPE?
ryanrdoherty Feb 28, 2024
5afa814
Fix NPE
ryanrdoherty Feb 28, 2024
facb734
Comply with new oauth API and try to return better errors
ryanrdoherty Mar 1, 2024
0baf925
Handle expired tokens better + some cleanup
ryanrdoherty Mar 1, 2024
1db781c
Merge branch 'master' into bearer-tokens
ryanrdoherty Mar 11, 2024
efb5c29
Just a little cleanup
ryanrdoherty Mar 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions Model/lib/conifer/roles/conifer/templates/WDK/model-config.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -145,49 +145,6 @@ site_vars file: {{ site_vars }}
{% endif -%}
/>

<accountDb login="{{ modelconfig_accountDb_login }}"
password="{{ modelconfig_accountDb_password }}"
connectionUrl="{{ modelconfig_accountDb_connectionUrl }}"
platform="{{ modelconfig_accountDb_platform }}"
accountSchema="{{ modelconfig_accountDb_accountSchema }}"
{% if modelconfig_accountDb_maxActive is defined -%}
maxActive="{{ modelconfig_accountDb_maxActive }}"
{% endif -%}
{% if modelconfig_accountDb_maxIdle is defined -%}
maxIdle="{{ modelconfig_accountDb_maxIdle }}"
{% endif -%}
{% if modelconfig_accountDb_minIdle is defined -%}
minIdle="{{ modelconfig_accountDb_minIdle }}"
{% endif -%}
{% if modelconfig_accountDb_maxWait is defined -%}
maxWait="{{ modelconfig_accountDb_maxWait }}"
{% endif -%}
{% if modelconfig_accountDb_defaultFetchSize is defined -%}
defaultFetchSize="{{ modelconfig_accountDb_defaultFetchSize }}"
{% endif -%}
{% if modelconfig_accountDb_showConnections is defined -%}
showConnections="{{ modelconfig_accountDb_showConnections }}"
{% endif -%}
{% if modelconfig_accountDb_showConnectionsInterval is defined -%}
showConnectionsInterval="{{ modelconfig_accountDb_showConnectionsInterval }}"
{% endif -%}
{% if modelconfig_accountDb_showConnectionsDuration is defined -%}
showConnectionsDuration="{{ modelconfig_accountDb_showConnectionsDuration }}"
{% endif -%}
{% if modelconfig_accountDb_driverInitClass is defined -%}
driverInitClass="{{ modelconfig_accountDb_driverInitClass }}"
{% endif %}
>

<userProperty name="username" displayName="Username" dbKey="username"/>
<userProperty name="firstName" displayName="First Name" dbKey="first_name" required="true"/>
<userProperty name="middleName" displayName="Middle Name" dbKey="middle_name"/>
<userProperty name="lastName" displayName="Last Name" dbKey="last_name" required="true"/>
<userProperty name="organization" displayName="Organization" dbKey="organization" required="true"/>
<userProperty name="interests" displayName="Interests" dbKey="interests" multiLine="true"/>

</accountDb>

{% if modelconfig_userDatasetStoreConfig is defined -%}
{{ modelconfig_userDatasetStoreConfig|indent }}
{% endif -%}
Expand Down
33 changes: 0 additions & 33 deletions Model/lib/rng/wdkModel-config.rng
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,6 @@
<attribute name="userSchema" />
</element>

<element name="accountDb">
<ref name="DBBaseContent" />
<attribute name="accountSchema" />
<zeroOrMore>
<element name="userProperty">
<attribute name="name">
<data type="string"/>
</attribute>
<attribute name="displayName">
<data type="string"/>
</attribute>
<attribute name="dbKey">
<data type="string"/>
</attribute>
<optional>
<attribute name="required">
<data type="boolean"/>
</attribute>
</optional>
<optional>
<attribute name="public">
<data type="boolean"/>
</attribute>
</optional>
<optional>
<attribute name="multiLine">
<data type="boolean"/>
</attribute>
</optional>
</element>
</zeroOrMore>
</element>

<optional>
<element name="userDatasetStore">
<attribute name="implementation"/>
Expand Down
22 changes: 8 additions & 14 deletions Model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,22 @@

<dependency>
<groupId>org.gusdb</groupId>
<artifactId>fgputil-accountdb</artifactId>
<artifactId>fgputil-server</artifactId>
</dependency>

<dependency>
<groupId>org.gusdb</groupId>
<artifactId>fgputil-server</artifactId>
<artifactId>fgputil-db</artifactId>
</dependency>

<dependency>
<groupId>org.gusdb</groupId>
<artifactId>fgputil-db</artifactId>
<artifactId>oauth2-client</artifactId>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -115,17 +120,6 @@
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
Expand Down
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();
Copy link
Member Author

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.

_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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.gusdb.fgputil.logging.ThreadLocalLoggingVars;
import org.gusdb.fgputil.runtime.GusHome;
import org.gusdb.fgputil.web.ApplicationContext;
import org.gusdb.wdk.cache.TemporaryUserDataStore;
import org.gusdb.wdk.model.ThreadMonitor;
import org.gusdb.wdk.model.Utilities;
import org.gusdb.wdk.model.WdkModel;
Expand Down Expand Up @@ -77,6 +78,9 @@ public static void terminateWdk(ApplicationContext applicationScope) {
// shut down thread monitor
ThreadMonitor.shutDown();

// shut down TemporaryUserData threadpool
TemporaryUserDataStore.shutDown();

WdkModel wdkModel = getWdkModel(applicationScope);
if (wdkModel != null) {
// insulate in case model never properly loaded
Expand Down
Loading
Loading