1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
25 package org.onap.dmaap.datarouter.provisioning.beans;
\r
27 import java.security.cert.X509Certificate;
\r
29 import javax.servlet.http.HttpServletRequest;
\r
31 import org.onap.dmaap.datarouter.provisioning.BaseServlet;
\r
34 * This class is used to log provisioning server events. Each event consists of a who
\r
35 * (who made the provisioning request including the IP address, the X-ATT-DR-ON-BEHALF-OF
\r
36 * header value, and the client certificate), a what (what request was made; the method
\r
37 * and servlet involved), and a how (how the request was handled; the result code and
\r
38 * message returned to the client). EventLogRecords are logged using log4j at the INFO level.
\r
40 * @author Robert Eby
\r
41 * @version $Id: EventLogRecord.java,v 1.1 2013/04/26 21:00:25 eby Exp $
\r
43 public class EventLogRecord {
\r
44 private final String ipaddr; // Who
\r
45 private final String behalfof;
\r
46 private final String clientSubject;
\r
47 private final String method; // What
\r
48 private final String servlet;
\r
49 private int result; // How
\r
50 private String message;
\r
52 public EventLogRecord(HttpServletRequest request) {
\r
53 // Who is making the request
\r
54 this.ipaddr = request.getRemoteAddr();
\r
55 String s = request.getHeader(BaseServlet.BEHALF_HEADER);
\r
56 this.behalfof = (s != null) ? s : "";
\r
57 X509Certificate certs[] = (X509Certificate[]) request.getAttribute(BaseServlet.CERT_ATTRIBUTE);
\r
58 this.clientSubject = (certs != null && certs.length > 0)
\r
59 ? certs[0].getSubjectX500Principal().getName() : "";
\r
61 // What is the request
\r
62 this.method = request.getMethod();
\r
63 this.servlet = request.getServletPath();
\r
65 // How was it dealt with
\r
70 public void setResult(int result) {
\r
71 this.result = result;
\r
74 public void setMessage(String message) {
\r
75 this.message = message;
\r
79 public String toString() {
\r
80 return String.format(
\r
81 "%s %s \"%s\" %s %s %d \"%s\"",
\r
82 ipaddr, behalfof, clientSubject,
\r