Search in sources :

Example 1 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder in project athenz by yahoo.

the class AuditLogMsgBuilderTest method starter.

DefaultAuditLogMsgBuilder starter(final String whatApi) {
    AuditLoggerFactory auditLoggerFactory = new DefaultAuditLoggerFactory();
    AuditLogger logger = auditLoggerFactory.create();
    AuditLogMsgBuilder msgBldr = logger.getMsgBuilder();
    msgBldr.who(TOKEN_STR).when("now-timestamp").clientIp("12.12.12.12").whatApi(whatApi);
    return (DefaultAuditLogMsgBuilder) msgBldr;
}
Also used : DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) AuditLoggerFactory(com.yahoo.athenz.common.server.log.AuditLoggerFactory) AuditLogger(com.yahoo.athenz.common.server.log.AuditLogger) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder)

Example 2 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder in project athenz by yahoo.

the class AuditLoggerTest method testLogMsgBuilder.

@Test
public void testLogMsgBuilder() {
    AuditLoggerFactory auditLoggerFactory = new DefaultAuditLoggerFactory();
    AuditLogger logger = auditLoggerFactory.create();
    AuditLogMsgBuilder msgBldr = logger.getMsgBuilder();
    auditLogger.log(msgBldr);
}
Also used : AuditLoggerFactory(com.yahoo.athenz.common.server.log.AuditLoggerFactory) AuditLogger(com.yahoo.athenz.common.server.log.AuditLogger) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) Test(org.testng.annotations.Test)

Example 3 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder 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)

Example 4 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder in project athenz by yahoo.

the class ZTSImplTest method testGetRoleTokenInvalidDomainAuditLog.

@Test
public void testGetRoleTokenInvalidDomainAuditLog() {
    HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(servletRequest.getRemoteAddr()).thenReturn("55.88.77.66");
    Mockito.when(servletRequest.isSecure()).thenReturn(true);
    final java.util.Set<String> aLogMsgs = new java.util.HashSet<String>();
    AuditLogger alogger = new AuditLogger() {

        public void log(String logMsg, String msgVersionTag) {
            aLogMsgs.add(logMsg);
        }

        public void log(AuditLogMsgBuilder msgBldr) {
            String msg = msgBldr.build();
            aLogMsgs.add(msg);
        }

        @Override
        public AuditLogMsgBuilder getMsgBuilder() {
            return new DefaultAuditLogMsgBuilder();
        }
    };
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.auditLogger = alogger;
    ZTSImpl.serverHostName = "localhost";
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal, servletRequest);
    try {
        ztsImpl.getRoleToken(context, "invalidDomain", null, Integer.valueOf(600), Integer.valueOf(1200), null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 404);
    }
    for (String msg : aLogMsgs) {
        assertTrue(msg.contains("ERROR=(No Such Domain)"));
        assertTrue(msg.contains("CLIENT-IP=(55.88.77.66)"));
        assertTrue(msg.contains("WHO=(who-name=user,who-domain=user_domain,who-fullname=user_domain.user)"));
        break;
    }
}
Also used : DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) DefaultAuditLogger(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger) AuditLogger(com.yahoo.athenz.common.server.log.AuditLogger) DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) HttpServletRequest(javax.servlet.http.HttpServletRequest) ChangeLogStore(com.yahoo.athenz.zts.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with AuditLogMsgBuilder

use of com.yahoo.athenz.common.server.log.AuditLogMsgBuilder in project athenz by yahoo.

the class ZTSImplTest method testGetRoleTokenAddrLoopbackNoXFFAuditLog.

@Test
public void testGetRoleTokenAddrLoopbackNoXFFAuditLog() {
    HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(servletRequest.getRemoteAddr()).thenReturn("127.0.0.1");
    Mockito.when(servletRequest.isSecure()).thenReturn(true);
    final java.util.Set<String> aLogMsgs = new java.util.HashSet<String>();
    AuditLogger alogger = new AuditLogger() {

        public void log(String logMsg, String msgVersionTag) {
            aLogMsgs.add(logMsg);
        }

        public void log(AuditLogMsgBuilder msgBldr) {
            String msg = msgBldr.build();
            aLogMsgs.add(msg);
        }

        @Override
        public AuditLogMsgBuilder getMsgBuilder() {
            return new DefaultAuditLogMsgBuilder();
        }
    };
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    ZTSImpl.serverHostName = "localhost";
    ztsImpl.auditLogger = alogger;
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal, servletRequest);
    RoleToken roleToken = ztsImpl.getRoleToken(context, "coretech", null, Integer.valueOf(600), Integer.valueOf(1200), null);
    com.yahoo.athenz.auth.token.RoleToken token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
    assertNotNull(token);
    String unsignToken = token.getUnsignedToken();
    for (String msg : aLogMsgs) {
        assertTrue(msg.contains("SUCCESS ROLETOKEN=(" + unsignToken));
        assertTrue(msg.contains("i=127.0.0.1"));
        assertTrue(msg.contains("CLIENT-IP=(127.0.0.1)"));
        break;
    }
}
Also used : DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) DefaultAuditLogger(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger) AuditLogger(com.yahoo.athenz.common.server.log.AuditLogger) DefaultAuditLogMsgBuilder(com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder) AuditLogMsgBuilder(com.yahoo.athenz.common.server.log.AuditLogMsgBuilder) HttpServletRequest(javax.servlet.http.HttpServletRequest) ChangeLogStore(com.yahoo.athenz.zts.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)24 DefaultAuditLogMsgBuilder (com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder)14 Principal (com.yahoo.athenz.auth.Principal)13 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)12 AuditLogger (com.yahoo.athenz.common.server.log.AuditLogger)8 Test (org.testng.annotations.Test)8 HashSet (java.util.HashSet)7 DefaultAuditLogger (com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger)6 SignedDomain (com.yahoo.athenz.zms.SignedDomain)6 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)6 DataStore (com.yahoo.athenz.zts.store.DataStore)6 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)6 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 X509Certificate (java.security.cert.X509Certificate)4 Authority (com.yahoo.athenz.auth.Authority)3 CryptoException (com.yahoo.athenz.auth.util.CryptoException)3 X509CertRequest (com.yahoo.athenz.zts.cert.X509CertRequest)3 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2