update link to upper-constraints.txt
[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 jakarta.servlet.http.HttpServletRequest;\r
28 import java.security.cert.X509Certificate;\r
29 import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
30 \r
31 /**\r
32  * This class is used to log provisioning server events.  Each event consists of a who\r
33  * (who made the provisioning request including the IP address, the X-DMAAP-DR-ON-BEHALF-OF\r
34  * header value, and the client certificate), a what (what request was made; the method\r
35  * and servlet involved), and a how (how the request was handled; the result code and\r
36  * message returned to the client).\r
37  *\r
38  * @author Robert Eby\r
39  * @version $Id: EventLogRecord.java,v 1.1 2013/04/26 21:00:25 eby Exp $\r
40  */\r
41 public class EventLogRecord {\r
42     private final String ipaddr;        // Who\r
43     private final String behalfof;\r
44     private final String clientSubject;\r
45     private final String method;        // What\r
46     private final String servlet;\r
47     private int result;                    // How\r
48     private String message;\r
49 \r
50     /**\r
51      * EventLogRecord constructor.\r
52      * @param request HTTP Request\r
53      */\r
54     public EventLogRecord(HttpServletRequest request) {\r
55         // Who is making the request\r
56         this.ipaddr = request.getRemoteAddr();\r
57         String str = request.getHeader(BaseServlet.BEHALF_HEADER);\r
58         this.behalfof = (str != null) ? str : "";\r
59         X509Certificate [] certs = (X509Certificate[]) request.getAttribute(BaseServlet.CERT_ATTRIBUTE);\r
60         this.clientSubject = (certs != null && certs.length > 0)\r
61                 ? certs[0].getSubjectX500Principal().getName() : "";\r
62 \r
63         // What is the request\r
64         this.method = request.getMethod();\r
65         this.servlet = request.getServletPath();\r
66 \r
67         // How was it dealt with\r
68         this.result = -1;\r
69         this.message = "";\r
70     }\r
71 \r
72     public void setResult(int result) {\r
73         this.result = result;\r
74     }\r
75 \r
76     public void setMessage(String message) {\r
77         this.message = message;\r
78     }\r
79 \r
80     @Override\r
81     public String toString() {\r
82         return String.format(\r
83                 "%s %s \"%s\" %s %s %d \"%s\"",\r
84                 ipaddr, behalfof, clientSubject,\r
85                 method, servlet,\r
86                 result, message\r
87         );\r
88     }\r
89 }\r