RsrcCtxWrapper implements ResourceContext { public void logPrincipal(final Principal principal) { if (principal == null) { return; } logPrincipal(principal.getFullName()); logAuthorityId(principal.getAuthority()); } RsrcCtxWrapper(HttpServletRequest request, HttpServletResponse response,
            Http.AuthorityList authList,  boolean optionalAuth, Authorizer authorizer,
            Metric metric, Object timerMetric, String apiName); com.yahoo.athenz.common.server.rest.ResourceContext context(); Principal principal(); String getRequestDomain(); Object getTimerMetric(); void setRequestDomain(String requestDomain); @Override HttpServletRequest request(); @Override HttpServletResponse response(); @Override String getApiName(); @Override String getHttpMethod(); @Override void authenticate(); @Override void authorize(String action, String resource, String trustedDomain); void logPrincipal(final Principal principal); void logPrincipal(final String principal); void logAuthorityId(Authority authority); void throwZtsException(com.yahoo.athenz.common.server.rest.ResourceException restExc);  }
@Test public void testLogPrincipal() { HttpServletRequest servletRequest = new MockHttpServletRequest(); HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); AuthorityList authListMock = new AuthorityList(); Authorizer authorizerMock = Mockito.mock(Authorizer.class); Metric metricMock = Mockito.mock(Metric.class); Object timerMetricMock = Mockito.mock(Object.class); RsrcCtxWrapper wrapper = new RsrcCtxWrapper(servletRequest, servletResponse, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName"); wrapper.logPrincipal((Principal) null); assertNull(servletRequest.getAttribute("com.yahoo.athenz.auth.principal")); wrapper.logPrincipal((String) null); assertNull(servletRequest.getAttribute("com.yahoo.athenz.auth.principal")); SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority()); wrapper.logPrincipal(principal); assertEquals(servletRequest.getAttribute("com.yahoo.athenz.auth.principal"), "hockey.kings"); assertEquals(servletRequest.getAttribute("com.yahoo.athenz.auth.authority_id"), "Auth-NTOKEN"); }