OAuthManagerImpl.java
4.89 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.http.HttpServletRequest
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.jackrabbit.api.security.user.User
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.osgi.framework.BundleContext
* org.scribe.model.OAuthRequest
* org.scribe.model.Response
* org.scribe.model.Verb
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.auth.oauth.impl;
import com.adobe.granite.auth.oauth.OAuthManager;
import com.adobe.granite.auth.oauth.Provider;
import com.adobe.granite.auth.oauth.impl.helper.OAuthHelper;
import com.adobe.granite.auth.oauth.impl.helper.ProviderConfigManager;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.api.security.user.User;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.osgi.framework.BundleContext;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Verb;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(name="com.adobe.granite.auth.oauth.OAuthManager")
@Service(value={OAuthManager.class})
@Property(name="service.description", value={"Service used to manage OAuth interactions."})
public class OAuthManagerImpl
implements OAuthManager {
private final Logger log;
@Reference
private ProviderConfigManager providerConfigManager;
@Activate
private void activate(BundleContext context, Map<String, Object> config) {
this.log.info("activating OAuthManagerImpl");
}
@Deactivate
private void deactivate() {
this.log.debug("deactivating OAuthManagerImpl");
}
public OAuthManagerImpl() {
this.log = LoggerFactory.getLogger(this.getClass());
this.log.info("creating OAuthManagerImpl");
}
@Override
public Response getOAuthDataWithSharedToken(Resource encryptedTokenResource, String configId, OAuthRequest oauthRequest) throws IOException {
this.log.debug("getOAuthDataWithSharedToken: fetching data from url:{}", (Object)oauthRequest.getUrl());
OAuthHelper helper = this.providerConfigManager.getHelper(configId);
Provider provider = this.getProvider(configId);
return helper.getProtectedData(encryptedTokenResource, provider, oauthRequest);
}
@Override
public String getOAuthDataWithSharedToken(Resource encryptedTokenResource, String configId, String url) throws IOException {
Response response = this.getOAuthDataWithSharedToken(encryptedTokenResource, configId, new OAuthRequest(Verb.GET, url));
return response.getBody();
}
@Override
public Response getOAuthDataWithUserToken(SlingHttpServletRequest request, String configId, OAuthRequest oauthRequest) throws IOException {
this.log.debug("getOAuthDataWithUserToken: fetching data from url:{}", (Object)oauthRequest.getUrl());
OAuthHelper helper = this.providerConfigManager.getHelper(configId);
Provider provider = this.getProvider(configId);
User user = provider.getCurrentUser(request);
return helper.getProtectedData(user, provider, oauthRequest);
}
@Override
public String getOAuthDataWithUserToken(SlingHttpServletRequest request, String configId, String url) throws IOException {
Response response = this.getOAuthDataWithUserToken(request, configId, new OAuthRequest(Verb.GET, url));
return response.getBody();
}
@Override
public Provider getProvider(String configId) {
return this.providerConfigManager.getProvider(configId);
}
@Override
public String getAuthorizedId(HttpServletRequest request, String configId) {
OAuthHelper helper = this.providerConfigManager.getHelper(configId);
return helper.getAuthorizedId(request);
}
protected void bindProviderConfigManager(ProviderConfigManager providerConfigManager) {
this.providerConfigManager = providerConfigManager;
}
protected void unbindProviderConfigManager(ProviderConfigManager providerConfigManager) {
if (this.providerConfigManager == providerConfigManager) {
this.providerConfigManager = null;
}
}
}