Skip to content

Commit

Permalink
fix(core): fix permissions issues (#1533)
Browse files Browse the repository at this point in the history
* Fix wrong connector permissions display conditions on screens
* Storing token in local storage to share it between browser tabs
* Handle auth issue for auth with bearer
  • Loading branch information
AlexisSouquiere authored Jul 31, 2023
1 parent 0519dbc commit f36ae79
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Root/Root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Root extends Component {
let config = new Map();
config.cancelToken = this.cancel.token;

if (sessionStorage.getItem('jwtToken')) {
if (localStorage.getItem('jwtToken')) {
config.headers = {};
config.headers['Authorization'] = 'Bearer ' + sessionStorage.getItem('jwtToken');
config.headers['Authorization'] = 'Bearer ' + localStorage.getItem('jwtToken');
}

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ConnectConfigs extends Form {
disabled={
plugin.name === 'name' ||
plugin.name === 'connector.class' ||
!(roles.CONNECT && roles.CONNECT.includes('UPDATE'))
!(roles.CONNECTOR && roles.CONNECTOR.includes('UPDATE'))
}
placeholder={plugin.defaultValue > 0 ? plugin.defaultValue : ''}
onChange={({ currentTarget: input }) => {
Expand Down Expand Up @@ -332,7 +332,7 @@ class ConnectConfigs extends Form {
<tbody>{display}</tbody>
</table>
</div>
{roles.CONNECT && roles.CONNECT.include('UPDATE') && (
{roles.CONNECTOR && roles.CONNECTOR.includes('UPDATE') && (
<div style={{ left: 0, width: '100%' }} className="khq-submit">
<button
type={'submit'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,15 @@ class ConnectTasks extends Root {
this.setState({ tableData: data });
}}
actions={
roles.CONNECT && roles.CONNECT.includes('UPDATE_STATE') && [constants.TABLE_RESTART]
roles.CONNECTOR &&
roles.CONNECTOR.includes('UPDATE_STATE') && [constants.TABLE_RESTART]
}
onRestart={row => {
this.handleAction(this.definitionState.RESTART_TASK, row.id);
}}
/>
</div>
{roles.CONNECT && roles.CONNECT.includes('UPDATE_STATE') && (
{roles.CONNECTOR && roles.CONNECTOR.includes('UPDATE_STATE') && (
<aside>
{definition.paused ? (
<li className="aside-button">
Expand Down
6 changes: 3 additions & 3 deletions client/src/containers/Connect/ConnectList/ConnectList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ class ConnectList extends Root {
const roles = this.state.roles || {};
let actions = [];

if (roles.CONNECT && roles.CONNECT.includes('READ')) {
if (roles.CONNECTOR && roles.CONNECTOR.includes('READ')) {
actions.push(constants.TABLE_DETAILS);
}
if (roles.CONNECT && roles.CONNECT.includes('DELETE')) {
if (roles.CONNECTOR && roles.CONNECTOR.includes('DELETE')) {
actions.push(constants.TABLE_DELETE);
}

Expand Down Expand Up @@ -356,7 +356,7 @@ class ConnectList extends Root {
}}
noContent={'No connectors available'}
/>
{roles.CONNECT && roles.CONNECT.includes('CREATE') && (
{roles.CONNECTOR && roles.CONNECTOR.includes('CREATE') && (
<aside>
<Link to={`/ui/${clusterId}/connect/${connectId}/create`} className="btn btn-primary">
Create a definition
Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Header extends Root {
sessionStorage.setItem('login', currentUserData.logged);
sessionStorage.setItem('user', 'default');
sessionStorage.setItem('roles', organizeRoles(currentUserData.roles));
sessionStorage.removeItem('jwtToken');
localStorage.removeItem('jwtToken');
this.setState({ login: currentUserData.logged }, () => {
this.props.history.replace({
pathname: '/ui/login',
Expand Down
9 changes: 8 additions & 1 deletion client/src/containers/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ class Login extends Form {
};

login(uriLogin(), body).then(res => {
// Handle login failed for bearer auth
if (res.status === 500) {
toast.error('Wrong Username or Password!');
return;
}

if (res.body) {
res.json().then(r => {
// Support JWT authentication through access_token
if (r.access_token) {
sessionStorage.setItem('jwtToken', r.access_token);
localStorage.setItem('jwtToken', r.access_token);
this.getData();
}
});
Expand All @@ -52,6 +58,7 @@ class Login extends Form {
}
});
} catch (err) {
// Handle login failed for cookie auth
toast.error('Wrong Username or Password!');
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/containers/Tail/Tail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class Tail extends Root {
const { search, selectedTopics, maxRecords } = this.state;
this.eventSource = new EventSourcePolyfill(
uriLiveTail(clusterId, search, selectedTopics, JSON.stringify(maxRecords)),
sessionStorage.getItem('jwtToken')
localStorage.getItem('jwtToken')
? {
headers: {
Authorization: 'Bearer ' + sessionStorage.getItem('jwtToken')
Authorization: 'Bearer ' + localStorage.getItem('jwtToken')
}
}
: {}
Expand Down
4 changes: 2 additions & 2 deletions client/src/containers/Topic/Topic/TopicData/TopicData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ class TopicData extends Root {
filters,
changePage ? nextPage : undefined
),
sessionStorage.getItem('jwtToken')
localStorage.getItem('jwtToken')
? {
headers: {
Authorization: 'Bearer ' + sessionStorage.getItem('jwtToken')
Authorization: 'Bearer ' + localStorage.getItem('jwtToken')
}
}
: {}
Expand Down

0 comments on commit f36ae79

Please sign in to comment.