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