Search in sources :

Example 1 with RsrcCtxWrapper

use of com.yahoo.athenz.zms.RsrcCtxWrapper in project athenz by yahoo.

the class ZMSUtils method getAuditLogMsgBuilder.

/**
 * Setup a new AuditLogMsgBuilder object with common values.
 */
public static AuditLogMsgBuilder getAuditLogMsgBuilder(ResourceContext ctx, AuditLogger auditLogger, String domainName, String auditRef, String caller, String method) {
    AuditLogMsgBuilder msgBldr = auditLogger.getMsgBuilder();
    // get the where - which means where this server is running
    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 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(princ.getFullName());
                List<String> roles = princ.getRoles();
                if (roles != null && roles.size() > 0) {
                    sb.append(",who-roles=").append(roles.toString());
                }
                unsignedCreds = sb.toString();
            }
            msgBldr.who(unsignedCreds);
        }
        // get the client IP
        msgBldr.clientIp(ServletRequestUtil.getRemoteAddress(ctx.request()));
    }
    return msgBldr;
}
Also used : AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) RsrcCtxWrapper(com.yahoo.athenz.zms.RsrcCtxWrapper) Principal(com.yahoo.athenz.auth.Principal)

Aggregations

Principal (com.yahoo.athenz.auth.Principal)1 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)1 RsrcCtxWrapper (com.yahoo.athenz.zms.RsrcCtxWrapper)1