SlingRepositoryImpl.java
8.47 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:
* com.day.crx.CRXModule
* com.day.crx.CRXRepository
* com.day.crx.License
* com.google.common.collect.ImmutableMap
* com.google.common.collect.ImmutableSet
* javax.jcr.Credentials
* javax.jcr.LoginException
* javax.jcr.NoSuchWorkspaceException
* javax.jcr.Repository
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.jackrabbit.api.JackrabbitRepository
* org.apache.jackrabbit.api.management.DataStoreGarbageCollector
* org.apache.jackrabbit.api.management.RepositoryManager
* org.apache.jackrabbit.oak.spi.security.ConfigurationParameters
* org.apache.jackrabbit.oak.spi.security.SecurityProvider
* org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl
* org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal
* org.apache.jackrabbit.oak.spi.security.principal.SystemUserPrincipal
* org.apache.jackrabbit.oak.spi.security.user.UserConfiguration
* org.apache.sling.jcr.api.SlingRepository
* org.apache.sling.jcr.base.AbstractSlingRepository2
* org.apache.sling.jcr.base.AbstractSlingRepositoryManager
* org.osgi.framework.Bundle
*/
package com.adobe.granite.repository.impl;
import com.adobe.granite.repository.impl.CRX3RepositoryImpl;
import com.adobe.granite.repository.impl.ServiceUsersConfigurationManager;
import com.adobe.granite.repository.impl.SlingRepositoryManager;
import com.day.crx.CRXModule;
import com.day.crx.CRXRepository;
import com.day.crx.License;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.io.File;
import java.security.Principal;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.security.auth.Subject;
import org.apache.jackrabbit.api.JackrabbitRepository;
import org.apache.jackrabbit.api.management.DataStoreGarbageCollector;
import org.apache.jackrabbit.api.management.RepositoryManager;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl;
import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
import org.apache.jackrabbit.oak.spi.security.principal.SystemUserPrincipal;
import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.base.AbstractSlingRepository2;
import org.apache.sling.jcr.base.AbstractSlingRepositoryManager;
import org.osgi.framework.Bundle;
public class SlingRepositoryImpl
extends AbstractSlingRepository2
implements CRXRepository,
JackrabbitRepository,
Repository,
SlingRepository,
RepositoryManager {
private final SlingRepositoryManager manager;
private final CRX3RepositoryImpl delegate;
private final ServiceUsersConfigurationManager serviceUsersConfigurationManager;
public SlingRepositoryImpl(SlingRepositoryManager manager, Bundle usingBundle, CRX3RepositoryImpl delegate, ServiceUsersConfigurationManager serviceUsersConfigurationManager) {
super((AbstractSlingRepositoryManager)manager, usingBundle);
this.manager = manager;
this.delegate = delegate;
this.serviceUsersConfigurationManager = serviceUsersConfigurationManager;
}
public void stop() {
throw new UnsupportedOperationException("RepositoryManager.stop()");
}
public DataStoreGarbageCollector createDataStoreGarbageCollector() throws RepositoryException {
if (this.delegate instanceof RepositoryManager) {
return ((RepositoryManager)this.delegate).createDataStoreGarbageCollector();
}
return null;
}
protected Session createAdministrativeSession(String workspace) throws RepositoryException {
Session adminSession;
SecurityProvider securityProvider = this.manager.getSecurityProvider();
final String adminId = (String)((UserConfiguration)securityProvider.getConfiguration(UserConfiguration.class)).getParameters().getConfigValue("adminId", (Object)"admin");
Set<> principals = Collections.singleton(new AdminPrincipal(){
public String getName() {
return adminId;
}
});
AuthInfoImpl authInfo = new AuthInfoImpl(adminId, Collections.emptyMap(), principals);
Subject subject = new Subject(true, principals, Collections.singleton(authInfo), Collections.emptySet());
try {
adminSession = (Session)Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>(){
@Override
public Session run() throws Exception {
ImmutableMap attrs = ImmutableMap.of((Object)"oak.refresh-interval", (Object)0, (Object)"oak.relaxed-locking", (Object)Boolean.TRUE);
return SlingRepositoryImpl.this.delegate.login(null, null, (Map<String, Object>)attrs);
}
}, null);
}
catch (PrivilegedActionException e) {
throw new RepositoryException("failed to retrieve service session.", (Throwable)e);
}
return adminSession;
}
protected Session createServiceSession(String serviceUserName, String workspace) throws RepositoryException {
if (!this.serviceUsersConfigurationManager.isServiceUserFastPathEnabled(serviceUserName)) {
return super.createServiceSession(serviceUserName, workspace);
}
return this.createServiceSessionFastPath(serviceUserName, workspace);
}
protected Session createServiceSessionFastPath(final String serviceUserName, String workspace) throws RepositoryException {
Session serviceSession;
ImmutableSet servicePrincipals = ImmutableSet.of((Object)new SystemUserPrincipal(){
public String getName() {
return serviceUserName;
}
});
AuthInfoImpl authInfo = new AuthInfoImpl(serviceUserName, Collections.emptyMap(), (Set)servicePrincipals);
Subject subject = new Subject(true, (Set<? extends Principal>)servicePrincipals, Collections.singleton(authInfo), Collections.emptySet());
try {
serviceSession = (Session)Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>(){
@Override
public Session run() throws Exception {
return SlingRepositoryImpl.this.delegate.login(null, null);
}
}, null);
}
catch (PrivilegedActionException e) {
throw new RepositoryException("failed to retrieve admin session.", (Throwable)e);
}
return serviceSession;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public Session impersonateFromService(String subServiceName, Credentials credentials, String workspaceName) throws LoginException, RepositoryException {
Session serviceSession = null;
try {
serviceSession = this.createAdministrativeSession(workspaceName);
Session session = serviceSession.impersonate(credentials);
return session;
}
finally {
if (serviceSession != null && serviceSession.isLive()) {
serviceSession.logout();
}
}
}
public File getHomeDir() {
return this.delegate.getHomeDir();
}
public License getLicense() {
return this.delegate.getLicense();
}
public CRXModule getModule(String moduleName) {
return this.delegate.getModule(moduleName);
}
public CRXModule[] getModules() {
return this.delegate.getModules();
}
public void installModule(Session session, CRXModule module) throws RepositoryException {
this.delegate.installModule(session, module);
}
public void uninstallModule(Session session, String moduleName) {
this.delegate.uninstallModule(session, moduleName);
}
public Session login(Credentials credentials, String s, Map<String, Object> stringObjectMap) throws LoginException, NoSuchWorkspaceException, RepositoryException {
return this.delegate.login(credentials, s, stringObjectMap);
}
public void shutdown() {
this.delegate.shutdown();
}
}