Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit 18b506f

Browse files
authored
Merge pull request #1817 from RocketChat/fix/cas
[FIX][IMPROVEMENT] CAS button not showing and CAS button style
2 parents a9009ba + c0c1508 commit 18b506f

18 files changed

Lines changed: 139 additions & 66 deletions

File tree

app/src/main/java/chat/rocket/android/authentication/loginoptions/presentation/LoginOptionsView.kt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,26 @@ interface LoginOptionsView : LoadingView, MessageView {
113113

114114
// CAS account.
115115
/**
116-
* Shows the CAS button if the sign in/sign out via CAS protocol is enabled by the server
117-
* settings.
116+
* Adds a CAS button into accounts container.
118117
*
119-
* REMARK: We must set up the CAS button listener before showing it [setupCasButtonListener].
118+
* @param casUrl The CAS url.
119+
* @param casToken The CAS token
120+
* @param serviceName The SAML service name.
121+
* @param serviceNameColor The SAML service name color (just stylizing).
122+
* @param buttonColor The SAML button color (just stylizing).
120123
* @see [showAccountsView]
121124
*/
122-
fun enableLoginByCas()
123-
124-
/**
125-
* Setups the CAS button.
126-
*
127-
* @param casUrl The CAS URL to authenticate with.
128-
* @param casToken The requested token to be sent to the CAS server.
129-
*/
130-
fun setupCasButtonListener(casUrl: String, casToken: String)
125+
fun addCasButton(
126+
caslUrl: String,
127+
casToken: String,
128+
serviceName: String,
129+
serviceNameColor: Int,
130+
buttonColor: Int
131+
)
131132

132133
// Custom OAuth account.
133134
/**
134-
* Adds a custom OAuth button in the accounts container.
135+
* Adds a custom OAuth button into accounts container.
135136
*
136137
* @customOauthUrl The custom OAuth url.
137138
* @state A random string generated by the app, which you'll verify later
@@ -151,12 +152,13 @@ interface LoginOptionsView : LoadingView, MessageView {
151152

152153
// SAML account.
153154
/**
154-
* Adds a SAML button in the accounts container.
155+
* Adds a SAML button into accounts container.
155156
*
156-
* @samlUrl The SAML url.
157-
* @serviceName The SAML service name.
158-
* @serviceNameColor The SAML service name color (just stylizing).
159-
* @buttonColor The SAML button color (just stylizing).
157+
* @param samlUrl The SAML url.
158+
* @param samlToken The SAML token.
159+
* @param serviceName The SAML service name.
160+
* @param serviceNameColor The SAML service name color (just stylizing).
161+
* @param buttonColor The SAML button color (just stylizing).
160162
* @see [showAccountsView]
161163
*/
162164
fun addSamlButton(

app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ private const val GITLAB_OAUTH_URL = "gitlab_oauth_url"
4040
private const val WORDPRESS_OAUTH_URL = "wordpress_oauth_url"
4141
private const val CAS_LOGIN_URL = "cas_login_url"
4242
private const val CAS_TOKEN = "cas_token"
43+
private const val CAS_SERVICE_NAME = "cas_service_name"
44+
private const val CAS_SERVICE_NAME_TEXT_COLOR = "cas_service_name_text_color"
45+
private const val CAS_SERVICE_BUTTON_COLOR = "cas_service_button_color"
4346
private const val CUSTOM_OAUTH_URL = "custom_oauth_url"
4447
private const val CUSTOM_OAUTH_SERVICE_NAME = "custom_oauth_service_name"
4548
private const val CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR = "custom_oauth_service_name_text_color"
@@ -69,6 +72,9 @@ fun newInstance(
6972
wordpressOauthUrl: String? = null,
7073
casLoginUrl: String? = null,
7174
casToken: String? = null,
75+
casServiceName: String? = null,
76+
casServiceNameTextColor: Int = 0,
77+
casServiceButtonColor: Int = 0,
7278
customOauthUrl: String? = null,
7379
customOauthServiceName: String? = null,
7480
customOauthServiceNameTextColor: Int = 0,
@@ -95,6 +101,9 @@ fun newInstance(
95101
putString(WORDPRESS_OAUTH_URL, wordpressOauthUrl)
96102
putString(CAS_LOGIN_URL, casLoginUrl)
97103
putString(CAS_TOKEN, casToken)
104+
putString(CAS_SERVICE_NAME, casServiceName)
105+
putInt(CAS_SERVICE_NAME_TEXT_COLOR, casServiceNameTextColor)
106+
putInt(CAS_SERVICE_BUTTON_COLOR, casServiceButtonColor)
98107
putString(CUSTOM_OAUTH_URL, customOauthUrl)
99108
putString(CUSTOM_OAUTH_SERVICE_NAME, customOauthServiceName)
100109
putInt(CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR, customOauthServiceNameTextColor)
@@ -127,6 +136,9 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
127136
private var wordpressOauthUrl: String? = null
128137
private var casLoginUrl: String? = null
129138
private var casToken: String? = null
139+
private var casServiceName: String? = null
140+
private var casServiceNameTextColor: Int = 0
141+
private var casServiceButtonColor: Int = 0
130142
private var customOauthUrl: String? = null
131143
private var customOauthServiceName: String? = null
132144
private var customOauthServiceTextColor: Int = 0
@@ -157,6 +169,9 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
157169
wordpressOauthUrl = bundle.getString(WORDPRESS_OAUTH_URL)
158170
casLoginUrl = bundle.getString(CAS_LOGIN_URL)
159171
casToken = bundle.getString(CAS_TOKEN)
172+
casServiceName = bundle.getString(CAS_SERVICE_NAME)
173+
casServiceNameTextColor = bundle.getInt(CAS_SERVICE_NAME_TEXT_COLOR)
174+
casServiceButtonColor = bundle.getInt(CAS_SERVICE_BUTTON_COLOR)
160175
customOauthUrl = bundle.getString(CUSTOM_OAUTH_URL)
161176
customOauthServiceName = bundle.getString(CUSTOM_OAUTH_SERVICE_NAME)
162177
customOauthServiceTextColor = bundle.getInt(CUSTOM_OAUTH_SERVICE_NAME_TEXT_COLOR)
@@ -200,6 +215,7 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
200215
setupCas()
201216
setupCustomOauth()
202217
setupSaml()
218+
setupAccountsView()
203219
setupLoginWithEmailView()
204220
setupCreateNewAccountView()
205221
}
@@ -235,19 +251,17 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
235251
setupWordpressButtonListener(wordpressOauthUrl.toString(), state.toString())
236252
enableLoginByWordpress()
237253
}
238-
239-
if (totalSocialAccountsEnabled > 0) {
240-
showAccountsView()
241-
if (totalSocialAccountsEnabled > 3) {
242-
setupExpandAccountsView()
243-
}
244-
}
245254
}
246255

247256
private fun setupCas() {
248-
if (casLoginUrl != null && casToken != null) {
249-
setupCasButtonListener(casLoginUrl.toString(), casToken.toString())
250-
enableLoginByCas()
257+
if (casLoginUrl != null && casToken != null && casServiceName != null) {
258+
addCasButton(
259+
casLoginUrl.toString(),
260+
casToken.toString(),
261+
casServiceName.toString(),
262+
casServiceNameTextColor,
263+
casServiceButtonColor
264+
)
251265
}
252266
}
253267

@@ -275,6 +289,15 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
275289
}
276290
}
277291

