MACTenantConfigurationImpl.java
4.33 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.security.user.UserManagementService
* com.day.cq.commons.inherit.InheritanceValueMap
* com.day.cq.wcm.webservicesupport.Configuration
* javax.jcr.RepositoryException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.dam.mac.sync.helper.impl;
import com.adobe.cq.dam.mac.sync.helper.impl.MACTenantConfiguration;
import com.adobe.cq.dam.mac.sync.helper.impl.util.OAuthUtil;
import com.adobe.granite.security.user.UserManagementService;
import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.wcm.webservicesupport.Configuration;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MACTenantConfigurationImpl
implements MACTenantConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(MACTenantConfigurationImpl.class);
private Configuration configuration;
private InheritanceValueMap properties;
private String userID = null;
private UserManagementService userManagementService;
public MACTenantConfigurationImpl(Configuration configuration, UserManagementService userManagementService) {
this.configuration = configuration;
this.properties = configuration.getProperties();
this.userManagementService = userManagementService;
}
@Override
public String getTenant() {
String tenantFromProp = this.readWrapper("tenant", String.class);
if (tenantFromProp != null) {
return tenantFromProp;
}
String tenantURL = this.getTenantURL();
if (tenantURL != null) {
String[] split;
if (tenantURL.startsWith("https://")) {
tenantURL = tenantURL.replaceFirst("https://", "");
}
if ((split = tenantURL.split("\\.")).length >= 2) {
return split[0];
}
}
return null;
}
@Override
public String getTenantURL() {
return this.readWrapper("tenantURL", String.class);
}
@Override
public String getDAMUser() {
if (this.userID == null) {
try {
this.userID = OAuthUtil.createReplicationUser(this.configuration.getResource().getResourceResolver(), this.getTenant(), this.userManagementService);
}
catch (RepositoryException e) {
throw new RuntimeException((Throwable)e);
}
}
return this.userID;
}
@Override
public String getOAuthClientId() {
return this.readWrapper("clientId", String.class);
}
@Override
public String getOAuthAudience() {
return this.readWrapper("audience", String.class);
}
@Override
public String[] getMACSyncPaths() {
String configVal = this.readWrapper("macSyncFolders", String.class);
if (configVal != null) {
String[] paths = configVal.split(",");
return paths;
}
return new String[0];
}
@Override
public String getPath() {
return this.configuration.getPath();
}
@Override
public Resource getResource() {
return this.configuration.getResource();
}
@Override
public boolean isSyncEnabled() {
return (Boolean)this.properties.get("syncEnabled", (Object)true);
}
@Override
public ValueMap getProperties() {
return this.properties;
}
@Override
public String getOAuthScope() {
return this.readWrapper("oauthScopes", String.class);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private <T> T readWrapper(String key, Class<T> type) {
Object result = null;
try {
result = this.properties.get(key, type);
return (T)result;
}
catch (Exception e) {
LOG.warn("Unable to read property " + key + " from configuration properties. Configuration resource was probably removed.");
}
finally {
return (T)result;
}
}
}