Skip to content

Commit

Permalink
feat(admin-ui): create redux for uma
Browse files Browse the repository at this point in the history
  • Loading branch information
harryandriyan committed Aug 15, 2022
1 parent 68f7cb0 commit 8a4aeb4
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ function ClientCibaParUmaPanel({ client, dispatch, scope, umaResources, scripts,
if (!isEmpty(uma)) {
setSelectedUMA(uma)
setScopeExpression(JSON.parse(uma.scopeExpression)?.data)
dispatch(getScope(uma.inum))
console.log('uma', uma)
const getClientInum = uma?.clients[0].split(',')[0]
const inum = getClientInum.split('=')[1]
dispatch(getScope(inum))
}

setOpen(true)
Expand Down Expand Up @@ -284,7 +287,6 @@ const mapStateToProps = (state) => {
clientData: state.oidcReducer.item,
loading: state.oidcReducer.loading,
scope: state.scopeReducer.item,
umaResources: state.oidcReducer.umaResources,
}
}
export default connect(mapStateToProps)(ClientCibaParUmaPanel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import ClientWizardForm from './ClientWizardForm'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import { useHistory } from 'react-router-dom'
import { connect } from 'react-redux'
import { editClient, getUMAResourcesByClient } from 'Plugins/auth-server/redux/actions/OIDCActions'
import { editClient } from 'Plugins/auth-server/redux/actions/OIDCActions'
import { getUMAResourcesByClient } from 'Plugins/auth-server/redux/actions/UMAResourceActions'
import { getScopes } from 'Plugins/auth-server/redux/actions/ScopeActions'
import { getOidcDiscovery } from 'Redux/actions/OidcDiscoveryActions'
import { getScripts } from 'Redux/actions/InitActions'
Expand Down Expand Up @@ -92,7 +93,7 @@ const mapStateToProps = (state) => {
oidcConfiguration: state.oidcDiscoveryReducer.configuration,
saveOperationFlag: state.oidcReducer.saveOperationFlag,
errorInSaveOperationFlag: state.oidcReducer.errorInSaveOperationFlag,
umaResources: state.oidcReducer.umaResources,
umaResources: state.umaResourceReducer.items,
}
}
export default connect(mapStateToProps)(ClientEditPage)
4 changes: 4 additions & 0 deletions admin-ui/plugins/auth-server/plugin-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import jsonReducer from './redux/reducers/JsonConfigReducer'
import jwksReducer from './redux/reducers/JwksReducer'
import acrReducer from './redux/reducers/AcrReducer'
import loggingReducer from './redux/reducers/LoggingReducer'
import umaResourceReducer from './redux/reducers/UMAResourceReducer'

import scopesSaga from './redux/sagas/OAuthScopeSaga'
import oidcSaga from './redux/sagas/OIDCSaga'
import jsonSaga from './redux/sagas/JsonConfigSaga'
import jwksSaga from './redux/sagas/JwksSaga'
import acrSaga from './redux/sagas/AcrsSaga'
import loggingSaga from './redux/sagas/LoggingSaga'
import umaResourceSaga from './redux/sagas/UMAResourceSaga'

import {
ACR_READ,
Expand Down Expand Up @@ -135,6 +137,7 @@ const pluginMetadata = {
{ name: 'jwksReducer', reducer: jwksReducer },
{ name: 'acrReducer', reducer: acrReducer },
{ name: 'loggingReducer', reducer: loggingReducer },
{ name: 'umaResourceReducer', reducer: umaResourceReducer },
],
sagas: [
scopesSaga(),
Expand All @@ -143,6 +146,7 @@ const pluginMetadata = {
jwksSaga(),
acrSaga(),
loggingSaga(),
umaResourceSaga(),
],
}

Expand Down
14 changes: 1 addition & 13 deletions admin-ui/plugins/auth-server/redux/actions/OIDCActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
DELETE_CLIENT_RESPONSE,
SET_CLIENT_ITEM,
SET_VIEW,
SEARCH_CLIENTS,
GET_UMA_RESOURCES,
GET_UMA_RESOURCES_RESPONSE
SEARCH_CLIENTS
} from './types'

export const getOpenidClients = (action) => ({
Expand Down Expand Up @@ -67,13 +65,3 @@ export const viewOnly = (view) => ({
type: SET_VIEW,
payload: { view },
})

export const getUMAResourcesByClient = (inum) => ({
type: GET_UMA_RESOURCES,
payload: { inum },
})

export const getUMAResourcesByClientResponse = (data) => ({
type: GET_UMA_RESOURCES_RESPONSE,
payload: { data },
})
14 changes: 14 additions & 0 deletions admin-ui/plugins/auth-server/redux/actions/UMAResourceActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
GET_UMA_RESOURCES,
GET_UMA_RESOURCES_RESPONSE
} from './types'

export const getUMAResourcesByClient = (inum) => ({
type: GET_UMA_RESOURCES,
payload: { inum },
})

export const getUMAResourcesByClientResponse = (data) => ({
type: GET_UMA_RESOURCES_RESPONSE,
payload: { data },
})
2 changes: 2 additions & 0 deletions admin-ui/plugins/auth-server/redux/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const DELETE_CLIENT = 'DELETE_CLIENT'
export const DELETE_CLIENT_RESPONSE = 'DELETE_CLIENT_RESPONSE'
export const SET_CLIENT_ITEM = 'SET_CLIENT_ITEM'
export const SET_VIEW = 'SET_VIEW'

// UMA Resources
export const GET_UMA_RESOURCES = 'GET_UMA_RESOURCES'
export const GET_UMA_RESOURCES_RESPONSE = 'GET_UMA_RESOURCES_RESPONSE'

Expand Down
8 changes: 0 additions & 8 deletions admin-ui/plugins/auth-server/redux/api/OIDCApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ export default class OIDCApi {
})
}

