-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathAuthNListPage.js
More file actions
192 lines (176 loc) · 6.36 KB
/
AuthNListPage.js
File metadata and controls
192 lines (176 loc) · 6.36 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
import React, { useState, useEffect, useContext, useCallback } from 'react'
import MaterialTable from '@material-table/core'
import { Paper } from '@mui/material'
import { useNavigate } from 'react-router-dom'
import { useSelector, useDispatch } from 'react-redux'
import { useCedarling } from '@/cedarling'
import GluuViewWrapper from 'Routes/Apps/Gluu/GluuViewWrapper'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import { useTranslation } from 'react-i18next'
import { SCOPE_READ, SCOPE_WRITE } from 'Utils/PermChecker'
import customColors from '@/customColors'
import SetTitle from 'Utils/SetTitle'
import { ThemeContext } from 'Context/theme/themeContext'
import getThemeColor from 'Context/theme/config'
import AuthNDetailPage from './AuthNDetailPage'
import { getLdapConfig } from 'Plugins/services/redux/features/ldapSlice'
import { getCustomScriptByType } from 'Plugins/admin/redux/features/customScriptSlice'
import { setCurrentItem } from '../../redux/features/authNSlice'
import { getAcrsConfig } from 'Plugins/auth-server/redux/features/acrSlice'
function AuthNListPage({ isBuiltIn = false }) {
const { hasCedarPermission, authorize } = useCedarling()
const { t } = useTranslation()
const dispatch = useDispatch()
const [myActions, setMyActions] = useState([])
const navigate = useNavigate()
const [limit] = useState(10)
const theme = useContext(ThemeContext)
const selectedTheme = theme.state.theme
const themeColors = getThemeColor(selectedTheme)
const bgThemeColor = { background: themeColors.background }
const [list, setList] = useState({
ldap: [],
scripts: [],
})
const authN = useSelector((state) => state.authNReducer.acrs)
const ldap = useSelector((state) => state.ldapReducer.ldap)
const scripts = useSelector((state) => state.customScriptReducer.items)
const scriptsLoading = useSelector((state) => state.customScriptReducer.loading)
const loading = useSelector((state) => state.ldapReducer.loading)
const acrs = useSelector((state) => state.acrReducer.acrReponse)
const customScriptloading = useSelector((state) => state.customScriptReducer.loading)
const { permissions: cedarPermissions } = useSelector((state) => state.cedarPermissions)
SetTitle(t('titles.authentication'))
// Permission initialization
useEffect(() => {
const authorizePermissions = async () => {
const permissions = [SCOPE_READ, SCOPE_WRITE]
try {
for (const permission of permissions) {
await authorize([permission])
}
} catch (error) {
console.error('Error authorizing scope permissions:', error)
}
}
authorizePermissions()
dispatch(getLdapConfig())
dispatch(getCustomScriptByType({ action: { type: 'person_authentication' } }))
dispatch(getAcrsConfig())
return () => {
// Cleanup if needed
}
}, [dispatch])
// Actions as state that will rebuild when permissions change
useEffect(() => {
const newActions = []
if (hasCedarPermission(SCOPE_WRITE)) {
newActions.push((rowData) => {
return {
icon: 'edit',
iconProps: {
id: 'editAutN' + rowData.inum,
style: { color: customColors.darkGray },
},
tooltip: `${t('messages.edit_authn')}`,
onClick: (event, rowData) => handleGoToAuthNEditPage(rowData),
disabled: !hasCedarPermission(SCOPE_WRITE),
}
})
}
setMyActions(newActions)
}, [cedarPermissions, t, handleGoToAuthNEditPage])
useEffect(() => {
setList({ ...list, ldap: [] })
if (ldap.length > 0 && !loading) {
const getEnabledldap = ldap.filter((item) => item.enabled === true)
if (getEnabledldap?.length > 0) {
const updateLDAPItems = ldap.map((item) => ({
...item,
name: 'default_ldap_password',
acrName: item.configId,
}))
setList({ ...list, ldap: updateLDAPItems })
}
}
}, [ldap, loading])
useEffect(() => {
setList({ ...list, scripts: [] })
if (scripts.length > 0 && !scriptsLoading) {
const getEnabledscripts = scripts.filter((item) => item.enabled === true)
if (getEnabledscripts?.length > 0) {
const updateScriptsItems = getEnabledscripts.map((item) => ({
...item,
name: 'myAuthnScript',
acrName: item.name,
}))
setList({ ...list, scripts: updateScriptsItems })
}
}
}, [scripts])
const handleGoToAuthNEditPage = useCallback(
(row) => {
dispatch(setCurrentItem({ item: row }))
return navigate(`/auth-server/authn/edit/:` + row.inum)
},
[dispatch, navigate],
)
return (
<GluuViewWrapper canShow={hasCedarPermission(SCOPE_READ)}>
<MaterialTable
key={limit ? limit : 0}
components={{
Container: (props) => <Paper {...props} elevation={0} />,
}}
columns={[
{ title: `${t('fields.acr')}`, field: 'acrName' },
{ title: `${t('fields.saml_acr')}`, field: 'samlACR' },
{ title: `${t('fields.level')}`, field: 'level' },
{
title: `${t('options.default')}`,
field: '',
render: (rowData) => {
return rowData.acrName === acrs.defaultAcr ? (
<i
className="fa fa-check"
style={{ color: customColors.logo, fontSize: '24px' }}
></i>
) : (
<i
className="fa fa-close"
style={{ color: customColors.accentRed, fontSize: '24px' }}
></i>
)
},
},
]}
data={
loading || customScriptloading
? []
: isBuiltIn
? authN
: [...list.ldap, ...list.scripts].sort((item1, item2) => item1.level - item2.level)
}
isLoading={loading || customScriptloading}
title=""
actions={myActions}
options={{
columnsButton: true,
search: false,
idSynonym: 'inum',
selection: false,
pageSize: limit,
headerStyle: {
...applicationStyle.tableHeaderStyle,
...bgThemeColor,
},
actionsColumnIndex: -1,
}}
detailPanel={(rowData) => {
return <AuthNDetailPage row={rowData.rowData} />
}}
/>
</GluuViewWrapper>
)
}
export default AuthNListPage