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