SecureDataWebConsolePlugin.java
4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.ServletException
* javax.servlet.ServletRequest
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* org.apache.felix.webconsole.AbstractWebConsolePlugin
* org.apache.felix.webconsole.DefaultVariableResolver
* org.apache.felix.webconsole.VariableResolver
* org.apache.felix.webconsole.WebConsoleUtil
*/
package com.adobe.granite.crypto.internal;
import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.internal.CryptoSupportImpl;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.VariableResolver;
import org.apache.felix.webconsole.WebConsoleUtil;
public class SecureDataWebConsolePlugin
extends AbstractWebConsolePlugin {
private static final long serialVersionUID = 1;
private static final String PAR_PLAIN = "datum";
private static final String PAR_PROTECTED = "protected";
private final CryptoSupportImpl cryptoSupport;
SecureDataWebConsolePlugin(CryptoSupportImpl cryptoSupport) {
this.cryptoSupport = cryptoSupport;
}
public String getLabel() {
return "crypto";
}
public String getTitle() {
return "Crypto Support";
}
protected void renderContent(HttpServletRequest req, HttpServletResponse res) throws IOException {
PrintWriter pw = res.getWriter();
pw.println("<p class=\"statline ui-state-highlight\">Use this form to prepare protection of sensitive data in configurations</p>");
pw.println("<form method=\"POST\">");
pw.println("<table class=\"nicetable ui-widget\">");
pw.println("<tr>");
pw.println("<th colspan=\"3\" class=\"ui-widget-header\">Protect Plain Text Strings</td>");
pw.println("</tr>");
pw.println("<tr>");
pw.println("<td>Plain Text</td>");
pw.println("<td style=\"width:100%;\">");
pw.println("<input style=\"width:100%;\" type=\"password\" name=\"datum\" value=\"${datum}\">");
pw.println("</td>");
pw.println("<td><input type=\"submit\" value=\"Protect\"></td>");
pw.println("</tr>");
pw.println("<tr>");
pw.println("<td>Protected Text</td>");
pw.println("<td style=\"width:100%;\" colspan=\"2\">");
pw.println("<input style=\"width:100%;\" type=\"text\" value=\"${protected}\" readOnly>");
pw.println("</td>");
pw.println("</tr>");
pw.println("</table>");
pw.println("</form>");
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String datum = WebConsoleUtil.getParameter((HttpServletRequest)req, (String)"datum");
String protectedDatum = "";
if (datum != null) {
try {
protectedDatum = this.cryptoSupport.protect(datum);
}
catch (CryptoException ce) {
protectedDatum = "Cannot protect plain text: " + ce;
}
}
if (req.getRequestURI().endsWith(".json")) {
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().printf("{\"%s\": \"%s\"}", "protected", protectedDatum);
} else {
VariableResolver vr = WebConsoleUtil.getVariableResolver((ServletRequest)req);
if (vr instanceof DefaultVariableResolver) {
DefaultVariableResolver dvr = (DefaultVariableResolver)vr;
dvr.put((Object)"datum", (Object)datum);
dvr.put((Object)"protected", (Object)protectedDatum);
}
this.doGet(req, resp);
}
}
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
VariableResolver vr = WebConsoleUtil.getVariableResolver((ServletRequest)req);
if (vr instanceof DefaultVariableResolver) {
DefaultVariableResolver dvr = (DefaultVariableResolver)vr;
dvr.put((Object)"datum", (Object)"");
dvr.put((Object)"protected", (Object)"");
}
super.service(req, resp);
}
}