7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * The contents of this file are subject to the terms of the Common Development and
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * Distribution License (the License). You may not use this file except in compliance with the
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * specific language governing permission and limitations under the License.
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * When distributing Covered Software, include this CDDL Header Notice in each file and include
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * Header, with the fields enclosed by brackets [] replaced by your own identifying
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * information: "Portions copyright [year] [name of copyright owner]".
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * Copyright 2015 ForgeRock AS.
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Joosteimport static org.forgerock.openam.utils.StringUtils.isEmpty;
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Joosteimport org.forgerock.audit.events.AccessAuditEventBuilder.ResponseStatus;
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * Attempts to parse an agent log message to extract useful information.
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * @since 13.0.0
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste WEB_AGENT("^user\\s+(\\S+)\\s*was\\s*(\\S+)\\s*access to\\s*(\\S+)$", 3, 1, 2),
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste JAVA_AGENT("^access to\\s*(\\S+)\\s+(\\S+)\\s*for user\\s*(\\S+)$", 1, 3, 2);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest Extractor(String pattern, int resourceIndex, int subjectIndex, int statusIndex) {
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest this.pattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * Given the log message, attempts to parse and extract known parts.
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * @param message
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * the log message
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest * @return the log extracts, null if parsing fails
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest for (Extractor extractor : Extractor.values()) {
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest Matcher matcher = extractor.newMatcher(message);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest private LogExtracts extract(Extractor extractor, Matcher matcher) {
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String resourceUrl = matcher.group(extractor.resourceIndex);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String subjectId = matcher.group(extractor.subjectIndex);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest String status = matcher.group(extractor.statusIndex);
7ad2fbd2d39159e30fdde02d014626b643758033Andrew Forrest return new LogExtracts(resourceUrl, subjectId, status);
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste private LogExtracts(String resourceUrl, String subjectId, String statusCode) {
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste // statusCode can be "allowed"
8acf5a373074b7db10b49aa33b35f8a541cabfd1Jaco Jooste // or "denied"