Skip to content

Commit 8a4aeb4

Browse files
committed
feat(admin-ui): create redux for uma
1 parent 68f7cb0 commit 8a4aeb4

File tree

13 files changed

+171
-86
lines changed

13 files changed

+171
-86
lines changed

admin-ui/plugins/auth-server/components/Clients/ClientCibaParUmaPanel.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ function ClientCibaParUmaPanel({ client, dispatch, scope, umaResources, scripts,
5858
if (!isEmpty(uma)) {
5959
setSelectedUMA(uma)
6060
setScopeExpression(JSON.parse(uma.scopeExpression)?.data)
61-
dispatch(getScope(uma.inum))
61+
console.log('uma', uma)
62+
const getClientInum = uma?.clients[0].split(',')[0]
63+
const inum = getClientInum.split('=')[1]
64+
dispatch(getScope(inum))
6265
}
6366

6467
setOpen(true)
@@ -284,7 +287,6 @@ const mapStateToProps = (state) => {
284287
clientData: state.oidcReducer.item,
285288
loading: state.oidcReducer.loading,
286289
scope: state.scopeReducer.item,
287-
umaResources: state.oidcReducer.umaResources,
288290
}
289291
}
290292
export default connect(mapStateToProps)(ClientCibaParUmaPanel)

admin-ui/plugins/auth-server/components/Clients/ClientEditPage.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import ClientWizardForm from './ClientWizardForm'
33
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
44
import { useHistory } from 'react-router-dom'
55
import { connect } from 'react-redux'
6-
import { editClient, getUMAResourcesByClient } from 'Plugins/auth-server/redux/actions/OIDCActions'
6+
import { editClient } from 'Plugins/auth-server/redux/actions/OIDCActions'
7+
import { getUMAResourcesByClient } from 'Plugins/auth-server/redux/actions/UMAResourceActions'
78
import { getScopes } from 'Plugins/auth-server/redux/actions/ScopeActions'
89
import { getOidcDiscovery } from 'Redux/actions/OidcDiscoveryActions'
910
import { getScripts } from 'Redux/actions/InitActions'
@@ -92,7 +93,7 @@ const mapStateToProps = (state) => {
9293
oidcConfiguration: state.oidcDiscoveryReducer.configuration,
9394
saveOperationFlag: state.oidcReducer.saveOperationFlag,
9495
errorInSaveOperationFlag: state.oidcReducer.errorInSaveOperationFlag,
95-
umaResources: state.oidcReducer.umaResources,
96+
umaResources: state.umaResourceReducer.items,
9697
}
9798
}
9899
export default connect(mapStateToProps)(ClientEditPage)

admin-ui/plugins/auth-server/plugin-metadata.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import jsonReducer from './redux/reducers/JsonConfigReducer'
1818
import jwksReducer from './redux/reducers/JwksReducer'
1919
import acrReducer from './redux/reducers/AcrReducer'
2020
import loggingReducer from './redux/reducers/LoggingReducer'
21+
import umaResourceReducer from './redux/reducers/UMAResourceReducer'
2122

2223
import scopesSaga from './redux/sagas/OAuthScopeSaga'
2324
import oidcSaga from './redux/sagas/OIDCSaga'
2425
import jsonSaga from './redux/sagas/JsonConfigSaga'
2526
import jwksSaga from './redux/sagas/JwksSaga'
2627
import acrSaga from './redux/sagas/AcrsSaga'
2728
import loggingSaga from './redux/sagas/LoggingSaga'
29+
import umaResourceSaga from './redux/sagas/UMAResourceSaga'
2830

2931
import {
3032
ACR_READ,
@@ -135,6 +137,7 @@ const pluginMetadata = {
135137
{ name: 'jwksReducer', reducer: jwksReducer },
136138
{ name: 'acrReducer', reducer: acrReducer },
137139
{ name: 'loggingReducer', reducer: loggingReducer },
140+
{ name: 'umaResourceReducer', reducer: umaResourceReducer },
138141
],
139142
sagas: [
140143
scopesSaga(),
@@ -143,6 +146,7 @@ const pluginMetadata = {
143146
jwksSaga(),
144147
acrSaga(),
145148
loggingSaga(),
149+
umaResourceSaga(),
146150
],
147151
}
148152

admin-ui/plugins/auth-server/redux/actions/OIDCActions.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
DELETE_CLIENT_RESPONSE,
1010
SET_CLIENT_ITEM,
1111
SET_VIEW,
12-
SEARCH_CLIENTS,
13-
GET_UMA_RESOURCES,
14-
GET_UMA_RESOURCES_RESPONSE
12+
SEARCH_CLIENTS
1513
} from './types'
1614