getUMAResources = async (clientId) => {
return new Promise((resolve, reject) => {
this.api.getOauthUmaResourcesByClientid(clientId, (error, data) => {
this.handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
Expand Down
21 changes: 21 additions & 0 deletions admin-ui/plugins/auth-server/redux/api/UMAResourceApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default class UMAResourceApi {
constructor(api) {
this.api = api
}

getUMAResources = async (clientId) => {
return new Promise((resolve, reject) => {
this.api.getOauthUmaResourcesByClientid(clientId, (error, data) => {
this.handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
1 change: 1 addition & 0 deletions admin-ui/plugins/auth-server/redux/audit/Resources.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const OIDC = 'openid-client'
export const SCOPE = 'scope'
export const UMA = 'uma'
export const JSON_CONFIG = 'json-configuration'
16 changes: 0 additions & 16 deletions admin-ui/plugins/auth-server/redux/reducers/OIDCReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
RESET,
SEARCH_CLIENTS,
SET_VIEW,
GET_UMA_RESOURCES,
GET_UMA_RESOURCES_RESPONSE
} from '../actions/types'
import reducerRegistry from 'Redux/reducers/ReducerRegistry'

Expand All @@ -23,7 +21,6 @@ const INIT_STATE = {
loading: false,
saveOperationFlag: false,
errorInSaveOperationFlag: false,
umaResources: {},
}

const reducerName = 'oidcReducer'
Expand Down Expand Up @@ -130,19 +127,6 @@ export default function oidcReducer(state = INIT_STATE, action) {
} else {
return handleDefault()
}
case GET_UMA_RESOURCES:
return handleLoading()

case GET_UMA_RESOURCES_RESPONSE:
if (action.payload.data) {
return {
...state,
umaResources: action.payload.data,
loading: false,
}
} else {
return handleDefault()
}
case RESET:
return {
...state,
Expand Down
57 changes: 57 additions & 0 deletions admin-ui/plugins/auth-server/redux/reducers/UMAResourceReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
RESET,
GET_UMA_RESOURCES,
GET_UMA_RESOURCES_RESPONSE
} from '../actions/types'
import reducerRegistry from 'Redux/reducers/ReducerRegistry'

const INIT_STATE = {
items: [],
loading: false,
}

const reducerName = 'UMAResourceReducer'

export default function UMAResourceReducer(state = INIT_STATE, action) {
switch (action.type) {

case GET_UMA_RESOURCES:
return handleLoading()

case GET_UMA_RESOURCES_RESPONSE:
if (action.payload.data) {
return {
...state,
items: action.payload.data,
loading: false,
}
} else {
return handleDefault()
}

case RESET:
return {
...state,
items: INIT_STATE.items,
loading: INIT_STATE.loading,
}

default:
return handleDefault()
}

function handleDefault() {
return {
...state,
loading: false,
}
}
function handleLoading() {
return {
...state,
loading: true,
}
}
}

reducerRegistry.register(reducerName, UMAResourceReducer)
47 changes: 2 additions & 45 deletions admin-ui/plugins/auth-server/redux/sagas/OIDCSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
getOpenidClientsResponse,
addClientResponse,
editClientResponse,
deleteClientResponse,
getUMAResourcesByClientResponse,
deleteClientResponse
} from '../actions/OIDCActions'
import { getAPIAccessToken } from '../actions/AuthActions'
import { OIDC } from '../audit/Resources'
Expand All @@ -24,8 +23,7 @@ import {
ADD_NEW_CLIENT,
EDIT_CLIENT,
DELETE_CLIENT,
SEARCH_CLIENTS,
GET_UMA_RESOURCES
SEARCH_CLIENTS
} from '../actions/types'
import OIDCApi from '../api/OIDCApi'
import { getClient } from 'Redux/api/base'
Expand All @@ -47,21 +45,6 @@ function* newFunction() {
return new OIDCApi(api)
}

function* newUMAFunction() {
const wholeToken = yield select((state) => state.authReducer.token)
let token = null
if (wholeToken) {
token = yield select((state) => state.authReducer.token.access_token)
} else {
token = null
}
const issuer = yield select((state) => state.authReducer.issuer)
const api = new JansConfigApi.OAuthUMAResourcesApi(
getClient(JansConfigApi, token, issuer),
)
return new OIDCApi(api)
}

export function* getOauthOpenidClients({ payload }) {
const audit = yield* initAudit()
try {
Expand Down Expand Up @@ -139,28 +122,6 @@ export function* deleteAClient({ payload }) {
}
}

export function* getUMAResourcesByClient({ payload }) {
const audit = yield* initAudit()
try {
payload = payload ? payload : {}
addAdditionalData(audit, FETCH, GET_UMA_RESOURCES, payload)
const openIdApi = yield* newUMAFunction()
const data = yield call(
openIdApi.getUMAResources,
payload.inum,
)
yield put(getUMAResourcesByClientResponse(data))
yield call(postUserAction, audit)
} catch (e) {
console.log(e)
yield put(getUMAResourcesByClientResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}

export function* getOpenidClientsWatcher() {
yield takeLatest(GET_OPENID_CLIENTS, getOauthOpenidClients)
}
Expand All @@ -179,9 +140,6 @@ export function* editClientWatcher() {
export function* deleteClientWatcher() {
yield takeLatest(DELETE_CLIENT, deleteAClient)
}
export function* getUMAResourcesByClientWatcher() {
yield takeLatest(GET_UMA_RESOURCES, getUMAResourcesByClient)
}

export default function* rootSaga() {
yield all([
Expand All @@ -190,6 +148,5 @@ export default function* rootSaga() {
fork(addClientWatcher),
fork(editClientWatcher),
fork(deleteClientWatcher),
fork(getUMAResourcesByClientWatcher),
])
}
Loading

0 comments on commit 8a4aeb4

Please sign in to comment.