Code style cleanup for prov authz and beans
[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).\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     /**\r
53      * EventLogRecord constructor.\r
54      * @param request HTTP Request\r
55      */\r
56     public EventLogRecord(HttpServletRequest request) {\r
57         // Who is making the request\r
58         this.ipaddr = request.getRemoteAddr();\r
59         String str = request.getHeader(BaseServlet.BEHALF_HEADER);\r
60         this.behalfof = (str != null) ? str : "";\r
61         X509Certificate [] certs = (X509Certificate[]) request.getAttribute(BaseServlet.CERT_ATTRIBUTE);\r
62         this.clientSubject = (certs != null && certs.length > 0)\r
63                 ? certs[0].getSubjectX500Principal().getName() : "";\r
64 \r
65         // What is the request\r
66         this.method = request.getMethod();\r
67         this.servlet = request.getServletPath();\r
68 \r
69         // How was it dealt with\r
70         this.result = -1;\r
71         this.message = "";\r
72     }\r
73 \r
74     public void setResult(int result) {\r
75         this.result = result;\r
76     }\r
77 \r
78     public void setMessage(String message) {\r
79         this.message = message;\r
80     }\r
81 \r
82     @Override\r
83     public String toString() {\r
84         return String.format(\r
85                 "%s %s \"%s\" %s %s %d \"%s\"",\r
86                 ipaddr, behalfof, clientSubject,\r
87                 method, servlet,\r
88                 result, message\r
89         );\r
90     }\r
91 }\r