1715
export const getOpenidClients = (action) => ({
@@ -67,13 +65,3 @@ export const viewOnly = (view) => ({
6765
type: SET_VIEW,
6866
payload: { view },
6967
})
70-
71-
export const getUMAResourcesByClient = (inum) => ({
72-
type: GET_UMA_RESOURCES,
73-
payload: { inum },
74-
})
75-
76-
export const getUMAResourcesByClientResponse = (data) => ({
77-
type: GET_UMA_RESOURCES_RESPONSE,
78-
payload: { data },
79-
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {
2+
GET_UMA_RESOURCES,
3+
GET_UMA_RESOURCES_RESPONSE
4+
} from './types'
5+
6+
export const getUMAResourcesByClient = (inum) => ({
7+
type: GET_UMA_RESOURCES,
8+
payload: { inum },
9+
})
10+
11+
export const getUMAResourcesByClientResponse = (data) => ({
12+
type: GET_UMA_RESOURCES_RESPONSE,
13+
payload: { data },
14+
})

admin-ui/plugins/auth-server/redux/actions/types.js

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export const DELETE_CLIENT = 'DELETE_CLIENT'
3737
export const DELETE_CLIENT_RESPONSE = 'DELETE_CLIENT_RESPONSE'
3838
export const SET_CLIENT_ITEM = 'SET_CLIENT_ITEM'
3939
export const SET_VIEW = 'SET_VIEW'
40+
41+
// UMA Resources
4042
export const GET_UMA_RESOURCES = 'GET_UMA_RESOURCES'
4143
export const GET_UMA_RESOURCES_RESPONSE = 'GET_UMA_RESOURCES_RESPONSE'
4244

admin-ui/plugins/auth-server/redux/api/OIDCApi.js

-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ export default class OIDCApi {
3535
})
3636
}
3737

38-
getUMAResources = async (clientId) => {
39-
return new Promise((resolve, reject) => {
40-
this.api.getOauthUmaResourcesByClientid(clientId, (error, data) => {
41-
this.handleResponse(error, reject, resolve, data)
42-
})
43-
})
44-
}
45-
4638
handleResponse(error, reject, resolve, data) {
4739
if (error) {
4840
reject(error)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default class UMAResourceApi {
2+
constructor(api) {
3+
this.api = api
4+
}
5+
6+
getUMAResources = async (clientId) => {
7+
return new Promise((resolve, reject) => {
8+
this.api.getOauthUmaResourcesByClientid(clientId, (error, data) => {
9+
this.handleResponse(error, reject, resolve, data)
10+
})
11+
})
12+
}
13+
14+
handleResponse(error, reject, resolve, data) {
15+
if (error) {
16+
reject(error)
17+
} else {
18+
resolve(data)
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const OIDC = 'openid-client'
22
export const SCOPE = 'scope'
3+
export const UMA = 'uma'
34
export const JSON_CONFIG = 'json-configuration'

admin-ui/plugins/auth-server/redux/reducers/OIDCReducer.js

-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
RESET,
1212
SEARCH_CLIENTS,
1313
SET_VIEW,
14-
GET_UMA_RESOURCES,
15-
GET_UMA_RESOURCES_RESPONSE
1614
} from '../actions/types'
1715
import reducerRegistry from 'Redux/reducers/ReducerRegistry'
1816

@@ -23,7 +21,6 @@ const INIT_STATE = {
2321
loading: false,
2422
saveOperationFlag: false,
2523
errorInSaveOperationFlag: false,
26-
umaResources: {},
2724
}
2825

2926
const reducerName = 'oidcReducer'
@@ -130,19 +127,6 @@ export default function oidcReducer(state = INIT_STATE, action) {
130127
} else {
131128
return handleDefault()
132129
}
133-
case GET_UMA_RESOURCES:
134-
return handleLoading()
135-
136-
case GET_UMA_RESOURCES_RESPONSE:
137-
if (action.payload.data) {
138-
return {
139-
...state,
140-
umaResources: action.payload.data,
141-
loading: false,
142-
}
143-
} else {
144-
return handleDefault()
145-
}
146130
case RESET:
147131
return {
148132
...state,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
RESET,
3+
GET_UMA_RESOURCES,
4+
GET_UMA_RESOURCES_RESPONSE
5+
} from '../actions/types'
6+
import reducerRegistry from 'Redux/reducers/ReducerRegistry'
7+
8+
const INIT_STATE = {
9+
items: [],
10+
loading: false,
11+
}
12+
13+
const reducerName = 'UMAResourceReducer'
14+
15+
export default function UMAResourceReducer(state = INIT_STATE, action) {
16+
switch (action.type) {
17+
18+
case GET_UMA_RESOURCES:
19+
return handleLoading()
20+
21+
case GET_UMA_RESOURCES_RESPONSE:
22+
if (action.payload.data) {
23+
return {
24+
...state,
25+
items: action.payload.data,
26+
loading: false,
27+
}
28+
} else {
29+
return handleDefault()
30+
}
31+
32+
case RESET:
33+
return {
34+
...state,
35+
items: INIT_STATE.items,
36+
loading: INIT_STATE.loading,
37+
}
38+
39+
default:
40+
return handleDefault()
41+
}
42+
43+
function handleDefault() {
44+
return {
45+
...state,
46+
loading: false,
47+
}
48+
}
49+
function handleLoading() {
50+
return {
51+
...state,
52+
loading: true,
53+
}
54+
}
55+
}
56+
57+
reducerRegistry.register(reducerName, UMAResourceReducer)

admin-ui/plugins/auth-server/redux/sagas/OIDCSaga.js

+2-45
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
getOpenidClientsResponse,
99
addClientResponse,
1010
editClientResponse,
11-
deleteClientResponse,
12-
getUMAResourcesByClientResponse,
11+
deleteClientResponse
1312
} from '../actions/OIDCActions'
1413
import { getAPIAccessToken } from '../actions/AuthActions'
1514
import { OIDC } from '../audit/Resources'
@@ -24,8 +23,7 @@ import {
2423
ADD_NEW_CLIENT,
2524
EDIT_CLIENT,
2625
DELETE_CLIENT,
27-
SEARCH_CLIENTS,
28-
GET_UMA_RESOURCES
26+
SEARCH_CLIENTS
2927
} from '../actions/types'
3028
import OIDCApi from '../api/OIDCApi'
3129
import { getClient } from 'Redux/api/base'
@@ -47,21 +45,6 @@ function* newFunction() {
4745
return new OIDCApi(api)
4846
}
4947

50-
function* newUMAFunction() {
51-
const wholeToken = yield select((state) => state.authReducer.token)
52-
let token = null
53-
if (wholeToken) {
54-
token = yield select((state) => state.authReducer.token.access_token)
55-
} else {
56-
token = null
57-
}
58-
const issuer = yield select((state) => state.authReducer.issuer)
59-
const api = new JansConfigApi.OAuthUMAResourcesApi(
60-
getClient(JansConfigApi, token, issuer),
61-
)
62-
return new OIDCApi(api)
63-
}
64-
6548
export function* getOauthOpenidClients({ payload }) {
6649
const audit = yield* initAudit()
6750
try {
@@ -139,28 +122,6 @@ export function* deleteAClient({ payload }) {
139122
}
140123
}
141124

142-
export function* getUMAResourcesByClient({ payload }) {
143-
const audit = yield* initAudit()
144-
try {
145-
payload = payload ? payload : {}
146-
addAdditionalData(audit, FETCH, GET_UMA_RESOURCES, payload)
147-
const openIdApi = yield* newUMAFunction()
148-
const data = yield call(
149-
openIdApi.getUMAResources,
150-
payload.inum,
151-
)
152-
yield put(getUMAResourcesByClientResponse(data))
153-
yield call(postUserAction, audit)
154-
} catch (e) {
155-
console.log(e)
156-
yield put(getUMAResourcesByClientResponse(null))
157-
if (isFourZeroOneError(e)) {
158-
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
159-
yield put(getAPIAccessToken(jwt))
160-
}
161-
}
162-
}
163-
164125
export function* getOpenidClientsWatcher() {
165126
yield takeLatest(GET_OPENID_CLIENTS, getOauthOpenidClients)
166127
}
@@ -179,9 +140,6 @@ export function* editClientWatcher() {
179140
export function* deleteClientWatcher() {
180141
yield takeLatest(DELETE_CLIENT, deleteAClient)
181142
}
182-
export function* getUMAResourcesByClientWatcher() {
183-
yield takeLatest(GET_UMA_RESOURCES, getUMAResourcesByClient)
184-
}
185143

186144
export default function* rootSaga() {
187145
yield all([
@@ -190,6 +148,5 @@ export default function* rootSaga() {
190148
fork(addClientWatcher),
191149
fork(editClientWatcher),
192150
fork(deleteClientWatcher),
193-
fork(getUMAResourcesByClientWatcher),
194151
])
195152
}

0 commit comments

Comments
 (0)