PackageShareServlet.java
29.8 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.jcr.vault.packaging.JcrPackage
* com.day.jcr.vault.packaging.JcrPackageDefinition
* com.day.jcr.vault.packaging.JcrPackageManager
* com.day.jcr.vault.packaging.PackageId
* com.day.jcr.vault.packaging.Packaging
* com.day.jcr.vault.packaging.Version
* com.day.text.Text
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.servlet.Servlet
* javax.servlet.ServletException
* javax.servlet.ServletOutputStream
* javax.servlet.http.HttpServlet
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* org.apache.commons.lang3.StringEscapeUtils
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.apache.sling.commons.json.io.JSONWriter
* org.apache.sling.xss.XSSAPI
* org.osgi.service.http.HttpContext
* org.osgi.service.http.HttpService
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.crx.packaging.impl;
import com.day.crx.packaging.PackageInfo;
import com.day.crx.packaging.PackageShare;
import com.day.crx.packaging.PackageShareSession;
import com.day.crx.packaging.Proxy;
import com.day.crx.packaging.impl.RequestWrapper;
import com.day.crx.packmgr.impl.support.Blob;
import com.day.crx.packmgr.impl.support.RequestParameter;
import com.day.jcr.vault.packaging.JcrPackage;
import com.day.jcr.vault.packaging.JcrPackageDefinition;
import com.day.jcr.vault.packaging.JcrPackageManager;
import com.day.jcr.vault.packaging.PackageId;
import com.day.jcr.vault.packaging.Packaging;
import com.day.jcr.vault.packaging.Version;
import com.day.text.Text;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.Dictionary;
import java.util.List;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.io.JSONWriter;
import org.apache.sling.xss.XSSAPI;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1)
@Service(value={Servlet.class})
public class PackageShareServlet
extends HttpServlet {
private static final Logger log = LoggerFactory.getLogger(PackageShareServlet.class);
public static final String SERVLET_PATH = "/res";
public static final String REWRITE_PATH = "/index.html";
private static final String LOGIN_PATH = "/login.html";
public static final String ATTR_DATA = "com.day.crx.packaging.spool.data";
public static final String TEXT_HTML_UTF8 = "text/html; charset=utf-8";
public static final String APPLICATION_JSON_UTF8 = "application/json; charset=utf-8";
@Reference
private PackageShare psSvc;
@Reference
private Packaging packaging;
@Reference(target="(contextId=com.day.crx.packmgr.impl.AuthHttpContext)")
private HttpContext myContext;
@Reference
private HttpService httpService;
@Reference
private XSSAPI xssAPI;
@Activate
protected void activate() {
try {
this.httpService.registerServlet("/crx/packageshare", (Servlet)this, null, this.myContext);
}
catch (Exception e) {
log.error("Error while registering servlet", (Throwable)e);
}
}
@Deactivate
protected void deactivate() {
this.httpService.unregister("/crx/packageshare");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String suffix = req.getPathInfo();
if (suffix == null || suffix.length() == 0 || "/".equals(suffix)) {
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/index.html");
return;
}
String cmd = suffix;
String target = "";
int idx = suffix.indexOf(47, 1);
if (idx > 0) {
cmd = suffix.substring(0, idx);
target = suffix.substring(idx);
}
if ("/login.html".equals(cmd)) {
this.doLogin(req, resp, target);
return;
}
if ("/index.jsp".equals(cmd)) {
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/index.html");
return;
}
if ("/index.html".equals(cmd)) {
this.doRewrite(req, resp, target);
return;
}
if ("/logout.html".equals(cmd)) {
this.doLogout(req, resp, target);
return;
}
if ("/userinfo.json".equals(cmd)) {
this.doUserInfo(req, resp, target);
return;
}
PackageShareSession s = this.psSvc.getSession(req);
if (s == null) {
resp.sendError(404);
return;
}
if (target.length() == 0) {
resp.sendError(404);
return;
}
Proxy proxy = s.createProxy(true);
proxy.setContextPath(req.getContextPath());
String ifModifiedSince = req.getHeader("if-modified-since");
if (ifModifiedSince != null) {
proxy.addExtraHeader("if-modified-since", ifModifiedSince);
}
try {
int status = proxy.doGet(target);
switch (status) {
case 200: {
String contentEncoding;
String contentType = proxy.getContentType();
if (contentType != null) {
resp.setContentType(contentType);
}
if ((contentEncoding = proxy.getResponseHeaderValue("Content-Encoding")) != null) {
resp.setHeader("Content-Encoding", contentEncoding);
}
if (proxy.getLastModified() != null) {
resp.setHeader("Last-Modified", proxy.getLastModified());
}
if (contentType.startsWith("text/css")) {
proxy.spoolCss(resp.getWriter());
} else {
proxy.spool((OutputStream)resp.getOutputStream());
}
return;
}
case 301:
case 302: {
String location = proxy.getLocation(true, true);
if (location == null) {
log.info("Package Share request to {} responds redirect but invalid location.", (Object)target);
resp.sendError(404);
return;
}
resp.sendRedirect(location);
return;
}
case 304: {
log.info("Package Share request to {} responds {}", (Object)target, (Object)status);
resp.sendError(status);
return;
}
}
log.info("Package Share request to {} responds {}", (Object)target, (Object)status);
resp.sendError(404);
}
finally {
proxy.close();
}
}
private void doUserInfo(HttpServletRequest req, HttpServletResponse resp, String target) throws IOException {
try {
String psUser = req.getParameter("psuser");
String psPass = req.getParameter("pspass");
JSONObject info = new JSONObject();
JSONObject status = new JSONObject();
status.put("valid", false);
info.put("status", (Object)status);
PackageShareSession s = this.psSvc.getSession(req, resp);
String refresh = req.getParameter("refresh");
if ("true".equals(refresh)) {
s.logout();
}
if (s.isAnonymous()) {
try {
s = this.psSvc.login(this.getSession(req), req, resp, psUser, psPass);
if (s == null) {
status.put("msg", (Object)"Invalid User or Password");
}
}
catch (IOException e) {
status.put("msg", (Object)e.toString());
}
}
if (s != null) {
status.put("valid", !s.isAnonymous());
status.put("id", (Object)s.getId());
info.put("info", (Object)s.getSessionInfo());
}
String shareId = req.getParameter("shareId");
String shareSize = req.getParameter("shareSize");
if (shareId != null && shareId.length() > 0 && s != null && !s.isAnonymous()) {
Proxy p = s.createProxy(false);
p.addExtraParameter("packageId", shareId);
if (shareSize != null) {
p.addExtraParameter("packageSize", shareSize);
}
p.addExtraParameter("_charset_", "utf-8");
p.setFollowRedirects(true);
int stat = p.doGet("/content/packageshare.requestshare.html");
if (stat == 200) {
String data = p.fetch();
try {
JSONObject json = new JSONObject(data);
info.put("share", (Object)json);
}
catch (JSONException e) {
// empty catch block
}
}
}
resp.setContentType("application/json; charset=utf-8");
resp.getWriter().write(info.toString());
resp.flushBuffer();
}
catch (JSONException e) {
resp.sendError(500, e.toString());
}
}
private void doLogout(HttpServletRequest req, HttpServletResponse resp, String target) throws IOException {
String referer;
PackageShareSession s = this.psSvc.getSession(req);
if (s != null) {
s.logout();
}
if ((referer = req.getParameter("referer")) == null) {
referer = "/index.html" + target;
}
resp.sendRedirect(req.getContextPath() + req.getServletPath() + referer);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void doLogin(HttpServletRequest req, HttpServletResponse resp, String target) throws IOException {
String data;
String statusMsg;
PackageShareSession s = this.psSvc.getSession(req, resp);
String status = req.getParameter("status");
statusMsg = req.getParameter("msg");
if ("invalid".equals(status)) {
statusMsg = "Invalid user name or password.";
} else if ("error".equals(status)) {
statusMsg = StringEscapeUtils.escapeXml((String)statusMsg);
statusMsg = "Adobe Package Share server not available (" + statusMsg + ")";
} else {
statusMsg = " ";
}
Proxy proxy = s.createProxy(false);
proxy.setContextPath(req.getContextPath());
proxy.addExtraParameter("err", statusMsg);
target = "/content/packageshare/tools/login.html";
String value = req.getParameter("t");
if (value != null && value.startsWith("/")) {
target = value;
}
data = "";
try {
if (proxy.doGet(target) == 200) {
StringWriter w = new StringWriter();
proxy.rewrite(w);
data = w.toString();
}
}
catch (Exception e) {
statusMsg = "Adobe Package Share server not available";
if (e instanceof ConnectException) {
statusMsg = statusMsg + " (connection refused)";
} else if (e instanceof UnknownHostException) {
statusMsg = statusMsg + " (unknown host)";
}
log.error(statusMsg, (Throwable)e);
s.logout();
}
finally {
proxy.close();
}
this.sendLogin(req, resp, data, target, statusMsg);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Unable to fully structure code
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
* Lifted jumps to return sites
*/
private void doRewrite(HttpServletRequest req, HttpServletResponse resp, String target) throws IOException {
s = this.psSvc.getSession(req, resp);
if (s.isAnonymous()) {
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/login.html" + target);
return;
}
data = (String)req.getAttribute("com.day.cq.packaging.spool.data");
if (data == null) {
proxy = s.createProxy(false);
proxy.setContextPath(req.getContextPath());
proxy.addExtraParameters(req);
if (target.length() == 0) {
target = "/content/packageshare.html";
}
statusMsg = null;
try {
status = proxy.doGet(target);
switch (status) {
case 301:
case 302: {
location = proxy.getLocation(true, false);
if (location == null) {
statusMsg = "Invalid redirect.";
throw new Exception(statusMsg);
}
resp.sendRedirect(location);
return;
}
case 200: {
w = new StringWriter();
proxy.rewrite(w);
data = w.toString();
** break;
}
}
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/login.html");
return;
}
catch (Exception e) {
data = "Adobe Package Share server not available";
if (statusMsg != null) {
data = data + ": " + statusMsg;
}
PackageShareServlet.log.error(data, (Throwable)e);
}
finally {
proxy.close();
}
}
this.send(req, resp, data, target);
}
private void send(HttpServletRequest req, HttpServletResponse resp, String data, String target) throws IOException {
String ctxPath = req.getContextPath() + "/crx/packmgr";
resp.setContentType("text/html; charset=utf-8");
PrintWriter out = resp.getWriter();
out.print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\">\n<html>\n<head>\n <title>Adobe Digital Enterprise Platform | Package Share</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
out.printf("<link rel=\"stylesheet\" href=\"%s/commons/css/switcher.css\" type=\"text/css\"> \n", ctxPath);
out.printf("<link rel=\"stylesheet\" href=\"%s/css/basic.css\" type=\"text/css\"> \n", ctxPath);
out.printf("<link rel=\"stylesheet\" href=\"%s/css/cq-ui-appl.css\" type=\"text/css\"> \n", ctxPath);
out.printf("<script src=\"%s/js/PackageShareClient.js\" type=\"text/javascript\"></script>\n", ctxPath);
out.print("<script type=\"text/javascript\">\n");
out.printf(" var cqPackageShareClient = new PackageShareClient(\"%s\", \"%s\");\n", req.getContextPath() + "/crx", "/packageshare");
JcrPackageManager packMgr = this.packaging.getPackageManager(this.getSession(req));
try {
for (JcrPackage pack : packMgr.listPackages(null, true)) {
PackageId id = pack.getDefinition().getId();
boolean installed = pack.getDefinition().getLastUnpacked() != null;
long size = pack.getSize();
String sizeStr = PackageInfo.formatSize(size);
out.printf("cqPackageShareClient.onLocalPackage(\"%s\",\"%s\",\"%s\",\"%s\", %s, %d, \"%s\", %d);\n", new Object[]{id, id.getGroup(), id.getName(), id.getVersion(), String.valueOf(installed), size, sizeStr, pack.getDefinition().getBuildCount()});
}
}
catch (RepositoryException e) {
// empty catch block
}
out.print(" try {\n window.addEventListener(\"keydown\", cqPackageShareClient.onKeyDown, true);\n } catch (x) {\n // msie\n window.attachEvent(\"onkeydown\", cqPackageShareClient.onKeyDown);\n }\n </script>\n</head>\n<body class=\"cq-packageshare-ui-body\">\n");
this.writeSwitcher(req, out);
out.printf(" <div class=\"cq-packageshare-frame\">%s</div>\n", data);
out.printf(" <div class=\"cq-packageshare-console-frame\">\n <form name=\"console_form\" id=\"console_form\" action=\"%s/packageshare/console.html\" target=\"console_frame\" method=\"post\">\n <input type=\"hidden\" name=\"_charset_\" value=\"utf-8\">\n <input type=\"hidden\" name=\"cmd\" value=\"download\">\n <input type=\"hidden\" name=\"url\">\n <input type=\"hidden\" name=\"pid\">\n <input type=\"hidden\" name=\"path\">\n <input type=\"hidden\" name=\"size\">\n <input type=\"hidden\" name=\"group\">\n <input type=\"hidden\" name=\"name\">\n </form>\n <div id=\"cq-packagemgr-console\" onClick=\"PackageShareClient.toggleConsole(false);\" class=\"cq-packagemgr-console cq-packagemgr-console-hidden\"><div class=\"cq-packagemgr-console-title\">Package Share Console</div>\n <iframe class=\"cq-packagemgr-console-frame\" name=\"console_frame\" id=\"console_frame\" src=\"about:blank\"></iframe>\n </div>\n </div>\n <br>\n</body>\n</html>", req.getContextPath());
}
private void sendLogin(HttpServletRequest req, HttpServletResponse resp, String data, String target, String statusMsg) throws IOException {
String ctxPath = req.getContextPath() + "/crx/packmgr";
resp.setContentType("text/html; charset=utf-8");
PrintWriter out = resp.getWriter();
out.print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\">\n<html>\n<head>\n <title>Adobe Digital Enterprise Platform | Package Share</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
out.printf("<link rel=\"stylesheet\" href=\"%s/commons/css/switcher.css\" type=\"text/css\"> \n", ctxPath);
out.printf("<link rel=\"stylesheet\" href=\"%s/css/basic.css\" type=\"text/css\"> \n", ctxPath);
out.printf("<link rel=\"stylesheet\" href=\"%s/css/cq-ui-appl.css\" type=\"text/css\"> \n", ctxPath);
out.printf("<script src=\"%s/js/PackageShareClient.js\" type=\"text/javascript\"></script>\n", ctxPath);
out.print(" <script type=\"text/javascript\">\n");
out.printf(" var cqPackageShareClient = new PackageShareClient(\"%s\", \"%s\");\n", req.getContextPath() + "/crx", "/packageshare");
out.print(" </script></head>\n");
if (data != null && data.length() > 0) {
out.print("<body class=\"cq-packageshare-ui-body\">\n");
this.writeSwitcher(req, out);
out.printf("<div class=\"cq-packageshare-frame\">%s</div>\n", data);
} else {
out.print("<body class=\"cq-ui-body\">\n <h1 class=\"cq-packagemgr\">Adobe Package Share</h1>\n <p>\n The Package Share server login page is currently not accessible. Please\n enter your credentials here.\n </p>\n");
out.printf(" <form action=\"%s\" method=\"post\">\n", this.xssAPI.getValidHref(req.getContextPath() + req.getServletPath() + "/login.html" + target));
out.print(" <table class=\"form\">\n <tr>\n <td class=\"cq-packagemgr-login-error\"> </td>\n");
out.printf(" <td class=\"cq-packagemgr-login-error\">%s</td>\n", statusMsg);
out.print(" </tr>\n <tr>\n <td><label for=\"psuser\" >Username</label></td>\n <td><input type=\"text\" name=\"psuser\" id=\"psuser\"></td>\n </tr>\n <tr>\n <td><label for=\"pspass\">Password</label></td>\n <td><input type=\"password\" name=\"pspass\" id=\"pspass\"></td>\n </tr>\n <tr>\n <td></td>\n <td><button type=\"submit\">Login</button></td>\n </tr>\n </table>\n </form>");
}
out.print("</body></html>");
}
private void writeSwitcher(HttpServletRequest req, PrintWriter out) {
String lpPath = "";
String ctxPath = req.getContextPath();
out.print("<div class='crx-switcher crx-packageshare'>\n<a class='crx-home-link' title='Back Home' href='" + lpPath + "/'></a>\n" + "<div class='crx-switcher-icons-wrapper'>\n" + "<table class='crx-switcher-icons'>" + "<tr>" + "<td><a class='icon iconA' title='Develop' href='" + ctxPath + "/crx/de/'></a></td>" + "<td><a class='icon iconB' title='Package' href='" + ctxPath + "/crx/packmgr" + "/'></a></td>" + "<td><a class='icon iconC' title='Share' href='" + ctxPath + "/crx/packageshare" + "/'></a></td>" + "</tr>" + "</table>" + "</div>\n" + "</div>\n");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void doPost(HttpServletRequest oReq, HttpServletResponse resp) throws ServletException, IOException {
block8 : {
RequestWrapper req = new RequestWrapper(oReq);
try {
String suffix;
String cmd = suffix = req.getPathInfo();
String target = "";
int idx = suffix.indexOf(47, 1);
if (idx > 0) {
cmd = suffix.substring(1, idx);
target = suffix.substring(idx);
} else if (suffix.startsWith("/")) {
cmd = suffix.substring(1);
}
if ("upload".equals(cmd)) {
this.doPostUpload(req, resp);
break block8;
}
if (req.getParameter("psuser") != null && req.getParameter("pspass") != null) {
this.doPostLogin((HttpServletRequest)req, resp, target);
break block8;
}
this.doPostSpool((HttpServletRequest)req, resp, target);
}
finally {
req.discard();
}
}
}
private void doPostUpload(RequestWrapper req, HttpServletResponse resp) throws IOException {
String id;
PackageShareSession s = this.psSvc.getSession((HttpServletRequest)req);
if (s == null && (id = req.getParameter("daypsid")) != null) {
s = this.psSvc.getSession(id);
}
if (s == null) {
log.info("Upload requested with no session id");
resp.sendError(404);
return;
}
RequestParameter p = req.getRequestParameter("package");
if (p == null) {
log.info("Upload requested with no package");
resp.sendError(404);
return;
}
if (!p.isFileParameter()) {
log.info("Upload requested with no package file");
resp.sendError(404);
return;
}
p.getData().detach();
try {
resp.setStatus(200);
resp.setContentType("application/json; charset=utf-8");
JSONWriter w = new JSONWriter((Writer)resp.getWriter());
w.object();
w.key("path").value((Object)p.getData().getFile().getPath());
w.key("name").value((Object)p.getFilename());
w.endObject();
resp.flushBuffer();
}
catch (Exception e) {
log.error("Error while processing upload.", (Throwable)e);
resp.sendError(500);
}
}
private void doPostLogin(HttpServletRequest req, HttpServletResponse resp, String target) throws IOException {
resp.setContentType("text/html; charset=utf-8");
String psUser = req.getParameter("psuser");
String psPass = req.getParameter("pspass");
PackageShareSession s = null;
Session session = this.getSession(req);
String status = "ok";
String msg = "";
if (psUser != null && psPass != null && psUser.length() > 0 && psPass.length() > 0) {
try {
s = this.psSvc.login(session, req, resp, psUser, psPass);
if (s == null) {
status = "invalid";
msg = "Invalid User or Password";
}
}
catch (IOException e) {
status = "error";
msg = e.toString();
}
}
String referer = req.getContextPath() + req.getServletPath();
if (s != null) {
referer = referer + "/index.html" + target;
} else {
referer = referer + "/login.html" + target;
referer = referer + "?status=" + Text.escape((String)status);
referer = referer + "&msg=" + Text.escape((String)msg);
}
resp.sendRedirect(referer);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Unable to fully structure code
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
* Lifted jumps to return sites
*/
private void doPostSpool(HttpServletRequest req, HttpServletResponse resp, String target) throws IOException, ServletException {
s = this.psSvc.getSession(req);
if (s == null) {
resp.sendError(404);
return;
}
if (target.length() == 0) {
resp.sendError(404);
return;
}
proxy = s.createProxy(false);
proxy.setContextPath(req.getContextPath());
proxy.addExtraParameters(req);
data = null;
try {
status = proxy.doPost(target);
PackageShareServlet.log.info("Package Share request to {} responds {}", (Object)target, (Object)status);
switch (status) {
case 200: {
w = new StringWriter();
proxy.rewrite(w);
data = w.toString();
** break;
}
case 304: {
resp.sendError(status);
return;
}
case 301:
case 302: {
location = proxy.getLocation(true, false);
if (location == null) {
PackageShareServlet.log.info("Package Share request to {} responds redirect but invalid location.", (Object)target);
resp.sendError(404);
return;
}
resp.sendRedirect(location);
return;
}
}
resp.sendError(404);
return;
}
finally {
proxy.close();
}
lbl37: // 1 sources:
if (data != null) {
this.send(req, resp, data, "");
return;
}
PackageShareServlet.log.info("Package Share request to {} error.", (Object)target);
resp.sendError(500);
}
private Session getSession(HttpServletRequest req) {
ResourceResolver resolver = (ResourceResolver)req.getAttribute("org.apache.sling.auth.core.ResourceResolver");
return (Session)resolver.adaptTo(Session.class);
}
protected void bindPsSvc(PackageShare packageShare) {
this.psSvc = packageShare;
}
protected void unbindPsSvc(PackageShare packageShare) {
if (this.psSvc == packageShare) {
this.psSvc = null;
}
}
protected void bindPackaging(Packaging packaging) {
this.packaging = packaging;
}
protected void unbindPackaging(Packaging packaging) {
if (this.packaging == packaging) {
this.packaging = null;
}
}
protected void bindMyContext(HttpContext httpContext) {
this.myContext = httpContext;
}
protected void unbindMyContext(HttpContext httpContext) {
if (this.myContext == httpContext) {
this.myContext = null;
}
}
protected void bindHttpService(HttpService httpService) {
this.httpService = httpService;
}
protected void unbindHttpService(HttpService httpService) {
if (this.httpService == httpService) {
this.httpService = null;
}
}
protected void bindXssAPI(XSSAPI xSSAPI) {
this.xssAPI = xSSAPI;
}
protected void unbindXssAPI(XSSAPI xSSAPI) {
if (this.xssAPI == xSSAPI) {
this.xssAPI = null;
}
}
}