@@ -124,166 +124,174 @@ abstract class CheckServerPresenter constructor(
124
124
125
125
if (services.isNotEmpty()) {
126
126
state = OauthHelper .getState()
127
+ checkEnabledOauthAccounts(services, serverUrl)
128
+ checkEnabledCasAccounts(serverUrl)
129
+ checkEnabledCustomOauthAccounts(services, serverUrl)
130
+ checkEnabledSamlAccounts(services, serverUrl)
131
+ }
132
+ } catch (exception: RocketChatException ) {
133
+ Timber .e(exception)
134
+ }
135
+ }
127
136
128
- // OAuth accounts.
129
- if (settings.isFacebookAuthenticationEnabled()) {
130
- getServiceMap(services, SERVICE_NAME_FACEBOOK )?.let { serviceMap ->
131
- getOauthClientId(serviceMap)?.let { clientId ->
132
- facebookOauthUrl =
133
- OauthHelper .getFacebookOauthUrl(clientId, serverUrl, state)
134
- totalSocialAccountsEnabled++
135
- }
136
- }
137
+ private fun checkEnabledOauthAccounts (services : List <Map <String ,Any >>, serverUrl : String ) {
138
+
139
+ if (settings.isFacebookAuthenticationEnabled()) {
140
+ getServiceMap(services, SERVICE_NAME_FACEBOOK )?.let { serviceMap ->
141
+ getOauthClientId(serviceMap)?.let { clientId ->
142
+ facebookOauthUrl =
143
+ OauthHelper .getFacebookOauthUrl(clientId, serverUrl, state)
144
+ totalSocialAccountsEnabled++
137
145
}
146
+ }
147
+ }
138
148
139
- if (settings.isGithubAuthenticationEnabled()) {
140
- getServiceMap(services, SERVICE_NAME_GITHUB )?.let { serviceMap ->
141
- getOauthClientId(serviceMap)?.let { clientId ->
142
- githubOauthUrl =
143
- OauthHelper .getGithubOauthUrl(clientId, state)
144
- totalSocialAccountsEnabled++
145
- }
146
- }
149
+ if (settings.isGithubAuthenticationEnabled()) {
150
+ getServiceMap(services, SERVICE_NAME_GITHUB )?.let { serviceMap ->
151
+ getOauthClientId(serviceMap)?.let { clientId ->
152
+ githubOauthUrl =
153
+ OauthHelper .getGithubOauthUrl(clientId, state)
154
+ totalSocialAccountsEnabled++
147
155
}
156
+ }
157
+ }
148
158
149
- if (settings.isGoogleAuthenticationEnabled()) {
150
- getServiceMap(services, SERVICE_NAME_GOOGLE )?.let { serviceMap ->
151
- getOauthClientId(serviceMap)?.let { clientId ->
152
- googleOauthUrl =
153
- OauthHelper .getGoogleOauthUrl(clientId, serverUrl, state)
154
- totalSocialAccountsEnabled++
155
- }
156
- }
159
+ if (settings.isGoogleAuthenticationEnabled()) {
160
+ getServiceMap(services, SERVICE_NAME_GOOGLE )?.let { serviceMap ->
161
+ getOauthClientId(serviceMap)?.let { clientId ->
162
+ googleOauthUrl =
163
+ OauthHelper .getGoogleOauthUrl(clientId, serverUrl, state)
164
+ totalSocialAccountsEnabled++
157
165
}
166
+ }
167
+ }
168
+
169
+ if (settings.isLinkedinAuthenticationEnabled()) {
170
+ getServiceMap(services, SERVICE_NAME_LINKEDIN )?.let { serviceMap ->
171
+ getOauthClientId(serviceMap)?.let { clientId ->
172
+ linkedinOauthUrl =
173
+ OauthHelper .getLinkedinOauthUrl(clientId, serverUrl, state)
174
+ totalSocialAccountsEnabled++
175
+ }
176
+ }
177
+ }
158
178
159
- if (settings.isLinkedinAuthenticationEnabled()) {
160
- getServiceMap(services, SERVICE_NAME_LINKEDIN )?.let { serviceMap ->
161
- getOauthClientId(serviceMap)?.let { clientId ->
162
- linkedinOauthUrl =
163
- OauthHelper .getLinkedinOauthUrl(clientId, serverUrl, state)
164
- totalSocialAccountsEnabled++
165
- }
179
+ if (settings.isGitlabAuthenticationEnabled()) {
180
+ getServiceMap(services, SERVICE_NAME_GILAB )?.let { serviceMap ->
181
+ getOauthClientId(serviceMap)?.let { clientId ->
182
+ gitlabOauthUrl = if (settings.gitlabUrl() != null ) {
183
+ OauthHelper .getGitlabOauthUrl(
184
+ host = settings.gitlabUrl(),
185
+ clientId = clientId,
186
+ serverUrl = serverUrl,
187
+ state = state
188
+ )
189
+ } else {
190
+ OauthHelper .getGitlabOauthUrl(
191
+ clientId = clientId,
192
+ serverUrl = serverUrl,
193
+ state = state
194
+ )
166
195
}
196
+ totalSocialAccountsEnabled++
167
197
}
198
+ }
199
+ }
168
200
169
- if (settings.isGitlabAuthenticationEnabled ()) {
170
- getServiceMap(services, SERVICE_NAME_GILAB )?.let { serviceMap ->
171
- getOauthClientId(serviceMap)?.let { clientId ->
172
- gitlabOauthUrl = if (settings.gitlabUrl() != null ) {
173
- OauthHelper .getGitlabOauthUrl(
174
- host = settings.gitlabUrl(),
175
- clientId = clientId ,
176
- serverUrl = serverUrl ,
177
- state = state
201
+ if (settings.isWordpressAuthenticationEnabled ()) {
202
+ getServiceMap(services, SERVICE_NAME_WORDPRESS )?.let { serviceMap ->
203
+ getOauthClientId(serviceMap)?.let { clientId ->
204
+ wordpressOauthUrl =
205
+ if (settings.wordpressUrl().isNullOrEmpty()) {
206
+ OauthHelper .getWordpressComOauthUrl(
207
+ clientId,
208
+ serverUrl,
209
+ state
178
210
)
179
211
} else {
180
- OauthHelper .getGitlabOauthUrl(
181
- clientId = clientId,
182
- serverUrl = serverUrl,
183
- state = state
212
+ OauthHelper .getWordpressCustomOauthUrl(
213
+ getCustomOauthHost(serviceMap)
214
+ ? : " https://public-api.wordpress.com" ,
215
+ getCustomOauthAuthorizePath(serviceMap)
216
+ ? : " /oauth/authorize" ,
217
+ clientId,
218
+ serverUrl,
219
+ SERVICE_NAME_WORDPRESS ,
220
+ state,
221
+ getCustomOauthScope(serviceMap) ? : " openid"
184
222
)
185
223
}
186
- totalSocialAccountsEnabled++
187
- }
188
- }
224
+ totalSocialAccountsEnabled++
189
225
}
226
+ }
227
+ }
228
+ }
190
229
191
- if (settings.isWordpressAuthenticationEnabled()) {
192
- getServiceMap(services, SERVICE_NAME_WORDPRESS )?.let { serviceMap ->
193
- getOauthClientId(serviceMap)?.let { clientId ->
194
- wordpressOauthUrl =
195
- if (settings.wordpressUrl().isNullOrEmpty()) {
196
- OauthHelper .getWordpressComOauthUrl(
197
- clientId,
198
- serverUrl,
199
- state
200
- )
201
- } else {
202
- OauthHelper .getWordpressCustomOauthUrl(
203
- getCustomOauthHost(serviceMap)
204
- ? : " https://public-api.wordpress.com" ,
205
- getCustomOauthAuthorizePath(serviceMap)
206
- ? : " /oauth/authorize" ,
207
- clientId,
208
- serverUrl,
209
- SERVICE_NAME_WORDPRESS ,
210
- state,
211
- getCustomOauthScope(serviceMap) ? : " openid"
212
- )
213
- }
214
- totalSocialAccountsEnabled++
215
- }
216
- }
217
- }
230
+ private fun checkEnabledCasAccounts (serverUrl : String ) {
231
+ if (settings.isCasAuthenticationEnabled()) {
232
+ casToken = generateRandomString(17 )
233
+ casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
234
+ totalSocialAccountsEnabled++
235
+ }
236
+ }
218
237
219
- // CAS account.
220
- if (settings.isCasAuthenticationEnabled()) {
221
- casToken = generateRandomString(17 )
222
- casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
238
+ private fun checkEnabledCustomOauthAccounts (services : List <Map <String ,Any >>, serverUrl : String ) {
239
+ getCustomOauthServices(services).let {
240
+ for (serviceMap in it) {
241
+ customOauthServiceName = getCustomOauthServiceName(serviceMap)
242
+ val host = getCustomOauthHost(serviceMap)
243
+ val authorizePath = getCustomOauthAuthorizePath(serviceMap)
244
+ val clientId = getOauthClientId(serviceMap)
245
+ val scope = getCustomOauthScope(serviceMap)
246
+ val serviceNameTextColor =
247
+ getServiceNameColorForCustomOauthOrSaml(serviceMap)
248
+ val serviceButtonColor = getServiceButtonColor(serviceMap)
249
+ if (customOauthServiceName != null &&
250
+ host != null &&
251
+ authorizePath != null &&
252
+ clientId != null &&
253
+ scope != null &&
254
+ serviceNameTextColor != null &&
255
+ serviceButtonColor != null
256
+ ) {
257
+ customOauthUrl = OauthHelper .getCustomOauthUrl(
258
+ host,
259
+ authorizePath,
260
+ clientId,
261
+ serverUrl,
262
+ customOauthServiceName.toString(),
263
+ state,
264
+ scope
265
+ )
266
+ customOauthServiceNameTextColor = serviceNameTextColor
267
+ customOauthServiceButtonColor = serviceButtonColor
223
268
totalSocialAccountsEnabled++
224
269
}
270
+ }
271
+ }
272
+ }
225
273
226
- // Custom OAuth account.
227
- getCustomOauthServices(services).let {
228
- for (serviceMap in it) {
229
- customOauthServiceName = getCustomOauthServiceName(serviceMap)
230
- val host = getCustomOauthHost(serviceMap)
231
- val authorizePath = getCustomOauthAuthorizePath(serviceMap)
232
- val clientId = getOauthClientId(serviceMap)
233
- val scope = getCustomOauthScope(serviceMap)
234
- val serviceNameTextColor =
235
- getServiceNameColorForCustomOauthOrSaml(serviceMap)
236
- val serviceButtonColor = getServiceButtonColor(serviceMap)
237
- if (customOauthServiceName != null &&
238
- host != null &&
239
- authorizePath != null &&
240
- clientId != null &&
241
- scope != null &&
242
- serviceNameTextColor != null &&
243
- serviceButtonColor != null
244
- ) {
245
-
246
- customOauthUrl = OauthHelper .getCustomOauthUrl(
247
- host,
248
- authorizePath,
249
- clientId,
250
- serverUrl,
251
- customOauthServiceName.toString(),
252
- state,
253
- scope
254
- )
255
- customOauthServiceNameTextColor = serviceNameTextColor
256
- customOauthServiceButtonColor = serviceButtonColor
257
- totalSocialAccountsEnabled++
258
- }
259
- }
260
- }
261
-
262
- // SAML account.
263
- getSamlServices(services).let {
264
- samlToken = generateRandomString(17 )
265
- for (serviceMap in it) {
266
- val provider = getSamlProvider(serviceMap)
267
- samlServiceName = getSamlServiceName(serviceMap)
268
- val serviceNameTextColor =
269
- getServiceNameColorForCustomOauthOrSaml(serviceMap)
270
- val serviceButtonColor = getServiceButtonColor(serviceMap)
271
-
272
- if (provider != null &&
273
- samlServiceName != null &&
274
- serviceNameTextColor != null &&
275
- serviceButtonColor != null
276
- ) {
277
- samlUrl = serverUrl.samlUrl(provider, samlToken.toString())
278
- samlServiceNameTextColor = serviceNameTextColor
279
- samlServiceButtonColor = serviceButtonColor
280
- totalSocialAccountsEnabled++
281
- }
282
- }
274
+ private fun checkEnabledSamlAccounts (services : List <Map <String ,Any >>, serverUrl : String ) {
275
+ getSamlServices(services).let {
276
+ samlToken = generateRandomString(17 )
277
+ for (serviceMap in it) {
278
+ val provider = getSamlProvider(serviceMap)
279
+ samlServiceName = getSamlServiceName(serviceMap)
280
+ val serviceNameTextColor =
281
+ getServiceNameColorForCustomOauthOrSaml(serviceMap)
282
+ val serviceButtonColor = getServiceButtonColor(serviceMap)
283
+
284
+ if (provider != null &&
285
+ samlServiceName != null &&
286
+ serviceNameTextColor != null &&
287
+ serviceButtonColor != null
288
+ ) {
289
+ samlUrl = serverUrl.samlUrl(provider, samlToken.toString())
290
+ samlServiceNameTextColor = serviceNameTextColor
291
+ samlServiceButtonColor = serviceButtonColor
292
+ totalSocialAccountsEnabled++
283
293
}
284
294
}
285
- } catch (exception: RocketChatException ) {
286
- Timber .e(exception)
287
295
}
288
296
}
289
297
0 commit comments