GuideStoreContentSubmissionImpl.java
7.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserManagementService
* com.day.cq.commons.jcr.JcrUtil
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.Session
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.api.JackrabbitSession
* org.apache.jackrabbit.api.security.principal.PrincipalManager
* org.apache.jackrabbit.api.security.user.Authorizable
* org.apache.jackrabbit.api.security.user.UserManager
* org.apache.sling.jcr.api.SlingRepository
* org.apache.sling.jcr.base.util.AccessControlUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.service.impl;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideStoreContentSubmission;
import com.adobe.granite.security.user.UserManagementService;
import com.day.cq.commons.jcr.JcrUtil;
import java.security.Principal;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.Session;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.principal.PrincipalManager;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.base.util.AccessControlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, metatype=0, label="Adaptive Form Submission Service", description="Service to aid in submission using service-users")
@Service(value={GuideStoreContentSubmission.class})
public class GuideStoreContentSubmissionImpl
implements GuideStoreContentSubmission {
private Logger log = LoggerFactory.getLogger(GuideStoreContentSubmission.class);
@Reference
private SlingRepository repository;
@Reference
private UserManagementService userManagementService;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void submissionForStoreContentUsingServiceUser(String authType, Session userSession, String guideStartParameter, String path) throws GuideException {
block17 : {
Session serviceSession = null;
try {
serviceSession = this.repository.loginService(null, null);
if (userSession.hasPermission("/content/usergenerated/content/forms", "add_node") && userSession.hasPermission(path, "add_node") && StringUtils.isNotEmpty((CharSequence)authType)) {
Node parent;
Node node = JcrUtil.createPath((String)path, (String)"sling:Folder", (Session)serviceSession);
if (node != null) {
node.setProperty("afStoreContentTempPermission", path);
}
if (!(parent = node.getParent()).hasProperty("nodePath") && StringUtils.startsWith((CharSequence)guideStartParameter, (CharSequence)"/content/forms/af/")) {
parent.setProperty("nodePath", guideStartParameter);
}
serviceSession.save();
UserManager userManager = AccessControlUtil.getUserManager((Session)serviceSession);
Authorizable userSessionAuthorizable = userManager.getAuthorizable(userSession.getUserID());
Authorizable everyoneAuthorizable = userManager.getAuthorizable(((JackrabbitSession)serviceSession).getPrincipalManager().getEveryone());
AccessControlUtil.replaceAccessControlEntry((Session)serviceSession, (String)path, (Principal)everyoneAuthorizable.getPrincipal(), (String[])new String[0], (String[])new String[]{"{http://www.jcp.org/jcr/1.0}all"}, (String[])new String[0], (String)null);
if (userSessionAuthorizable != null) {
AccessControlUtil.replaceAccessControlEntry((Session)serviceSession, (String)path, (Principal)userSessionAuthorizable.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);
}
break block17;
}
this.log.error("User does not have add_node permissions or its an anonymous user on {}", (Object)path);
}
catch (Exception e) {
this.log.error("Failed to create path or set permissions.", (Throwable)e);
}
finally {
try {
if (serviceSession != null) {
if (serviceSession.hasPendingChanges()) {
serviceSession.save();
}
serviceSession.logout();
}
}
catch (Exception e) {
this.log.error("Failed to save the changes made in the repository", (Throwable)e);
}
}
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void unsetPrivilegesForStoreContent(Session userSession, String path) {
Session serviceSession = null;
try {
serviceSession = this.repository.loginService(null, null);
UserManager userManager = AccessControlUtil.getUserManager((Session)serviceSession);
Authorizable userSessionAuthorizable = userManager.getAuthorizable(userSession.getUserID());
if (userSessionAuthorizable != null) {
AccessControlUtil.replaceAccessControlEntry((Session)serviceSession, (String)path, (Principal)userSessionAuthorizable.getPrincipal(), (String[])new String[0], (String[])new String[0], (String[])new String[]{"{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)null);
}
}
catch (Exception e) {
this.log.error("Unable to remove privileges", (Throwable)e);
}
finally {
try {
if (serviceSession != null) {
if (serviceSession.hasPendingChanges()) {
serviceSession.save();
}
serviceSession.logout();
}
}
catch (Exception e) {
this.log.error("Failed to save the changes made in the repository", (Throwable)e);
}
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
protected void bindUserManagementService(UserManagementService userManagementService) {
this.userManagementService = userManagementService;
}
protected void unbindUserManagementService(UserManagementService userManagementService) {
if (this.userManagementService == userManagementService) {
this.userManagementService = null;
}
}
}