RsrcCtxWrapper implements ResourceContext { public void logPrincipal(final Principal principal) { if (principal == null) { return; } ctx.request().setAttribute(ServerCommonConsts.REQUEST_PRINCIPAL, principal.getFullName()); logAuthorityId(principal.getAuthority()); } RsrcCtxWrapper(HttpServletRequest request, HttpServletResponse response,
                   Http.AuthorityList authList, boolean optionalAuth,
                   Authorizer authorizer, Object timerMetric, String apiName); Principal principal(); String getRequestDomain(); Object getTimerMetric(); void setRequestDomain(String requestDomain); @Override String getApiName(); @Override String getHttpMethod(); @Override HttpServletRequest request(); @Override HttpServletResponse response(); @Override void authenticate(); @Override void authorize(String action, String resource, String trustedDomain); void logPrincipal(final Principal principal); void logAuthorityId(Authority authority);  }
@Test public void testLogPrincipal() { HttpServletRequest servletRequest = new MockHttpServletRequest(); HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); AuthorityList authListMock = new AuthorityList(); Authorizer authorizerMock = Mockito.mock(Authorizer.class); Object timerMetric = new Object(); RsrcCtxWrapper wrapper = new RsrcCtxWrapper(servletRequest, servletResponse, authListMock, false, authorizerMock, timerMetric, "apiName"); wrapper.logPrincipal(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"); }