KEYCLOAK-15481: Display forbidden screen
This commit is contained in:
parent
2572b1464b
commit
952e8fecee
4 changed files with 48 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
# Put new messages for Account Console Here
|
||||
# Feel free to use any existing messages from the base theme
|
||||
pageNotFound=Page Not Found
|
||||
forbidden=Forbidden
|
||||
needAccessRights=You do not have access rights to this request. Contact your administrator.
|
||||
invalidRoute={0} is not a valid route.
|
||||
actionRequiresIDP=This action requires redirection to your identity provider.
|
||||
continue=Continue
|
||||
|
|
|
@ -19,6 +19,7 @@ import {Route, Switch} from 'react-router-dom';
|
|||
import {NavItem, NavExpandable} from '@patternfly/react-core';
|
||||
import {Msg} from './widgets/Msg';
|
||||
import {PageNotFound} from './content/page-not-found/PageNotFound';
|
||||
import { ForbiddenPage } from './content/forbidden-page/ForbiddenPage';
|
||||
|
||||
export interface ContentItem {
|
||||
id?: string;
|
||||
|
@ -167,6 +168,7 @@ export function makeRoutes(): React.ReactNode {
|
|||
|
||||
return (<Switch>
|
||||
{routes}
|
||||
<Route path="/forbidden" component={ForbiddenPage}/>
|
||||
<Route component={PageNotFound}/>
|
||||
</Switch>);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
import {KeycloakService} from '../keycloak-service/keycloak.service';
|
||||
import {ContentAlert} from '../content/ContentAlert';
|
||||
|
||||
declare const baseUrl: string;
|
||||
|
||||
type ConfigResolve = (config: RequestInit) => void;
|
||||
|
||||
export interface HttpResponse<T = {}> extends Response {
|
||||
|
@ -88,12 +90,16 @@ export class AccountServiceClient {
|
|||
}
|
||||
|
||||
private handleError(response: HttpResponse): void {
|
||||
if (response != null && response.status === 401) {
|
||||
if (response !== null && response.status === 401) {
|
||||
// session timed out?
|
||||
this.kcSvc.login();
|
||||
}
|
||||
|
||||
if (response != null && response.data != null) {
|
||||
if (response !== null && response.status === 403) {
|
||||
window.location.href = baseUrl + '/#/forbidden';
|
||||
}
|
||||
|
||||
if (response !== null && response.data != null) {
|
||||
ContentAlert.danger(
|
||||
`${response.statusText}: ${response.data['errorMessage'] ? response.data['errorMessage'] : ''} ${response.data['error'] ? response.data['error'] : ''}`
|
||||
);
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2020 Red Hat, Inc. and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import * as React from 'react';
|
||||
|
||||
import { WarningTriangleIcon } from '@patternfly/react-icons';
|
||||
import {Msg} from '../../widgets/Msg';
|
||||
import EmptyMessageState from '../../widgets/EmptyMessageState';
|
||||
|
||||
|
||||
export class ForbiddenPage extends React.Component {
|
||||
|
||||
public constructor() {
|
||||
super({});
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
return (
|
||||
<EmptyMessageState icon={WarningTriangleIcon} messageKey="forbidden">
|
||||
<Msg msgKey="needAccessRights"/>
|
||||
</EmptyMessageState>
|
||||
);
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue