-
Notifications
You must be signed in to change notification settings - Fork 21
fix(admin-ui): Use typescript generated client for ACR and Authn pages #2553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0dfd282
fix(admin-ui): Use typescript generated client for ACR and Authn page…
syntrydy 153e9eb
fix(admin-ui): Use typescript generated client for ACR and Authn page…
syntrydy d8950bc
fix(admin-ui): Apply code review #2552
syntrydy 79d6207
fix(admin-ui): Apply code review #2552
syntrydy bfc7af9
fix(admin-ui): Apply code review #2552
syntrydy 4755a02
Merge branch 'main' into adminui-2552
moabu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
admin-ui/plugins/auth-server/components/AuthN/AuthNEditPage.js
This file was deleted.
Oops, something went wrong.
192 changes: 192 additions & 0 deletions
192
admin-ui/plugins/auth-server/components/AuthN/AuthNEditPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| import React, { useState, useCallback, type ReactElement } from 'react' | ||
| import { CardBody, Card } from 'Components' | ||
| import { useAtomValue } from 'jotai' | ||
| import AuthNForm from './AuthNForm' | ||
| import GluuLoader from 'Routes/Apps/Gluu/GluuLoader' | ||
| import GluuAlert from 'Routes/Apps/Gluu/GluuAlert' | ||
| import { useTranslation } from 'react-i18next' | ||
| import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' | ||
| import { useAppNavigation, ROUTES } from '@/helpers/navigation' | ||
| import { | ||
| usePutAcrs, | ||
| usePutConfigDatabaseLdap, | ||
| usePutConfigScripts, | ||
| type AuthenticationMethod, | ||
| type GluuLdapConfiguration, | ||
| type CustomScript, | ||
| } from 'JansConfigApi' | ||
| import { updateToast } from 'Redux/features/toastSlice' | ||
| import { useDispatch } from 'react-redux' | ||
| import { currentAuthNItemAtom, type AuthNItem } from './atoms' | ||
|
|
||
| interface ConfigurationProperty { | ||
| key?: string | ||
| value?: string | ||
| value1?: string | ||
| value2?: string | ||
| hide?: boolean | ||
| } | ||
|
|
||
| interface AuthNFormValues { | ||
| acr: string | ||
| level: number | ||
| defaultAuthNMethod: boolean | string | ||
| samlACR: string | ||
| description: string | ||
| primaryKey: string | ||
| passwordAttribute: string | ||
| hashAlgorithm: string | ||
| bindDN: string | ||
| maxConnections: string | number | ||
| remotePrimaryKey: string | ||
| localPrimaryKey: string | ||
| servers: string | string[] | ||
| baseDNs: string | string[] | ||
| bindPassword: string | ||
| useSSL: boolean | ||
| enabled: boolean | ||
| configId: string | ||
| baseDn: string | undefined | ||
| inum: string | undefined | ||
| configurationProperties?: ConfigurationProperty[] | ||
| } | ||
|
|
||
| function AuthNEditPage(): ReactElement { | ||
| const dispatch = useDispatch() | ||
| const { navigateToRoute } = useAppNavigation() | ||
| const { t } = useTranslation() | ||
| const atomItem = useAtomValue(currentAuthNItemAtom) | ||
| const item: AuthNItem = atomItem || {} | ||
syntrydy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const [isSubmitting, setIsSubmitting] = useState(false) | ||
|
|
||
| // Orval mutation hooks | ||
| const handleSuccess = useCallback(() => { | ||
| dispatch(updateToast(true, 'success')) | ||
| setTimeout(() => { | ||
| navigateToRoute(ROUTES.AUTH_SERVER_AUTHN) | ||
| }, 2000) | ||
| }, [dispatch, navigateToRoute]) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const handleError = useCallback( | ||
| (error: Error) => { | ||
| const errorMessage = error?.message || t('messages.error_in_saving') | ||
| dispatch(updateToast(true, 'error', errorMessage)) | ||
| setIsSubmitting(false) | ||
| }, | ||
| [dispatch, t], | ||
| ) | ||
|
|
||
| const putAcrsMutation = usePutAcrs({ | ||
| mutation: { | ||
| onSuccess: handleSuccess, | ||
| onError: handleError, | ||
| }, | ||
| }) | ||
|
|
||
| const putLdapMutation = usePutConfigDatabaseLdap({ | ||
| mutation: { | ||
| onSuccess: handleSuccess, | ||
| onError: handleError, | ||
| }, | ||
| }) | ||
|
|
||
| const putScriptMutation = usePutConfigScripts({ | ||
| mutation: { | ||
| onSuccess: handleSuccess, | ||
| onError: handleError, | ||
| }, | ||
| }) | ||
syntrydy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const isLoading = | ||
| isSubmitting || | ||
| putAcrsMutation.isPending || | ||
| putLdapMutation.isPending || | ||
| putScriptMutation.isPending | ||
|
|
||
| async function handleSubmit(data: AuthNFormValues): Promise<void> { | ||
| setIsSubmitting(true) | ||
|
|
||
| try { | ||
| if (item.name === 'simple_password_auth') { | ||
| if (data.defaultAuthNMethod === 'true' || data.defaultAuthNMethod === true) { | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const acrData: AuthenticationMethod = { defaultAcr: 'simple_password_auth' } | ||
| await putAcrsMutation.mutateAsync({ data: acrData }) | ||
| } else { | ||
| // No changes to make | ||
| handleSuccess() | ||
| } | ||
| } else if (item.name === 'default_ldap_password') { | ||
| // Update LDAP config | ||
| const ldapPayload: GluuLdapConfiguration = { | ||
| configId: item.configId || '', | ||
| bindDN: data.bindDN, | ||
| bindPassword: data.bindPassword, | ||
| servers: Array.isArray(data.servers) ? data.servers : [data.servers], | ||
| baseDNs: Array.isArray(data.baseDNs) ? data.baseDNs : [data.baseDNs], | ||
| primaryKey: data.primaryKey, | ||
| localPrimaryKey: data.localPrimaryKey, | ||
| maxConnections: | ||
| typeof data.maxConnections === 'string' | ||
| ? parseInt(data.maxConnections, 10) | ||
| : data.maxConnections, | ||
| useSSL: data.useSSL, | ||
| enabled: data.enabled, | ||
| level: data.level, | ||
| } | ||
|
|
||
| // Update default ACR if selected | ||
| if (data.defaultAuthNMethod === 'true' || data.defaultAuthNMethod === true) { | ||
| const acrData: AuthenticationMethod = { defaultAcr: data.configId } | ||
| await putAcrsMutation.mutateAsync({ data: acrData }) | ||
| } | ||
|
|
||
| await putLdapMutation.mutateAsync({ data: ldapPayload }) | ||
syntrydy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| // Script-based authentication | ||
| const scriptPayload: CustomScript = { | ||
| inum: data.inum, | ||
| dn: data.baseDn, | ||
| name: item.acrName, | ||
| description: data.description, | ||
| level: data.level, | ||
| scriptType: 'person_authentication', | ||
| } | ||
|
|
||
| if (data?.configurationProperties && data.configurationProperties.length > 0) { | ||
| scriptPayload.configurationProperties = data.configurationProperties | ||
| .filter((e): e is ConfigurationProperty => e != null) | ||
| .filter((e) => Object.keys(e).length !== 0) | ||
| .map((e) => ({ | ||
| value1: e.key || e.value1 || '', | ||
| value2: e.value || e.value2 || '', | ||
| hide: false, | ||
| })) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Update default ACR if selected | ||
| if (data.defaultAuthNMethod === 'true' || data.defaultAuthNMethod === true) { | ||
| const acrData: AuthenticationMethod = { defaultAcr: item.acrName || '' } | ||
| await putAcrsMutation.mutateAsync({ data: acrData }) | ||
| } | ||
|
|
||
| await putScriptMutation.mutateAsync({ data: scriptPayload }) | ||
| } | ||
| } catch { | ||
| // Error handling is done in onError callbacks | ||
| setIsSubmitting(false) | ||
| } | ||
syntrydy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return ( | ||
| <GluuLoader blocking={isLoading}> | ||
| <GluuAlert severity={t('titles.error')} message={t('messages.error_in_saving')} /> | ||
| <Card className="mb-3" style={applicationStyle.mainCard}> | ||
| <CardBody> | ||
| <AuthNForm handleSubmit={handleSubmit} item={{ ...item }} /> | ||
| </CardBody> | ||
| </Card> | ||
| </GluuLoader> | ||
syntrydy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export default AuthNEditPage | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.