292+
private fun setupAccountsView() {
293+
if (totalSocialAccountsEnabled > 0) {
294+
showAccountsView()
295+
if (totalSocialAccountsEnabled > 3) {
296+
setupExpandAccountsView()
297+
}
298+
}
299+
}
300+
278301
private fun setupLoginWithEmailView() {
279302
if (isLoginFormEnabled) {
280303
showLoginWithEmailButton()
@@ -319,10 +342,17 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
319342
setupButtonListener(button_wordpress, wordpressUrl, state, REQUEST_CODE_FOR_OAUTH)
320343

321344
// CAS service account.
322-
override fun enableLoginByCas() = enableAccountButton(button_cas)
323-
324-
override fun setupCasButtonListener(casUrl: String, casToken: String) =
325-
setupButtonListener(button_cas, casUrl, casToken, REQUEST_CODE_FOR_CAS)
345+
override fun addCasButton(
346+
caslUrl: String,
347+
casToken: String,
348+
serviceName: String,
349+
serviceNameColor: Int,
350+
buttonColor: Int
351+
) {
352+
val button = getCustomServiceButton(serviceName, serviceNameColor, buttonColor)
353+
setupButtonListener(button, caslUrl, casToken, REQUEST_CODE_FOR_CAS)
354+
accounts_container.addView(button)
355+
}
326356

327357
// Custom OAuth account.
328358
override fun addCustomOauthButton(

app/src/main/java/chat/rocket/android/authentication/onboarding/presentation/OnBoardingPresenter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class OnBoardingPresenter @Inject constructor(
4343
wordpressOauthUrl,
4444
casLoginUrl,
4545
casToken,
46+
casServiceName,
47+
casServiceNameTextColor,
48+
casServiceButtonColor,
4649
customOauthUrl,
4750
customOauthServiceName,
4851
customOauthServiceNameTextColor,
@@ -73,9 +76,8 @@ class OnBoardingPresenter @Inject constructor(
7376
view.showLoading()
7477
try {
7578
withContext(DefaultDispatcher) {
76-
refreshSettingsInteractor.refresh(serverUrl)
77-
7879
setupConnectionInfo(serverUrl)
80+
refreshSettingsInteractor.refresh(serverUrl)
7981

8082
// preparing next fragment before showing it
8183
checkEnabledAccounts(serverUrl)

app/src/main/java/chat/rocket/android/authentication/presentation/AuthenticationNavigator.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
3030
wordpressOauthUrl: String? = null,
3131
casLoginUrl: String? = null,
3232
casToken: String? = null,
33+
casServiceName: String? = null,
34+
casServiceNameTextColor: Int = 0,
35+
casServiceButtonColor: Int = 0,
3336
customOauthUrl: String? = null,
3437
customOauthServiceName: String? = null,
3538
customOauthServiceNameTextColor: Int = 0,
@@ -59,6 +62,9 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
5962
wordpressOauthUrl,
6063
casLoginUrl,
6164
casToken,
65+
casServiceName,
66+
casServiceNameTextColor,
67+
casServiceButtonColor,
6268
customOauthUrl,
6369
customOauthServiceName,
6470
customOauthServiceNameTextColor,

app/src/main/java/chat/rocket/android/authentication/server/presentation/ServerPresenter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class ServerPresenter @Inject constructor(
5353
wordpressOauthUrl,
5454
casLoginUrl,
5555
casToken,
56+
casServiceName,
57+
casServiceNameTextColor,
58+
casServiceButtonColor,
5659
customOauthUrl,
5760
customOauthServiceName,
5861
customOauthServiceNameTextColor,
@@ -92,8 +95,6 @@ class ServerPresenter @Inject constructor(
9295
withContext(DefaultDispatcher) {
9396
refreshSettingsInteractor.refresh(serverUrl)
9497

95-
setupConnectionInfo(serverUrl)
96-
9798
// preparing next fragment before showing it
9899
checkEnabledAccounts(serverUrl)
99100
checkIfLoginFormIsEnabled()

app/src/main/java/chat/rocket/android/helper/MessageParser.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import android.text.style.ReplacementSpan
1313
import android.view.View
1414
import androidx.core.content.res.ResourcesCompat
1515
import chat.rocket.android.R
16-
import androidx.core.util.PatternsCompat
1716
import chat.rocket.android.chatroom.ui.StrikethroughDelimiterProcessor
1817
import chat.rocket.android.emoji.EmojiParser
1918
import chat.rocket.android.emoji.EmojiRepository

app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ abstract class CheckServerPresenter constructor(
6161
internal var wordpressOauthUrl: String? = null
6262
internal var casLoginUrl: String? = null
6363
internal var casToken: String? = null
64+
internal var casServiceName: String? = null
65+
internal var casServiceNameTextColor: Int = 0
66+
internal var casServiceButtonColor: Int = 0
6467
internal var customOauthUrl: String? = null
6568
internal var customOauthServiceName: String? = null
6669
internal var customOauthServiceNameTextColor: Int = 0
@@ -79,6 +82,31 @@ abstract class CheckServerPresenter constructor(
7982
settings = it
8083
}
8184
client = factory.create(serverUrl)
85+
86+
state = ""
87+
facebookOauthUrl = null
88+
githubOauthUrl = null
89+
googleOauthUrl = null
90+
linkedinOauthUrl = null
91+
gitlabOauthUrl = null
92+
wordpressOauthUrl = null
93+
casLoginUrl = null
94+
casToken = null
95+
casServiceName = null
96+
casServiceNameTextColor = 0
97+
casServiceButtonColor = 0
98+
customOauthUrl = null
99+
customOauthServiceName = null
100+
customOauthServiceNameTextColor = 0
101+
customOauthServiceButtonColor= 0
102+
samlUrl = null
103+
samlToken = null
104+
samlServiceName = null
105+
samlServiceNameTextColor = 0
106+
samlServiceButtonColor = 0
107+
totalSocialAccountsEnabled = 0
108+
isLoginFormEnabled = false
109+
isNewAccountCreationEnabled = false
82110
}
83111

84112
internal fun checkServerInfo(serverUrl: String): Job {
@@ -125,7 +153,7 @@ abstract class CheckServerPresenter constructor(
125153
if (services.isNotEmpty()) {
126154
state = OauthHelper.getState()
127155
checkEnabledOauthAccounts(services, serverUrl)
128-
checkEnabledCasAccounts(serverUrl)
156+
checkEnabledCasAccounts(services, serverUrl)
129157
checkEnabledCustomOauthAccounts(services, serverUrl)
130158
checkEnabledSamlAccounts(services, serverUrl)
131159
}
@@ -227,11 +255,25 @@ abstract class CheckServerPresenter constructor(
227255
}
228256
}
229257

230-
private fun checkEnabledCasAccounts(serverUrl: String) {
258+
private fun checkEnabledCasAccounts(services: List<Map<String,Any>>, serverUrl: String) {
231259
if (settings.isCasAuthenticationEnabled()) {
232260
casToken = generateRandomString(17)
233261
casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
234-
totalSocialAccountsEnabled++
262+
getCasServices(services).let {
263+
for (serviceMap in it) {
264+
casServiceName = getServiceName(serviceMap)
265+
val serviceNameTextColor = getServiceNameColor(serviceMap)
266+
val serviceButtonColor = getServiceButtonColor(serviceMap)
267+
if (casServiceName != null &&
268+
serviceNameTextColor != null &&
269+
serviceButtonColor != null
270+
) {
271+
casServiceNameTextColor = serviceNameTextColor
272+
casServiceButtonColor = serviceButtonColor
273+
totalSocialAccountsEnabled++
274+
}
275+
}
276+
}
235277
}
236278
}
237279

@@ -244,8 +286,9 @@ abstract class CheckServerPresenter constructor(
244286
val clientId = getOauthClientId(serviceMap)
245287
val scope = getCustomOauthScope(serviceMap)
246288
val serviceNameTextColor =
247-
getServiceNameColorForCustomOauthOrSaml(serviceMap)
289+
getServiceNameColor(serviceMap)
248290
val serviceButtonColor = getServiceButtonColor(serviceMap)
291+
249292
if (customOauthServiceName != null &&
250293
host != null &&
251294
authorizePath != null &&
@@ -276,9 +319,9 @@ abstract class CheckServerPresenter constructor(
276319
samlToken = generateRandomString(17)
277320
for (serviceMap in it) {
278321
val provider = getSamlProvider(serviceMap)
279-
samlServiceName = getSamlServiceName(serviceMap)
322+
samlServiceName = getServiceName(serviceMap)
280323
val serviceNameTextColor =
281-
getServiceNameColorForCustomOauthOrSaml(serviceMap)
324+
getServiceNameColor(serviceMap)
282325
val serviceButtonColor = getServiceButtonColor(serviceMap)
283326

284327
if (provider != null &&
@@ -369,6 +412,14 @@ abstract class CheckServerPresenter constructor(
369412
private fun getCustomOauthServiceName(serviceMap: Map<String, Any>): String? =
370413
serviceMap["service"] as? String
371414

415+
/**
416+
* Returns a CAS service list.
417+
*
418+
* @return A CAS service list, otherwise an empty list if there is no CAS service.
419+
*/
420+
private fun getCasServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> =
421+
listMap.filter { map -> map["service"] == "cas" }
422+
372423
/**
373424
* Returns a SAML OAuth service list.
374425
*
@@ -388,26 +439,27 @@ abstract class CheckServerPresenter constructor(
388439

389440
/**
390441
* Returns the text of the SAML service.
442+
* REMARK: This can be used SAML or CAS.
391443
*
392444
* @param serviceMap The service map to get the text of the SAML service.
393445
* @return The text of the SAML service, otherwise null.
394446
*/
395-
private fun getSamlServiceName(serviceMap: Map<String, Any>): String? =
447+
private fun getServiceName(serviceMap: Map<String, Any>): String? =
396448
serviceMap["buttonLabelText"] as? String
397449

398450
/**
399451
* Returns the text color of the service name.
400-
* REMARK: This can be used for custom OAuth or SAML.
452+
* REMARK: This can be used for custom OAuth, SAML or CAS.
401453
*
402454
* @param serviceMap The service map to get the text color from.
403455
* @return The text color of the service (custom OAuth or SAML), otherwise null.
404456
*/
405-
private fun getServiceNameColorForCustomOauthOrSaml(serviceMap: Map<String, Any>): Int? =
457+
private fun getServiceNameColor(serviceMap: Map<String, Any>): Int? =
406458
(serviceMap["buttonLabelColor"] as? String)?.parseColor()
407459

408460
/**
409461
* Returns the button color of the service name.
410-
* REMARK: This can be used for custom OAuth or SAML.
462+
* REMARK: This can be used for custom OAuth, SAML or CAS.
411463
*
412464
* @param serviceMap The service map to get the button color from.
413465
* @return The button color of the service (custom OAuth or SAML), otherwise null.

0 commit comments

Comments
 (0)