MobileAppsOAuthInfoProvider.java
4.08 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.crypto.CryptoException
* com.adobe.granite.crypto.CryptoSupport
* 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.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.platform.impl.provider;
import com.adobe.cq.mobile.platform.MobileAppsInfoProvider;
import com.adobe.cq.mobile.platform.MobileResource;
import com.adobe.cq.mobile.platform.MobileResourceType;
import com.adobe.granite.crypto.CryptoException;
import com.adobe.granite.crypto.CryptoSupport;
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.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={MobileAppsInfoProvider.class})
public class MobileAppsOAuthInfoProvider
implements MobileAppsInfoProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(MobileAppsOAuthInfoProvider.class);
public static final String NN_OAUTH = "oauth";
public static final String JSON_KEY_OAUTH = "oauth";
public static final String PN_OAUTH_CLIENT_ID = "clientId";
public static final String PN_OAUTH_CLIENT_SECRET = "clientSecret";
public static final String PN_OAUTH_CLIENT_REDIRECT = "redirectUri";
private static final String OAUTH_PATH = "jcr:content/oauth";
@Reference
private CryptoSupport cryptoSupport;
@Override
public void updateInfo(JSONWriter writer, MobileResource mobileResource) {
if (!mobileResource.isA(MobileResourceType.INSTANCE.getType())) {
return;
}
Resource resource = (Resource)mobileResource.adaptTo(Resource.class);
Resource oauth = resource.getChild("jcr:content/oauth");
if (oauth != null) {
ValueMap props = oauth.getValueMap();
String clientId = (String)props.get("clientId", (Object)"");
String clientSecret = (String)props.get("clientSecret", (Object)"");
String redirectURI = (String)props.get("redirectUri", (Object)"");
if (this.cryptoSupport.isProtected(clientSecret)) {
try {
clientSecret = this.cryptoSupport.unprotect(clientSecret);
}
catch (CryptoException e) {
LOGGER.error("Unable to decode the oauth client secret");
}
}
try {
if (StringUtils.isNotBlank((CharSequence)clientId) && StringUtils.isNotBlank((CharSequence)clientSecret) && StringUtils.isNotBlank((CharSequence)redirectURI)) {
writer.key("oauth");
writer.object();
writer.key("clientId").value((Object)clientId);
writer.key("clientSecret").value((Object)clientSecret);
writer.key("redirectURI").value((Object)redirectURI);
writer.endObject();
} else {
LOGGER.error("Unable to add oauth properties, missing mandatory values");
}
}
catch (JSONException e) {
LOGGER.error("Unable to provide AEM Mobile apps instance oauth data", (Throwable)e);
}
}
}
protected void bindCryptoSupport(CryptoSupport cryptoSupport) {
this.cryptoSupport = cryptoSupport;
}
protected void unbindCryptoSupport(CryptoSupport cryptoSupport) {
if (this.cryptoSupport == cryptoSupport) {
this.cryptoSupport = null;
}
}
}