Skip to content

Commit a870aea

Browse files
committed
Addressing comments from @singhpk234
1 parent e2ed743 commit a870aea

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

runtime/service/src/main/java/org/apache/polaris/service/events/jsonEventListener/aws/cloudwatch/AwsCloudWatchEventListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.List;
3434
import java.util.concurrent.CompletableFuture;
3535
import java.util.function.Supplier;
36+
import org.apache.polaris.core.auth.PolarisPrincipal;
3637
import org.apache.polaris.core.context.CallContext;
3738
import org.apache.polaris.service.config.PolarisIcebergObjectMapperCustomizer;
3839
import org.apache.polaris.service.events.jsonEventListener.PropertyMapEventListener;
@@ -146,19 +147,23 @@ private static void ensureResourceExists(
146147
void shutdown() {
147148
if (client != null) {
148149
client.close();
150+
client = null;
149151
}
150152
}
151153

152154
@Override
153155
protected void transformAndSendEvent(HashMap<String, Object> properties) {
154156
properties.put("realm_id", callContext.getRealmContext().getRealmIdentifier());
155157
properties.put("principal", securityContext.getUserPrincipal().getName());
158+
properties.put(
159+
"activated_roles", ((PolarisPrincipal) securityContext.getUserPrincipal()).getRoles());
156160
// TODO: Add request ID when it is available
157161
String eventAsJson;
158162
try {
159163
eventAsJson = objectMapper.writeValueAsString(properties);
160164
} catch (JsonProcessingException e) {
161165
LOGGER.error("Error processing event into JSON string: ", e);
166+
LOGGER.debug("Failed to convert the following object into JSON string: {}", properties);
162167
return;
163168
}
164169
InputLogEvent inputLogEvent =

runtime/service/src/test/java/org/apache/polaris/service/events/jsonEventListener/aws/cloudwatch/AwsCloudWatchEventListenerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
import java.security.Principal;
3131
import java.time.Clock;
3232
import java.time.Duration;
33+
import java.util.Set;
3334
import java.util.concurrent.ExecutorService;
3435
import java.util.concurrent.Executors;
3536
import java.util.concurrent.TimeUnit;
3637
import org.apache.iceberg.catalog.TableIdentifier;
3738
import org.apache.polaris.core.PolarisCallContext;
39+
import org.apache.polaris.core.auth.PolarisPrincipal;
3840
import org.apache.polaris.core.context.CallContext;
3941
import org.apache.polaris.core.context.RealmContext;
4042
import org.apache.polaris.service.config.PolarisIcebergObjectMapperCustomizer;
@@ -141,12 +143,13 @@ protected CloudWatchLogsAsyncClient createCloudWatchAsyncClient() {
141143
PolarisCallContext polarisCallContext = Mockito.mock(PolarisCallContext.class);
142144
RealmContext realmContext = Mockito.mock(RealmContext.class);
143145
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
144-
Principal principal = Mockito.mock(Principal.class);
146+
Principal principal = Mockito.mock(PolarisPrincipal.class);
145147
when(callContext.getRealmContext()).thenReturn(realmContext);
146148
when(callContext.getPolarisCallContext()).thenReturn(polarisCallContext);
147149
when(realmContext.getRealmIdentifier()).thenReturn(REALM);
148150
when(securityContext.getUserPrincipal()).thenReturn(principal);
149151
when(principal.getName()).thenReturn(TEST_USER);
152+
when(((PolarisPrincipal) principal).getRoles()).thenReturn(Set.of("role1", "role2"));
150153
listener.callContext = callContext;
151154
listener.securityContext = securityContext;
152155

0 commit comments

Comments
 (0)