OutboxManagerImpl.java
7.31 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.annotation.Nonnull
* javax.annotation.Nullable
* javax.jcr.Node
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.commons.JcrUtils
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.replication.impl;
import com.day.cq.replication.AccessDeniedException;
import com.day.cq.replication.Outbox;
import com.day.cq.replication.OutboxManager;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.impl.OutboxImpl;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
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.commons.JcrUtils;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={OutboxManager.class})
public class OutboxManagerImpl
implements OutboxManager {
private static final Logger log = LoggerFactory.getLogger(OutboxManagerImpl.class);
public static final String DEFAULT_OUTBOX_PATH = "/var/replication/outbox";
public static final String OUTBOXES_PATH = "/var/replication/outboxes";
@Reference
protected SlingRepository repository;
@Nullable
@Override
public Outbox getOutbox(Session session, String name, boolean autoCreate) throws ReplicationException, AccessDeniedException {
if (name == null || "..".equals(name) || name.indexOf(47) > 0) {
throw new ReplicationException("Illegal outbox name: " + name);
}
return this.internalGetOutbox(session, "/var/replication/outboxes/" + name, autoCreate);
}
@Nonnull
@Override
public Outbox getDefaultOutbox(Session session) throws ReplicationException {
return this.internalGetOutbox(session, "/var/replication/outbox", true);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled force condition propagation
* Lifted jumps to return sites
*/
private Outbox internalGetOutbox(Session session, String path, boolean autoCreate) throws ReplicationException {
Outbox outbox;
Node outbox2 = null;
if (session.nodeExists(path)) {
outbox2 = session.getNode(path);
} else if (autoCreate) {
outbox2 = JcrUtils.getOrCreateByPath((String)path, (String)"sling:Folder", (String)"sling:OrderedFolder", (Session)session, (boolean)true);
}
if (outbox2 != null) return new OutboxImpl(outbox2);
Session systemSession = null;
try {
systemSession = this.repository.loginService("replicationService", null);
if (session.nodeExists(path)) {
throw new AccessDeniedException("Not allowed on " + path);
}
outbox = null;
if (systemSession == null) return outbox;
}
catch (Throwable var7_8) {
try {
if (systemSession == null) throw var7_8;
systemSession.logout();
throw var7_8;
}
catch (RepositoryException e) {
throw new ReplicationException("Error accessing outbox", (Exception)e);
}
}
systemSession.logout();
return outbox;
}
@Deprecated
@Override
public synchronized void put(InputStream in) throws ReplicationException {
Session systemSession = null;
try {
systemSession = this.repository.loginService("replicationService", null);
this.getDefaultOutbox(systemSession).put(null, in);
}
catch (RepositoryException e) {
throw new ReplicationException("Error while adding outbox element.", (Exception)e);
}
finally {
if (systemSession != null) {
systemSession.logout();
}
}
}
@Deprecated
@Override
public synchronized void put(ReplicationAction action) throws ReplicationException {
Session systemSession = null;
try {
systemSession = this.repository.loginService("replicationService", null);
this.getDefaultOutbox(systemSession).put(action, null);
}
catch (RepositoryException e) {
throw new ReplicationException("Error while adding outbox element.", (Exception)e);
}
finally {
if (systemSession != null) {
systemSession.logout();
}
}
}
@Deprecated
@Override
public synchronized void put(ReplicationAction action, InputStream in) throws ReplicationException {
Session systemSession = null;
try {
systemSession = this.repository.loginService("replicationService", null);
this.getDefaultOutbox(systemSession).put(action, in);
}
catch (RepositoryException e) {
throw new ReplicationException("Error while adding outbox element.", (Exception)e);
}
finally {
if (systemSession != null) {
systemSession.logout();
}
}
}
@Deprecated
@Override
public synchronized void fetch(Session session, Calendar time, OutputStream out) throws ReplicationException {
this.getDefaultOutbox(session).fetch(time, out);
}
@Deprecated
@Override
public boolean checkPermission(Session session) {
try {
this.getDefaultOutbox(session);
return true;
}
catch (ReplicationException e) {
log.error("Cannot access outbox. User [{}] doesn't have sufficient permissions on [{}]", (Object)session.getUserID(), (Object)"/var/replication/outbox");
return false;
}
}
@Activate
protected void activate(ComponentContext ctx) throws RepositoryException {
Session session = null;
try {
session = this.repository.loginService("replicationService", null);
JcrUtils.getOrCreateByPath((String)"/var/replication/outbox", (String)"sling:Folder", (String)"sling:Folder", (Session)session, (boolean)false);
JcrUtils.getOrCreateByPath((String)"/var/replication/outboxes", (String)"sling:Folder", (String)"sling:Folder", (Session)session, (boolean)false);
session.save();
}
finally {
if (session != null) {
session.logout();
}
}
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
}