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