### Question:
HttpRequestSessionContext implements SessionContext { @Override public Identity getIdentity() { return identity; } HttpRequestSessionContext(MultivaluedMap<String, String> headers, String remoteAddress, Optional<Identity> authenticatedIdentity, GroupProvider groupProvider); static Identity extractAuthorizedIdentity(HttpServletRequest servletRequest, HttpHeaders httpHeaders, AccessControl accessControl, GroupProvider groupProvider); static Identity extractAuthorizedIdentity(Optional<Identity> optionalAuthenticatedIdentity, MultivaluedMap<String, String> headers, AccessControl accessControl, GroupProvider groupProvider); @Override Optional<Identity> getAuthenticatedIdentity(); @Override Identity getIdentity(); @Override String getCatalog(); @Override String getSchema(); @Override String getPath(); @Override String getSource(); @Override String getRemoteUserAddress(); @Override String getUserAgent(); @Override String getClientInfo(); @Override Set<String> getClientTags(); @Override Set<String> getClientCapabilities(); @Override ResourceEstimates getResourceEstimates(); @Override String getTimeZoneId(); @Override String getLanguage(); @Override Map<String, String> getSystemProperties(); @Override Map<String, Map<String, String>> getCatalogSessionProperties(); @Override Map<String, String> getPreparedStatements(); @Override Optional<TransactionId> getTransactionId(); @Override boolean supportClientTransaction(); @Override Optional<String> getTraceToken(); static final String AUTHENTICATED_IDENTITY; }### Answer:
@Test public void testMappedUser() { MultivaluedMap<String, String> userHeaders = new GuavaMultivaluedMap<>(ImmutableListMultimap.of(PRESTO_USER, "testUser")); MultivaluedMap<String, String> emptyHeaders = new MultivaluedHashMap<>(); HttpRequestSessionContext context = new HttpRequestSessionContext(userHeaders, "testRemote", Optional.empty(), ImmutableSet::of); assertEquals(context.getIdentity(), Identity.forUser("testUser").withGroups(ImmutableSet.of("testUser")).build()); context = new HttpRequestSessionContext( emptyHeaders, "testRemote", Optional.of(Identity.forUser("mappedUser").withGroups(ImmutableSet.of("test")).build()), ImmutableSet::of); assertEquals(context.getIdentity(), Identity.forUser("mappedUser").withGroups(ImmutableSet.of("test", "mappedUser")).build()); context = new HttpRequestSessionContext(userHeaders, "testRemote", Optional.of(Identity.ofUser("mappedUser")), ImmutableSet::of); assertEquals(context.getIdentity(), Identity.forUser("testUser").withGroups(ImmutableSet.of("testUser")).build()); assertThatThrownBy(() -> new HttpRequestSessionContext(emptyHeaders, "testRemote", Optional.empty(), user -> ImmutableSet.of())) .isInstanceOf(WebApplicationException.class) .matches(e -> ((WebApplicationException) e).getResponse().getStatus() == 400); }