Skip to content

Commit

Permalink
fixes #2309: Do not reach out to remote user operations when asked (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
d-hwang authored Mar 14, 2024
1 parent b087ac9 commit 150e293
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import datawave.microservice.querymetric.QueryMetricFactoryImpl;
import datawave.security.authorization.DatawavePrincipal;
import datawave.security.authorization.UserOperations;
import datawave.security.authorization.remote.RemoteUserOperationsImpl;
import datawave.security.util.WSAuthorizationsUtil;
import datawave.webservice.common.connection.AccumuloConnectionFactory;
import datawave.webservice.query.Query;
Expand Down Expand Up @@ -131,8 +132,11 @@ public RunningQuery(QueryMetricsBean queryMetrics, AccumuloClient client, Accumu
DatawavePrincipal queryPrincipal = (logic.getUserOperations() == null) ? (DatawavePrincipal) principal
: logic.getUserOperations().getRemoteUser((DatawavePrincipal) principal);
// the overall principal (the one with combined auths across remote user operations) is our own user operations (probably the UserOperationsBean)
DatawavePrincipal overallPrincipal = (userOperations == null) ? (DatawavePrincipal) principal
: userOperations.getRemoteUser((DatawavePrincipal) principal);
// don't call remote user operations if it's asked not to
DatawavePrincipal overallPrincipal = (userOperations == null
|| "false".equalsIgnoreCase(settings.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES).getParameterValue()))
? (DatawavePrincipal) principal
: userOperations.getRemoteUser((DatawavePrincipal) principal);
this.calculatedAuths = WSAuthorizationsUtil.getDowngradedAuthorizations(methodAuths, overallPrincipal, queryPrincipal);
this.timing = timing;
this.executor = Executors.newSingleThreadExecutor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import datawave.query.data.UUIDType;
import datawave.security.authorization.DatawavePrincipal;
import datawave.security.authorization.UserOperations;
import datawave.security.authorization.remote.RemoteUserOperationsImpl;
import datawave.security.util.WSAuthorizationsUtil;
import datawave.util.time.DateHelper;
import datawave.webservice.common.audit.AuditParameters;
Expand Down Expand Up @@ -478,8 +479,11 @@ public String getAuths(String logicName, MultivaluedMap<String,String> queryPara
DatawavePrincipal queryPrincipal = (logic.getUserOperations() == null) ? (DatawavePrincipal) principal
: logic.getUserOperations().getRemoteUser((DatawavePrincipal) principal);
// the overall principal (the one with combined auths across remote user operations) is our own user operations (probably the UserOperationsBean)
DatawavePrincipal overallPrincipal = (userOperations == null) ? (DatawavePrincipal) principal
: userOperations.getRemoteUser((DatawavePrincipal) principal);
// don't call remote user operations if it's asked not to
DatawavePrincipal overallPrincipal = (userOperations == null
|| "false".equalsIgnoreCase(queryParameters.getFirst(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES)))
? (DatawavePrincipal) principal
: userOperations.getRemoteUser((DatawavePrincipal) principal);
if (queryAuths != null) {
userAuths = WSAuthorizationsUtil.downgradeUserAuths(queryAuths, overallPrincipal, queryPrincipal);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import datawave.security.authorization.DatawaveUser;
import datawave.security.authorization.SubjectIssuerDNPair;
import datawave.security.authorization.UserOperations;
import datawave.security.authorization.remote.RemoteUserOperationsImpl;
import datawave.security.user.UserOperationsBean;
import datawave.security.util.WSAuthorizationsUtil;
import datawave.webservice.common.audit.AuditBean;
Expand Down Expand Up @@ -372,6 +373,8 @@ public void testAdminCancel_LookupAccumuloQuery() throws Exception {
expect(this.query.getPageTimeout()).andReturn(-1).anyTimes();
expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
expect(context.getCallerPrincipal()).andReturn(principal);
expect(this.queryLogicFactory.getQueryLogic("ql1", principal)).andReturn((QueryLogic) this.queryLogic1);
expect(this.queryLogic1.getConnectionPriority()).andReturn(Priority.NORMAL);
Expand Down Expand Up @@ -770,6 +773,8 @@ public void testCreateQueryAndNext_HappyPath() throws Exception {
expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
expect(this.query.getUncaughtExceptionHandler()).andReturn(new QueryUncaughtExceptionHandler()).anyTimes();
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
this.metrics.updateMetric(isA(QueryMetric.class));
PowerMock.expectLastCall().times(2);
expect(this.query.getUserDN()).andReturn(userDN).anyTimes();
Expand Down Expand Up @@ -949,6 +954,8 @@ public void testCreateQueryAndNext_BadID() throws Exception {
expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
expect(this.query.getUncaughtExceptionHandler()).andReturn(new QueryUncaughtExceptionHandler()).anyTimes();
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
this.metrics.updateMetric(isA(QueryMetric.class));
PowerMock.expectLastCall().times(2);
expect(this.query.getUserDN()).andReturn(userDN).anyTimes();
Expand Down Expand Up @@ -1459,6 +1466,8 @@ public void testCreateQueryAndNext_DoubleAuditValues() throws Exception {
expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
expect(this.query.getUncaughtExceptionHandler()).andReturn(new QueryUncaughtExceptionHandler()).anyTimes();
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
this.metrics.updateMetric(isA(QueryMetric.class));
PowerMock.expectLastCall().times(2);
expect(this.query.getUserDN()).andReturn(userDN).anyTimes();
Expand Down Expand Up @@ -1762,6 +1771,8 @@ public void testCreateQueryAndNext_ButNoResults() throws Exception {
expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
expect(this.query.getUncaughtExceptionHandler()).andReturn(new QueryUncaughtExceptionHandler()).anyTimes();
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
this.metrics.updateMetric(isA(QueryMetric.class));
PowerMock.expectLastCall().times(2);
expect(this.query.getUserDN()).andReturn(userDN).anyTimes();
Expand Down Expand Up @@ -2823,6 +2834,8 @@ public void testList_HappyPath() throws Exception {
expect(this.query.getPageTimeout()).andReturn(-1).anyTimes();
expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
expect(this.query.getDnList()).andReturn(dnList).anyTimes();
expect(this.queryLogic1.getResultLimit(this.query)).andReturn(-1L);
expect(this.queryLogic1.getMaxResults()).andReturn(-1L);
Expand Down Expand Up @@ -3340,6 +3353,8 @@ public void testReset_NoPreexistingRunningQuery() throws Exception {
expect(this.query.getEndDate()).andReturn(null);
expect(this.query.getQueryName()).andReturn(queryName);
expect(this.query.getParameters()).andReturn((Set) Collections.emptySet());
expect(this.query.findParameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES))
.andReturn(new QueryImpl.Parameter(RemoteUserOperationsImpl.INCLUDE_REMOTE_SERVICES, "true")).anyTimes();
expect(this.query.getColumnVisibility()).andReturn(authorization);
expect(this.queryLogic1.getSelectors(this.query)).andReturn(null);
expect(this.auditor.audit(auditMap)).andReturn(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RemoteUserOperationsImpl extends RemoteHttpService implements UserO

private static final String FLUSH_CREDS = "flushCachedCredentials";

private static final String INCLUDE_REMOTE_SERVICES = "includeRemoteServices";
public static final String INCLUDE_REMOTE_SERVICES = "includeRemoteServices";

private ObjectReader genericResponseReader;

Expand Down

0 comments on commit 150e293

Please sign in to comment.