-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0468537
commit cacd96c
Showing
13 changed files
with
271 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/license_management/common/constants/permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const APP_PERMISSION = 'cluster:manage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { connect } from 'react-redux'; | ||
import { withRouter } from 'react-router-dom'; | ||
|
||
import { App as PresentationComponent } from './app'; | ||
import { getPermission, isPermissionsLoading, getPermissionsError } from './store/reducers/licenseManagement'; | ||
import { loadPermissions } from './store/actions/permissions'; | ||
|
||
const mapStateToProps = state => { | ||
return { | ||
hasPermission: getPermission(state), | ||
permissionsLoading: isPermissionsLoading(state), | ||
permissionsError: getPermissionsError(state), | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = { | ||
loadPermissions, | ||
}; | ||
|
||
export const App = withRouter(connect(mapStateToProps, mapDispatchToProps)( | ||
PresentationComponent | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/license_management/public/store/actions/permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createAction } from 'redux-actions'; | ||
import { getPermissions } from '../../lib/es'; | ||
|
||
export const permissionsLoading = createAction( | ||
'LICENSE_MANAGEMENT_PERMISSIONS_LOADING' | ||
); | ||
|
||
export const permissionsSuccess = createAction( | ||
'LICENSE_MANAGEMENT_PERMISSIONS_SUCCESS' | ||
); | ||
|
||
export const permissionsError = createAction( | ||
'LICENSE_MANAGEMENT_PERMISSIONS_ERROR' | ||
); | ||
|
||
export const loadPermissions = () => async dispatch => { | ||
dispatch(permissionsLoading(true)); | ||
try { | ||
const permissions = await getPermissions(); | ||
dispatch(permissionsLoading(false)); | ||
dispatch(permissionsSuccess(permissions.hasPermission)); | ||
} catch (e) { | ||
dispatch(permissionsLoading(false)); | ||
dispatch(permissionsError(e)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/license_management/public/store/reducers/permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { handleActions } from 'redux-actions'; | ||
|
||
import { permissionsSuccess, permissionsError, permissionsLoading } from '../actions/permissions'; | ||
|
||
export const permissions = handleActions({ | ||
[permissionsLoading](state, { payload }) { | ||
return { | ||
loading: payload, | ||
}; | ||
}, | ||
[permissionsSuccess](state, { payload }) { | ||
return { | ||
hasPermission: payload, | ||
}; | ||
}, | ||
[permissionsError](state, { payload }) { | ||
return { | ||
error: payload, | ||
}; | ||
}, | ||
}, {}); |
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/license_management/server/lib/permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { wrapCustomError } from '../../../../server/lib/create_router/error_wrappers'; | ||
|
||
export async function getPermissions(req, xpackInfo) { | ||
if (!xpackInfo) { | ||
// xpackInfo is updated via poll, so it may not be available until polling has begun. | ||
// In this rare situation, tell the client the service is temporarily unavailable. | ||
throw wrapCustomError(new Error('Security info unavailable'), 503); | ||
} | ||
|
||
const securityInfo = xpackInfo && xpackInfo.isAvailable() && xpackInfo.feature('security'); | ||
if (!securityInfo || !securityInfo.isAvailable() || !securityInfo.isEnabled()) { | ||
// If security isn't enabled, let the user use license management | ||
return { | ||
hasPermission: true, | ||
}; | ||
} | ||
|
||
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('admin'); | ||
const options = { | ||
method: 'POST', | ||
path: '/_security/user/_has_privileges', | ||
body: { | ||
cluster: ['manage'], // License management requires "manage" cluster privileges | ||
} | ||
}; | ||
|
||
try { | ||
const response = await callWithRequest(req, 'transport.request', options); | ||
return { | ||
hasPermission: response.cluster.manage, | ||
}; | ||
} catch (error) { | ||
return error.body; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/license_management/server/routes/api/license/register_permissions_route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getPermissions } from '../../../lib/permissions'; | ||
|
||
export function registerPermissionsRoute(router, xpackInfo) { | ||
router.post('/permissions', (request) => { | ||
return getPermissions(request, xpackInfo); | ||
}); | ||
} |