ZMSUtils { public static AuditLogMsgBuilder getAuditLogMsgBuilder(ResourceContext ctx, AuditLogger auditLogger, String domainName, String auditRef, String caller, String method) { AuditLogMsgBuilder msgBldr = auditLogger.getMsgBuilder(); msgBldr.where(ZMSImpl.serverHostName); msgBldr.whatDomain(domainName).why(auditRef).whatApi(caller).whatMethod(method); if (ctx != null) { Principal princ = ((RsrcCtxWrapper) ctx).principal(); if (princ != null) { String fullName = princ.getFullName(); String unsignedCreds = princ.getUnsignedCredentials(); if (unsignedCreds == null) { StringBuilder sb = new StringBuilder(); sb.append("who-name=").append(princ.getName()); sb.append(",who-domain=").append(princ.getDomain()); sb.append(",who-fullname=").append(fullName); List<String> roles = princ.getRoles(); if (roles != null && roles.size() > 0) { sb.append(",who-roles=").append(roles.toString()); } unsignedCreds = sb.toString(); } msgBldr.who(unsignedCreds); msgBldr.whoFullName(fullName); } msgBldr.clientIp(ServletRequestUtil.getRemoteAddress(ctx.request())); } return msgBldr; }  static void addAssertion(Policy policy, String resource, String action, String role,
            AssertionEffect effect); static Role makeAdminRole(String domainName, List<String> adminUsers); static Policy makeAdminPolicy(String domainName, Role adminsRole); static String roleResourceName(String domainName, String roleName); static String groupResourceName(String domainName, String groupName); static String policyResourceName(String domainName, String policyName); static String serviceResourceName(String domainName, String serviceName); static String entityResourceName(String domainName, String serviceName); static String removeDomainPrefix(String objectName, String domainName, String objectPrefix); static String removeDomainPrefixForService(String serviceName, String domainName); static String getTenantResourceGroupRolePrefix(String provSvcName, String tenantDomain, String resourceGroup); static String getProviderResourceGroupRolePrefix(String provSvcDomain, String provSvcName, String resourceGroup); static String getTrustedResourceGroupRolePrefix(String provSvcDomain, String provSvcName,
            String tenantDomain, String resourceGroup); static List<String> convertRoleMembersToMembers(List<RoleMember> members); static List<RoleMember> convertMembersToRoleMembers(List<String> members); static AuditLogMsgBuilder getAuditLogMsgBuilder(ResourceContext ctx,
            AuditLogger auditLogger, String domainName, String auditRef, String caller,
            String method); static RuntimeException error(int code, String msg, String caller); static RuntimeException requestError(String msg, String caller); static RuntimeException unauthorizedError(String msg, String caller); static RuntimeException forbiddenError(String msg, String caller); static RuntimeException notFoundError(String msg, String caller); static RuntimeException internalServerError(String msg, String caller); static RuntimeException quotaLimitError(String msg, String caller); static boolean emitMonmetricError(int errorCode, String caller); static void threadSleep(long millis); static boolean parseBoolean(final String value, boolean defaultValue); static Principal.Type principalType(final String memberName, final String userDomainPrefix,
                                               final List<String> addlUserCheckDomainPrefixList); static boolean isUserDomainPrincipal(final String memberName, final String userDomainPrefix,
            final List<String> addlUserCheckDomainPrefixList); static String extractObjectName(String domainName, String fullName, String objType); static String extractRoleName(String domainName, String fullRoleName); static String extractGroupName(String domainName, String fullGroupName); static String extractPolicyName(String domainName, String fullPolicyName); static String extractServiceName(String domainName, String fullServiceName); static boolean isUserAuthorityFilterValid(Authority userAuthority, final String filterList, final String memberName); static String combineUserAuthorityFilters(final String roleUserAuthorityFilter, final String domainUserAuthorityFilter); static String lowerDomainInResource(String resource); static boolean userAuthorityAttrMissing(final String origAttrList, final String checkAttrList);  }
@Test public void testGetAudtLogMsgBuilder() { List<String> roles = Arrays.asList("role1", "role2"); Principal principal = SimplePrincipal.create("athenz", "creds", roles, null); RsrcCtxWrapper ctx = Mockito.mock(RsrcCtxWrapper.class); Mockito.when(ctx.principal()).thenReturn(principal); HttpServletRequestWrapper request = Mockito.mock(HttpServletRequestWrapper.class); Mockito.when(ctx.request()).thenReturn(request); Mockito.when(request.getRemoteAddr()).thenReturn("10.11.12.13"); AuditLoggerFactory factory = new DefaultAuditLoggerFactory(); AuditLogger auditLogger = factory.create(); AuditLogMsgBuilder msgBuilder = ZMSUtils.getAuditLogMsgBuilder(ctx, auditLogger, "athenz", "audit-ref", "unit-test", "putRole"); assertNotNull(msgBuilder); assertTrue(msgBuilder.who().contains("who-roles=[role1, role2]"), msgBuilder.who()); }