Skip to content

Commit 2874224

Browse files
committed
oidc, console2: improve error handling
1 parent 59b2a86 commit 2874224

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

console2/src/components/pages/UnauthorizedPage/index.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@ import * as React from 'react';
2323
import { RedirectButton } from '../../organisms';
2424

2525
import './styles.css';
26-
import { Card, CardContent, CardHeader, Divider, Image } from 'semantic-ui-react';
27-
import { useContext, useEffect } from 'react';
28-
import { UserSessionContext } from '../../../session';
29-
30-
export default () => {
31-
const session = useContext(UserSessionContext);
32-
33-
useEffect(() => {
34-
session.setUserInfo(undefined);
35-
}, [session]);
26+
import {Card, CardContent, CardDescription, CardHeader, Divider, Image} from 'semantic-ui-react';
27+
import {withRouter} from "react-router";
3628

29+
export default withRouter((props) => {
30+
const error = new URLSearchParams(props.location.search).get('error');
3731
return (
3832
<div className="flexbox-container">
3933
<Card centered={true}>
@@ -42,6 +36,8 @@ export default () => {
4236

4337
<CardHeader>You are not authorized.</CardHeader>
4438

39+
{error && <CardDescription>Error: {error}</CardDescription>}
40+
4541
<Divider />
4642

4743
<RedirectButton primary={true} fluid={true} location={'/'}>
@@ -51,4 +47,4 @@ export default () => {
5147
</Card>
5248
</div>
5349
);
54-
};
50+
});

server/dist/src/main/resources/concord-server.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ concord-server {
589589
urlBase = "http://concord.example.com"
590590
afterLoginUrl = "http://concord.example.com"
591591
afterLogoutUrl = "http://concord.example.com/#/logout/done"
592+
onErrorUrl = "http://concord.example.com/#/unauthorized"
592593

593594
scopes = [ "openid", "profile", "email", "groups"]
594595

server/plugins/oidc/src/main/java/com/walmartlabs/concord/server/plugins/oidc/OidcCallbackFilter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
7272
postLoginUrl = cfg.getAfterLoginUrl();
7373
}
7474

75+
String error = req.getParameter("error");
76+
if (error != null) {
77+
String derivedError = "unknown";
78+
if ("access_denied".equals(error)) {
79+
derivedError = "oidc_access_denied";
80+
}
81+
resp.sendRedirect(resp.encodeRedirectURL(cfg.getOnErrorUrl() + "?from=" + postLoginUrl + "&error=" + derivedError));
82+
return;
83+
}
84+
7585
try {
7686
CallbackLogic<?, JEEContext> callback = pac4jConfig.getCallbackLogic();
7787
callback.perform(context, pac4jConfig, pac4jConfig.getHttpActionAdapter(), postLoginUrl, true, false, true, OidcPluginModule.CLIENT_NAME);

server/plugins/oidc/src/main/java/com/walmartlabs/concord/server/plugins/oidc/PluginConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public class PluginConfiguration {
5858
@Config("oidc.afterLogoutUrl")
5959
private String afterLogoutUrl;
6060

61+
@Inject
62+
@Config("oidc.onErrorUrl")
63+
private String onErrorUrl;
64+
6165
@Inject
6266
@Nullable
6367
@Config("oidc.scopes")
@@ -102,6 +106,10 @@ public String getAfterLogoutUrl() {
102106
return afterLogoutUrl;
103107
}
104108

109+
public String getOnErrorUrl() {
110+
return onErrorUrl;
111+
}
112+
105113
public List<String> getScopes() {
106114
return scopes;
107115
}

0 commit comments

Comments
 (0)