Improved multi Proxy DNSLocator based
[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  * Modifications Copyright (C) 2019 IBM.
8  * ===========================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END====================================================
21  *
22  */
23 package org.onap.aaf.auth.batch.reports.bodies;
24
25 import java.io.IOException;
26 import java.util.GregorianCalendar;
27 import java.util.List;
28
29 import org.onap.aaf.auth.batch.helpers.LastNotified;
30 import org.onap.aaf.auth.batch.reports.Notify;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.cadi.Access;
33 import org.onap.aaf.misc.env.util.Chrono;
34
35 public abstract class NotifyCredBody extends NotifyBody {
36
37     private final String explanation;
38     private final String instruction;
39      
40     public NotifyCredBody(Access access, String name) {
41         super(access,"cred",name);
42         
43         // Default
44         explanation = "The following Credentials that you are responsible for "
45                 + "are expiring on the dates shown. <br><br>"
46                 ;
47                 
48         instruction = "<br><h3>Instructions for 'Password':</h3><ul>" 
49                 + "<li><b><i>Click</i></b> on the Fully Qualified ID to ADD a new Password</li>"
50                 + "<li><b>REMEMBER!</b> You are not finished until you <ol>"
51                 + "<li><b>CHANGE <i>ALL</i></b> the configurations on <b><i>ALL</i></b> your processes!!</li>"
52                 + "<li><b>BOUNCE</b> them</li></ol>"
53                 + "<li>IF there is a WARNING, click the link for more information</li>"
54                 + "</ul>";
55     }
56     
57     /**
58      * Default Dynamic Text.  Override is expected
59      * @return
60      */
61     protected String dynamic() {
62         return "Failure to act before the expiration date will cause your App's Authentications to fail.";
63     }
64
65     @Override
66     public boolean body(AuthzTrans trans, StringBuilder sb, int indent, Notify n, String id) {
67         print(sb,indent,explanation);
68         print(sb,indent,dynamic());
69         println(sb,indent,instruction);
70         println(sb,indent,"<table>");
71         indent+=2;
72         println(sb,indent,"<tr>");
73         indent+=2;
74         println(sb,indent,"<th>Fully Qualified ID</th>");
75         println(sb,indent,"<th>Unique ID</th>");
76         println(sb,indent,"<th>Type</th>");
77         println(sb,indent,"<th>Expires</th>");
78         println(sb,indent,"<th>Warnings</th>");
79         indent-=2;
80         println(sb,indent,"</tr>");
81         String theid;
82         String type;
83         String info;
84         String expires;
85         String warnings;
86         GregorianCalendar gc = new GregorianCalendar();
87         for(List<String> row : rows.get(id)) {
88             theid=row.get(1);
89             switch(row.get(3)) {
90                 case "1":
91                 case "2":
92                     type = "Password";
93                     break;
94                 case "200":
95                     type = "x509 (Certificate)";
96                     break;
97                 default:
98                     type = "Unknown, see AAF GUI";
99                     break;
100             }
101             theid = "<a href=\""+n.guiURL+"/creddetail?ns="+row.get(2)+"\">"+theid+"</a>";
102             gc.setTimeInMillis(Long.parseLong(row.get(5)));
103             expires = Chrono.niceUTCStamp(gc);
104             info = row.get(6);
105             //TODO get Warnings 
106             warnings = "";
107             
108             println(sb,indent,"<tr>");
109             indent+=2;
110             printCell(sb,indent,theid);
111             printCell(sb,indent,info);
112             printCell(sb,indent,type);
113             printCell(sb,indent,expires);
114             printCell(sb,indent,warnings);
115             indent-=2;
116             println(sb,indent,"</tr>");
117         }
118         indent-=2;
119         println(sb,indent,"</table>");
120         
121         return true;
122     }
123     
124     @Override
125     public void record(AuthzTrans trans, StringBuilder query, String id, List<String> notified, LastNotified ln) {
126         for(List<String> row : rows.get(id)) {
127             for(String n : notified) {
128                 // Need to match LastNotified Key ... cred.id + '|' + inst.type + '|' + inst.tag;
129                 ln.update(query, n, row.get(0), row.get(1)+'|'+row.get(3)+'|'+row.get(6));
130             }
131         }
132     }
133
134     @Override
135     public String user(List<String> row) {
136         if( (row != null) && row.size()>1) {
137             return row.get(1);
138         }
139         return null;
140     }
141
142
143 }