Replace ATT headers
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / EventLogRecord.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\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
10  * *\r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * *\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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 \r
24 \r
25 package org.onap.dmaap.datarouter.provisioning.beans;\r
26 \r
27 import java.security.cert.X509Certificate;\r
28 \r
29 import javax.servlet.http.HttpServletRequest;\r
30 \r
31 import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
32 \r
33 /**\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-DMAAP-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
39  *\r
40  * @author Robert Eby\r
41  * @version $Id: EventLogRecord.java,v 1.1 2013/04/26 21:00:25 eby Exp $\r
42  */\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
51 \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
60 \r
61         // What is the request\r
62         this.method = request.getMethod();\r
63         this.servlet = request.getServletPath();\r
64 \r
65         // How was it dealt with\r
66         this.result = -1;\r
67         this.message = "";\r
68     }\r
69 \r
70     public void setResult(int result) {\r
71         this.result = result;\r
72     }\r
73 \r
74     public void setMessage(String message) {\r
75         this.message = message;\r
76     }\r
77 \r
78     @Override\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
83                 method, servlet,\r
84                 result, message\r
85         );\r
86     }\r
87 }\r