ProviderConfig.java
8.35 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.crypto.CryptoSupport
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.PropertyUnbounded
* org.apache.sling.commons.osgi.OsgiUtil
* org.osgi.service.cm.ConfigurationException
* org.scribe.builder.api.Api
* org.scribe.model.OAuthConfig
* org.scribe.model.SignatureType
* org.scribe.oauth.OAuthService
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.auth.oauth.impl.helper;
import com.adobe.granite.auth.oauth.Provider;
import com.adobe.granite.auth.oauth.impl.helper.OauthTokenManager;
import com.adobe.granite.crypto.CryptoSupport;
import java.io.OutputStream;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.osgi.service.cm.ConfigurationException;
import org.scribe.builder.api.Api;
import org.scribe.model.OAuthConfig;
import org.scribe.model.SignatureType;
import org.scribe.oauth.OAuthService;
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.provider", ds=0, metatype=1, configurationFactory=1)
@Properties(value={@Property(name="oauth.config.id"), @Property(name="oauth.client.id"), @Property(name="oauth.client.secret"), @Property(name="oauth.scope", unbounded=PropertyUnbounded.ARRAY), @Property(name="oauth.config.provider.id"), @Property(name="oauth.create.users", boolValue={0}), @Property(name="force.strict.username.matching", boolValue={0}), @Property(name="oauth.create.users.groups", unbounded=PropertyUnbounded.ARRAY), @Property(name="oauth.encode.userids", boolValue={0}), @Property(name="oauth.hash.userids", boolValue={0}), @Property(name="oauth.callBackUrl", value={""}), @Property(name="oauth.access.token.persist", boolValue={0}), @Property(name="oauth.access.token.persist.cookie", boolValue={0}), @Property(name="oauth.csrf.state.protection", boolValue={1}), @Property(name="oauth.redirect.request.params", boolValue={0})})
public class ProviderConfig {
private boolean autoCreateUsers;
private boolean forceStrictUsernameMatching;
private boolean encodeUserIds;
private boolean hashUserIds;
private String[] autoCreateUsersGroups;
private final String configId;
private final String providerId;
private String callBackUrl;
private boolean saveAccessToken;
private boolean saveAccessTokenCookie;
private boolean enableCSRFStateProtection;
private boolean persistRequestParamsCallbackUrl;
private OauthTokenManager tokenManager;
private final Logger log;
private final String clientId;
private final String clientSecret;
private final String pid;
private String scope;
private int loginTimeout;
private int cookieMaxAge;
public ProviderConfig(String pid, int loginTimeout, int cookieMaxAge, Dictionary<String, Object> config, CryptoSupport cryptoSupport) throws ConfigurationException {
String scope;
this.log = LoggerFactory.getLogger(this.getClass());
this.pid = pid;
this.cookieMaxAge = cookieMaxAge;
this.loginTimeout = loginTimeout;
String configId = OsgiUtil.toString((Object)config.get("oauth.config.id"), (String)"");
if (configId.length() == 0) {
throw new ConfigurationException("oauth.config.id", "Config ID must not be empty");
}
String clientId = OsgiUtil.toString((Object)config.get("oauth.client.id"), (String)"");
String clientSecret = OsgiUtil.toString((Object)config.get("oauth.client.secret"), (String)"");
this.providerId = OsgiUtil.toString((Object)config.get("oauth.config.provider.id"), (String)"");
if (this.providerId.length() == 0) {
throw new ConfigurationException("oauth.config.provider.id", "Provider ID must not be empty");
}
String[] scopes = OsgiUtil.toStringArray((Object)config.get("oauth.scope"));
if (scopes == null || scopes.length == 0) {
scope = null;
} else {
StringBuilder result = new StringBuilder();
String separator = "";
for (String string : scopes) {
result.append(separator);
result.append(string);
separator = ",";
}
scope = result.toString();
}
this.autoCreateUsers = OsgiUtil.toBoolean((Object)config.get("oauth.create.users"), (boolean)false);
this.encodeUserIds = OsgiUtil.toBoolean((Object)config.get("oauth.encode.userids"), (boolean)false);
this.hashUserIds = OsgiUtil.toBoolean((Object)config.get("oauth.hash.userids"), (boolean)false);
this.forceStrictUsernameMatching = OsgiUtil.toBoolean((Object)config.get("force.strict.username.matching"), (boolean)false);
this.autoCreateUsersGroups = OsgiUtil.toStringArray((Object)config.get("oauth.create.users.groups"), (String[])new String[0]);
this.saveAccessToken = OsgiUtil.toBoolean((Object)config.get("oauth.access.token.persist"), (boolean)false);
this.saveAccessTokenCookie = OsgiUtil.toBoolean((Object)config.get("oauth.access.token.persist.cookie"), (boolean)false);
this.enableCSRFStateProtection = OsgiUtil.toBoolean((Object)config.get("oauth.csrf.state.protection"), (boolean)true);
this.persistRequestParamsCallbackUrl = OsgiUtil.toBoolean((Object)config.get("oauth.redirect.request.params"), (boolean)false);
String configCallBackUrl = OsgiUtil.toString((Object)config.get("oauth.callBackUrl"), (String)"");
if (configCallBackUrl == null || configCallBackUrl.length() == 0) {
configCallBackUrl = null;
}
this.callBackUrl = configCallBackUrl;
this.configId = configId;
this.clientId = clientId;
this.clientSecret = clientSecret;
this.scope = scope;
this.tokenManager = new OauthTokenManager(cryptoSupport, loginTimeout, cookieMaxAge);
}
public String getConfigId() {
return this.configId;
}
public String getPid() {
return this.pid;
}
public String getProviderId() {
return this.providerId;
}
public String getClientId() {
return this.clientId;
}
public String getClientSecret() {
return this.clientSecret;
}
public String getCallBackUrl() {
return this.callBackUrl;
}
public boolean getAutoCreateUsers() {
return this.autoCreateUsers;
}
public boolean getEncodeUserIds() {
return this.encodeUserIds;
}
public boolean getHashUserIds() {
return this.hashUserIds;
}
public boolean getForceStrictUsernameMatching() {
return this.forceStrictUsernameMatching;
}
public String[] getAutoCreateUsersGroups() {
return this.autoCreateUsersGroups;
}
public boolean getSaveAccessToken() {
return this.saveAccessToken;
}
public boolean getSaveAccessTokenCookie() {
return this.saveAccessTokenCookie;
}
public boolean getEnableCSRFStateProtection() {
return this.enableCSRFStateProtection;
}
public boolean getPersistRequestParamsCallbackUrl() {
return this.persistRequestParamsCallbackUrl;
}
public void setPersistRequestParamsCallbackUrl(boolean persistRequestParamsCallbackUrl) {
this.persistRequestParamsCallbackUrl = persistRequestParamsCallbackUrl;
}
public OauthTokenManager getOAuthTokenManager() {
return this.tokenManager;
}
public int getCookieMaxAge() {
return this.cookieMaxAge;
}
public int getLoginTimeout() {
return this.loginTimeout;
}
public OAuthConfig getOAuthConfig(String callbackUrl) {
return new OAuthConfig(this.getClientId(), this.getClientSecret(), callbackUrl, SignatureType.QueryString, this.getScope(), null);
}
public OAuthService getOAuthService(Provider provider, String callbackUrl) {
return provider.getApi().createService(this.getOAuthConfig(callbackUrl));
}
public String getScope() {
return this.scope;
}
}