a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: LogRecWrite.java,v 1.6 2009/06/19 02:33:29 bigfatrat Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
e6c3a72a023407f5d1fface64356e1cc81f1af31Phill Cunnington * Portions Copyrighted 2011-2016 ForgeRock AS.
bb63e33b7207cd81af13f453ea310808288cc6efKohei Tamura * Portions Copyrighted 2013 Nomura Research Institute, Ltd
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.log.service;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bab1e6524fca64a55ecfc2503295092db8e0f48eCraig McDonnellimport static java.util.concurrent.TimeUnit.MILLISECONDS;
d84817c20fc73c3fd7832b2c30555c1ccff0d04dJaco Joosteimport static org.forgerock.openam.audit.AuditConstants.*;
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Joosteimport static org.forgerock.openam.utils.CollectionUtils.getFirstItem;
d84817c20fc73c3fd7832b2c30555c1ccff0d04dJaco Jooste
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.dpro.parser.ParseOutput;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.comm.share.Response;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOTokenManager;
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Joosteimport com.sun.identity.idm.IdRepoException;
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Joosteimport com.sun.identity.idm.IdUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.LogConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.LogRecord;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.Logger;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.s1is.LogSSOTokenDetails;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport com.sun.identity.log.service.AgentLogParser.LogExtracts;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.log.spi.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.monitoring.Agent;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.monitoring.MonitoringUtil;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.monitoring.SsoServerLoggingHdlrEntryImpl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.monitoring.SsoServerLoggingSvcImpl;
4ddc917bae3d889f687151804d52ff293bbded19Brian Baileyimport org.forgerock.audit.events.AuditEvent;
bab1e6524fca64a55ecfc2503295092db8e0f48eCraig McDonnellimport org.forgerock.openam.audit.AMAuditEventBuilderUtils;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport org.forgerock.openam.audit.AuditConstants;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport org.forgerock.openam.audit.AuditEventFactory;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport org.forgerock.openam.audit.AuditEventPublisher;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport org.forgerock.openam.audit.context.AuditRequestContext;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport org.forgerock.openam.utils.StringUtils;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Baileyimport java.net.URI;
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Baileyimport java.net.URISyntaxException;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.Collections;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.Hashtable;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.Iterator;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.List;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.Map;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.Set;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.Vector;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrestimport java.util.logging.Level;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class implements <code>ParseOutput</code> interface and <code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * LogOperation</code> interface. It is parsing request and process the request.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * log record. This class is registered with the SAX parser.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class LogRecWrite implements LogOperation, ParseOutput {
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste private static final String EVALUATION_REALM = "org.forgerock.openam.agents.config.policy.evaluation.realm";
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String _logname;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String _loggedBySid;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Vector _records = new Vector();
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Return result of the request processing in <code>Response</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return result of the request processing in <code>Response</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest public Response execute(AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Response res = new Response("OK");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SsoServerLoggingSvcImpl slsi = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SsoServerLoggingHdlrEntryImpl slei = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (MonitoringUtil.isRunning()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster slsi = Agent.getLoggingSvcMBean();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster slei = slsi.getHandler(SsoServerLoggingSvcImpl.REMOTE_HANDLER_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Logger logger = (Logger)Logger.getLogger(_logname);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (Debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.message("LogRecWrite: exec: logname = " + _logname);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford Level level =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Level.parse(((com.sun.identity.log.service.LogRecord)_records.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elementAt(0)).level);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = ((com.sun.identity.log.service.LogRecord)_records.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elementAt(0)).msg;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map logInfoMap = ((com.sun.identity.log.service.LogRecord)_records.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elementAt(0)).logInfoMap;
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford Object [] parameters =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ((com.sun.identity.log.service.LogRecord)_records.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster elementAt(0)).parameters;
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster msg = new String(com.sun.identity.shared.encode.Base64.decode(msg));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch(RuntimeException ex){
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford // if message is not base64 encoded just ignore &
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // write msg as it is.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (Debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.message("LogRecWrite: message is not base64 encoded");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LogRecord rec = new LogRecord(level, msg);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (logInfoMap != null) {
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String loginIDSid =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (String)logInfoMap.get(LogConstants.LOGIN_ID_SID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (loginIDSid != null && loginIDSid.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken loginIDToken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOTokenManager ssom = SSOTokenManager.getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loginIDToken = ssom.createSSOToken(loginIDSid);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (Debug.warningEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.warning("LogService::process(): SSOException", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rec.setLogInfoMap(logInfoMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (loginIDToken != null){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // here fill up logInfo into the newlr
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rec = LogSSOTokenDetails.logSSOTokenInfo(rec, loginIDToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford // now take one be one values from logInfoMap and overwrite
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // any populated value from sso token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set keySet = logInfoMap.keySet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator i = keySet.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String key = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String value = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (i.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster key = (String)i.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = (String)logInfoMap.get(key);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if(value != null && value.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (key.equalsIgnoreCase(LogConstants.DATA)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = new String(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster com.sun.identity.shared.encode.Base64.decode(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch(RuntimeException ex){
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford // if message is not base64 encoded just
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // ignore & write msg as it is.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (Debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.message(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "LogRecWrite: data is not "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "base64 encoded");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rec.addLogInfo(key, value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rec.setLogInfoMap(logInfoMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
bb63e33b7207cd81af13f453ea310808288cc6efKohei Tamura rec.addLogInfo(LogConstants.LOG_LEVEL, rec.getLevel().toString());
bb63e33b7207cd81af13f453ea310808288cc6efKohei Tamura
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rec.setParameters(parameters);
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken loggedByToken = null;
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste String realm = NO_REALM;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOTokenManager ssom = SSOTokenManager.getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster loggedByToken = ssom.createSSOToken(_loggedBySid);
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste Map<String, Set<String>> appAttributes = IdUtils.getIdentity(loggedByToken).getAttributes();
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste realm = getFirstItem(appAttributes.get(EVALUATION_REALM), NO_REALM);
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste } catch (IdRepoException | SSOException ssoe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Debug.error("LogRecWrite: exec:SSOException: ", ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (MonitoringUtil.isRunning()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster slei.incHandlerRequestCount(1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste auditAccessMessage(auditEventPublisher, auditEventFactory, rec, realm);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster logger.log(rec, loggedByToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Log file record write okay and return OK
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (MonitoringUtil.isRunning()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster slei.incHandlerSuccessCount(1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return res;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste private void auditAccessMessage(AuditEventPublisher auditEventPublisher, AuditEventFactory auditEventFactory,
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste LogRecord record, String realm) {
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest AgentLogParser logParser = new AgentLogParser();
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest LogExtracts logExtracts = logParser.tryParse(record.getMessage());
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest if (logExtracts == null) {
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest // A message type of no interest
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest return;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest }
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest @SuppressWarnings("unchecked")
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest Map<String, String> info = record.getLogInfoMap();
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String clientIp = info.get(LogConstants.IP_ADDR);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest if (StringUtils.isEmpty(clientIp)) {
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest clientIp = info.get(LogConstants.HOST_NAME);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest }
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String contextId = info.get(LogConstants.CONTEXT_ID);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String clientId = info.get(LogConstants.LOGIN_ID);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String resourceUrl = logExtracts.getResourceUrl();
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest int queryStringIndex = resourceUrl.indexOf('?');
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String queryString = queryStringIndex > -1 ? resourceUrl.substring(queryStringIndex) : "";
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String path = resourceUrl.replace(queryString, "");
bab1e6524fca64a55ecfc2503295092db8e0f48eCraig McDonnell Map<String, List<String>> queryParameters = AMAuditEventBuilderUtils.getQueryParametersAsMap(queryString);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
681162a025178d2ec56dd5b5cf44e928b0aff3c0Jaco Jooste AuditEvent auditEvent = auditEventFactory.accessEvent(realm)
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest .transactionId(AuditRequestContext.getTransactionIdValue())
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste .eventName(EventName.AM_ACCESS_OUTCOME)
1f2fcf34dac590b156bc682f7715dcd3be40f7b4Andrew Forrest .component(Component.POLICY_AGENT)
6b6359cabb99ffbe7c788604a533d5686c20e515Brian Bailey .userId(clientId)
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey .httpRequest(hasSecureScheme(resourceUrl), "UNKNOWN", path, queryParameters,
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey Collections.<String, List<String>>emptyMap())
d79b3a1008170c69ef720163254b78c998d55ee0Craig McDonnell .request("HTTP", "UNKNOWN")
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest .client(clientIp)
d79b3a1008170c69ef720163254b78c998d55ee0Craig McDonnell .trackingId(contextId)
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste .response(logExtracts.getStatus(), logExtracts.getStatusCode(), -1, MILLISECONDS)
4ddc917bae3d889f687151804d52ff293bbded19Brian Bailey .toEvent();
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest
4ddc917bae3d889f687151804d52ff293bbded19Brian Bailey auditEventPublisher.tryPublish(AuditConstants.ACCESS_TOPIC, auditEvent);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest }
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey private boolean hasSecureScheme(String resourceUrl) {
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey URI resourceURI;
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey try {
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey resourceURI = new URI(resourceUrl);
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey String scheme = resourceURI.getScheme();
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey if (StringUtils.isNotEmpty(scheme) && "https".equals(scheme.toLowerCase())) {
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey return true;
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey }
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey } catch (URISyntaxException e) {
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey //Fall through...
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey }
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey return false;
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey }
bcca58b64ccdda9e7b71f71945b7dffd6d2ca8d1Brian Bailey
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The method that implements the ParseOutput interface. This is called
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * by the SAX parser.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name name of request
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param elems vaector has parsing elements
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param atts parsing attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pcdata given data to be parsed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void process(String name, Vector elems, Hashtable atts,
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford String pcdata) {
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _logname = ((Log) elems.elementAt(0))._logname;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _loggedBySid = ((Log) elems.elementAt(0))._loggedBySid;
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 1; i < elems.size(); i++) {
dfa51161ad226f5998270e3becb25817774aa168Tony Bamford com.sun.identity.log.service.LogRecord lr =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (com.sun.identity.log.service.LogRecord)elems.elementAt(i);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster _records.addElement(lr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster} //end of LogRecWrite