Improve Batches
[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.GregorianCalendar;
25 import java.util.List;
26
27 import org.onap.aaf.auth.batch.reports.Notify;
28 import org.onap.aaf.auth.env.AuthzTrans;
29 import org.onap.aaf.cadi.Access;
30 import org.onap.aaf.misc.env.util.Chrono;
31
32 public abstract class NotifyCredBody extends NotifyBody {
33
34         private final String explanation;
35         public NotifyCredBody(Access access, String name) throws IOException {
36                 super(access,"cred",name);
37                 
38                 // Default
39                 explanation = "The following Credentials that you are responsible for "
40                                 + "are expiring on the dates shown. "
41                                 + "Failure to act before the expiration date will cause your App's "
42                                 + "Authentications to fail."
43                                 + "<h3>Instructions for 'Password':</h3><ul>" 
44                                 + "<li><b><i>Click</i></b> on the Fully Qualified ID to ADD a new Password</li>"
45                                 + "<li><b>REMEMBER!</b> You are not finished until you <ol>"
46                                 + "<li><b>CHANGE <i>ALL</i></b> the configurations on <b><i>ALL</i></b> your processes!!</li>"
47                                 + "<li><b>BOUNCE</b> them</li></ol>"
48                                 + "<li>IF there is a WARNING, click the link for more information</li>"
49                                 + "</ul>";
50         }
51
52         @Override
53         public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
54                 println(sb,indent,explanation);
55                 println(sb,indent,"<table>");
56                 indent+=2;
57                 println(sb,indent,"<tr>");
58                 indent+=2;
59                 println(sb,indent,"<th>Fully Qualified ID</th>");
60                 println(sb,indent,"<th>Unique ID</th>");
61                 println(sb,indent,"<th>Type</th>");
62                 println(sb,indent,"<th>Expires</th>");
63                 println(sb,indent,"<th>Warnings</th>");
64                 indent-=2;
65                 println(sb,indent,"</tr>");
66                 String theid, type, info, expires, warnings;
67                 GregorianCalendar gc = new GregorianCalendar();
68                 for(List<String> row : rows.get(id)) {
69                         theid=row.get(1);
70                         switch(row.get(3)) {
71                                 case "1":
72                                 case "2":
73                                         type = "Password";
74                                         break;
75                                 case "200":
76                                         type = "x509 (Certificate)";
77                                         break;
78                                 default:
79                                         type = "Unknown, see AAF GUI";
80                                         break;
81                         }
82                         theid = "<a href=\""+n.guiURL+"/creddetail?ns="+row.get(2)+"\">"+theid+"</a>";
83                         gc.setTimeInMillis(Long.parseLong(row.get(5)));
84                         expires = Chrono.niceUTCStamp(gc);
85                         info = row.get(6);
86                         //TODO get Warnings 
87                         warnings = "";
88                         
89                         println(sb,indent,"<tr>");
90                         indent+=2;
91                         printCell(sb,indent,theid);
92                         printCell(sb,indent,info);
93                         printCell(sb,indent,type);
94                         printCell(sb,indent,expires);
95                         printCell(sb,indent,warnings);
96                         indent-=2;
97                         println(sb,indent,"</tr>");
98                 }
99                 indent-=2;
100                 println(sb,indent,"</table>");
101                 
102                 return true;
103         }
104
105         @Override
106         public String user(List<String> row) {
107                 if( (row != null) && row.size()>1) {
108                         return row.get(1);
109                 }
110                 return null;
111         }
112
113
114 }