Add Cred Reporting Mailer
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / reports / bodies / NotifyCredBody.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21 package org.onap.aaf.auth.batch.reports.bodies;
22
23 import java.io.IOException;
24 import java.util.List;
25
26 import org.onap.aaf.auth.batch.reports.Notify;
27 import org.onap.aaf.auth.env.AuthzTrans;
28 import org.onap.aaf.cadi.Access;
29
30 public abstract class NotifyCredBody extends NotifyBody {
31
32         private final String explanation;
33         public NotifyCredBody(Access access, String name) throws IOException {
34                 super("cred",name);
35                 
36                 // Default
37                 explanation = "The following Credentials are expiring on the dates shown. "
38                                 + "Failure to act before the expiration date will cause your App's Authentications to fail.";
39         }
40
41         @Override
42         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
43                 println(sb,indent,explanation);
44                 println(sb,indent,"<br><br>");
45                 println(sb,indent,"<table>");
46                 indent+=2;
47                 println(sb,indent,"<tr>");
48                 indent+=2;
49                 println(sb,indent,"<th>Fully Qualified ID</th>");
50                 println(sb,indent,"<th>Type</th>");
51                 println(sb,indent,"<th>Details</th>");
52                 println(sb,indent,"<th>Expires</th>");
53                 println(sb,indent,"<th>Cred Detail Page</th>");
54                 indent-=2;
55                 println(sb,indent,"</tr>");
56                 String theid, type, info, gui, expires, notes;
57                 String p_theid=null, p_type=null, p_gui=null, p_expires=null;
58                 for(List<String> row : rows.get(id)) {
59                         theid=row.get(1);
60                         switch(row.get(3)) {
61                                 case "1":
62                                 case "2":
63                                         type = "Password";
64                                 case "200":
65                                         type = "x509 (Certificate)";
66                                         break;
67                                 default:
68                                         type = "Unknown, see AAF GUI";
69                                         break;
70                         }
71                         gui = "<a href=\""+n.guiURL+"/creddetail?ns="+row.get(2)+"\">"+row.get(2)+"</a>";
72                         expires = row.get(4);
73                         info = row.get(6);
74                         notes = row.get(8);
75                         if(notes!=null && !notes.isEmpty()) {
76                                 info += "<br>" + notes; 
77                         }
78                         
79                         println(sb,indent,"<tr>");
80                         indent+=2;
81                         printCell(sb,indent,theid,p_theid);
82                         printCell(sb,indent,type,p_type);
83                         printCell(sb,indent,info,null);
84                         printCell(sb,indent,expires,p_expires);
85                         printCell(sb,indent,gui,p_gui);
86                         indent-=2;
87                         println(sb,indent,"</tr>");
88                         p_theid=theid;
89                         p_type=type;
90                         p_gui=gui;
91                         p_expires=expires;
92                 }
93                 indent-=2;
94                 println(sb,indent,"</table>");
95                 
96                 return true;
97         }
98
99         @Override
100         public String user(List<String> row) {
101                 if( (row != null) && row.size()>1) {
102                         return row.get(1);
103                 }
104                 return null;
105         }
106
107
108 }