TempStorageProviderServlet.java
8.17 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.Session
* javax.servlet.Servlet
* javax.servlet.ServletException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.api.security.user.Authorizable
* org.apache.jackrabbit.api.security.user.UserManager
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.apache.sling.jcr.api.SlingRepository
* org.apache.sling.jcr.base.util.AccessControlUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.forms.common.servlet;
import com.adobe.forms.common.service.FormsCommonConfigurationService;
import com.adobe.forms.common.service.FormsException;
import com.adobe.forms.common.utils.FormsConstants;
import com.adobe.forms.common.utils.TempStorageUtils;
import com.day.cq.commons.jcr.JcrUtil;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.security.Principal;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.base.util.AccessControlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={Servlet.class})
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"fd/af/components/guideContainer", "xfaforms/profile"}), @Property(name="sling.servlet.methods", value={"POST"}), @Property(name="service.description", value={"Adaptive Form UUID ACL Creator"}), @Property(name="sling.servlet.selectors", value={"fd.tempstorageprovider"})})
public class TempStorageProviderServlet
extends SlingAllMethodsServlet {
private Logger logger = LoggerFactory.getLogger(TempStorageProviderServlet.class);
@Reference
private SlingRepository repository;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private FormsCommonConfigurationService formsCommonConfigurationService;
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String uuidPath = request.getParameter("uuidPath");
if (uuidPath != null && uuidPath.length() > 0) {
try {
boolean isAnonymous;
URI uuidURI = new URI(uuidPath);
String uuidNormalizedPath = uuidURI.normalize().getPath();
Session userSession = (Session)request.getResourceResolver().adaptTo(Session.class);
Session serviceSession = this.repository.loginService(null, null);
boolean bl = isAnonymous = request.getAuthType() == null;
if (!TempStorageUtils.isPreviewDisabled(this.formsCommonConfigurationService.getTempStorageConfig(), isAnonymous)) {
for (int i = 0; i < FormsConstants.FD_TEMP_PATHS.length; ++i) {
if (!uuidNormalizedPath.startsWith(FormsConstants.FD_TEMP_PATHS[i])) continue;
try {
String userFolder = uuidNormalizedPath.substring(uuidNormalizedPath.lastIndexOf(47) + 1);
Node userCreationTempNode = serviceSession.getNode(FormsConstants.FD_TEMP_PATHS[i]);
Node node = JcrUtil.createUniqueNode((Node)userCreationTempNode, (String)userFolder, (String)"sling:Folder", (Session)serviceSession);
node.setProperty("tmpNode", true);
if (isAnonymous) {
node.setProperty("guideComponentType", "anonymousTempStorage");
}
serviceSession.save();
UserManager userManager = AccessControlUtil.getUserManager((Session)userSession);
Authorizable authorizable = userManager.getAuthorizable(userSession.getUserID());
if (authorizable == null) continue;
if (!isAnonymous) {
AccessControlUtil.replaceAccessControlEntry((Session)serviceSession, (String)uuidNormalizedPath, (Principal)authorizable.getPrincipal(), (String[])new String[]{"{http://www.jcp.org/jcr/1.0}read", "{http://www.jcp.org/jcr/1.0}modifyProperties", "{http://www.jcp.org/jcr/1.0}addChildNodes", "{http://www.jcp.org/jcr/1.0}nodeTypeManagement"}, (String[])new String[0], (String[])new String[0], (String)null);
continue;
}
AccessControlUtil.replaceAccessControlEntry((Session)serviceSession, (String)uuidNormalizedPath, (Principal)authorizable.getPrincipal(), (String[])new String[]{"{http://www.jcp.org/jcr/1.0}read", "{http://www.jcp.org/jcr/1.0}addChildNodes", "{http://www.jcp.org/jcr/1.0}modifyProperties", "{http://www.jcp.org/jcr/1.0}nodeTypeManagement"}, (String[])new String[0], (String[])new String[0], (String)null);
}
catch (Exception e) {
String errorMsg = "There was an error in uploading attachments";
this.logger.error(errorMsg, (Throwable)e);
response.setStatus(500);
response.getWriter().write(errorMsg);
throw new FormsException(errorMsg, e);
}
finally {
if (serviceSession != null) {
if (serviceSession.hasPendingChanges()) {
serviceSession.save();
}
serviceSession.logout();
}
}
}
}
}
catch (Exception e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new FormsException(e);
}
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindFormsCommonConfigurationService(FormsCommonConfigurationService formsCommonConfigurationService) {
this.formsCommonConfigurationService = formsCommonConfigurationService;
}
protected void unbindFormsCommonConfigurationService(FormsCommonConfigurationService formsCommonConfigurationService) {
if (this.formsCommonConfigurationService == formsCommonConfigurationService) {
this.formsCommonConfigurationService = null;
}
}
}