Skip to content

Commit

Permalink
Changes to support bearer tokens and remove accountdb access from WDK
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrdoherty committed Feb 1, 2024
1 parent cf0c5d3 commit ffff175
Show file tree
Hide file tree
Showing 30 changed files with 433 additions and 744 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,7 @@ site_vars file: {{ site_vars }}
{% 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 }}
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions Model/src/main/java/org/gusdb/wdk/model/WdkModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import org.gusdb.wdk.model.user.BasketFactory;
import org.gusdb.wdk.model.user.FavoriteFactory;
import org.gusdb.wdk.model.user.StepFactory;
import org.gusdb.wdk.model.user.UnregisteredUser.UnregisteredUserType;
import org.gusdb.wdk.model.user.User;
import org.gusdb.wdk.model.user.UserFactory;
import org.gusdb.wdk.model.user.analysis.StepAnalysisFactory;
Expand Down Expand Up @@ -1365,7 +1364,7 @@ public User getSystemUser() {
try {
systemUserLock.lock();
if (systemUser == null) {
systemUser = userFactory.createUnregistedUser(UnregisteredUserType.SYSTEM);
systemUser = userFactory.createUnregistedUser();
}
}
finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.gusdb.wdk.model.config;

import java.util.ArrayList;
import java.util.List;

import org.gusdb.fgputil.accountdb.UserPropertyName;
import org.gusdb.fgputil.db.platform.DBPlatform;

public class ModelConfigAccountDB extends ModelConfigDB {

private String _accountSchema;
private List<UserPropertyName> _userPropertyNames = new ArrayList<UserPropertyName>();

public void setAccountSchema(String accountSchema) {
_accountSchema = DBPlatform.normalizeSchema(accountSchema);
Expand All @@ -18,12 +13,4 @@ public void setAccountSchema(String accountSchema) {
public String getAccountSchema() {
return _accountSchema;
}

public void addUserPropertyName(UserPropertyName property) {
_userPropertyNames.add(property);
}

public List<UserPropertyName> getUserPropertyNames() {
return _userPropertyNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.URL;

import org.apache.commons.digester3.Digester;
import org.gusdb.fgputil.accountdb.UserPropertyName;
import org.gusdb.fgputil.xml.XmlParser;
import org.gusdb.fgputil.xml.XmlValidator;
import org.gusdb.wdk.model.WdkModelException;
Expand Down Expand Up @@ -65,7 +64,6 @@ private static Digester configureDigester() {

// load user db
configureNode(digester, "modelConfig/accountDb", ModelConfigAccountDB.class, "setAccountDB");
configureNode(digester, "modelConfig/accountDb/userProperty", UserPropertyName.class, "addUserPropertyName");

// userdatasetstore
configureNode(digester, "modelConfig/userDatasetStore", ModelConfigUserDatasetStore.class, "setUserDatasetStore");
Expand Down
51 changes: 51 additions & 0 deletions Model/src/main/java/org/gusdb/wdk/model/user/BearerTokenUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.gusdb.wdk.model.user;

import org.apache.log4j.Logger;
import org.gusdb.oauth2.client.ValidatedToken;
import org.gusdb.oauth2.shared.token.IdTokenFields;
import org.gusdb.wdk.model.WdkModel;
import org.gusdb.wdk.session.WdkOAuthClientWrapper;
import org.json.JSONObject;

public class BearerTokenUser extends User {

private static final Logger LOG = Logger.getLogger(BearerTokenUser.class);

private final WdkOAuthClientWrapper _client;
private final ValidatedToken _token;
private boolean _userInfoFetched = false;

public BearerTokenUser(WdkModel wdkModel, WdkOAuthClientWrapper client, ValidatedToken token) {
// parent constructor sets immutable fields provided on the token
super(wdkModel,
Long.valueOf(token.getUserId()),
token.isGuest(),
token.getTokenContents().get(IdTokenFields.signature.name(), String.class),
token.getTokenContents().get(IdTokenFields.preferred_username.name(), String.class));
_client = client;
_token = token;
}

@Override
protected void fetchUserInfo() {
// return if already fetched
if (_userInfoFetched) return;

LOG.info("User data fetch requested for user " + getUserId() + "; querying OAuth server.");
// fetch user info from OAuth server where it is stored (but only on demand, and only once for this object's lifetime)
JSONObject userInfo = _client.getUserData(_token);

// set email (standard property but mutable so set on user profile and not token
setEmail(userInfo.getString(IdTokenFields.email.name()));

// set other user properties found only on user profile object
for (WdkUserProperty userProp : User.USER_PROPERTIES.values()) {
userProp.setValue(this, userInfo.optString(userProp.getName(), null));
}

LOG.info("User data successfully fetched for " + getDisplayName() + " / " + getOrganization());
_userInfoFetched = true;
}

}

28 changes: 0 additions & 28 deletions Model/src/main/java/org/gusdb/wdk/model/user/RegisteredUser.java

This file was deleted.

39 changes: 0 additions & 39 deletions Model/src/main/java/org/gusdb/wdk/model/user/UnregisteredUser.java

This file was deleted.

Loading

0 comments on commit ffff175

Please sign in to comment.