-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jmx): re-implement enhanced transient JMX credentials (#524)
* feat(jmx): re-implement enhanced transient JMX credentials * yarn format:apply * add comma * remove unused dep * add more description about purpose of stored credentials * add link to Settings * add card providing context/explanation of rules and links to other views * remove unnecessary clear() call * update snapshot * add key property to child cards * clean up storage location / key handling * redefine as arrow func * apply prettier format * add snapshot test for Settings page * add test for JMX Credentials storage location settings control * add unit test for JmxCredentials.service * check that session storage is selected by default * test that dropdown reflects clicked selection * minor refactor * use 'within' * wait for select menu to close, not wait for text to not be visible * remove unnecessary cast
- Loading branch information
1 parent
ec23856
commit 19f353f
Showing
19 changed files
with
1,027 additions
and
33 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright The Cryostat Authors | ||
* | ||
* The Universal Permissive License (UPL), Version 1.0 | ||
* | ||
* Subject to the condition set forth below, permission is hereby granted to any | ||
* person obtaining a copy of this software, associated documentation and/or data | ||
* (collectively the "Software"), free of charge and under any and all copyright | ||
* rights in the Software, and any and all patent rights owned or freely | ||
* licensable by each licensor hereunder covering either (i) the unmodified | ||
* Software as contributed to or provided by such licensor, or (ii) the Larger | ||
* Works (as defined below), to deal in both | ||
* | ||
* (a) the Software, and | ||
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | ||
* one is included with the Software (each a "Larger Work" to which the Software | ||
* is contributed by such licensors), | ||
* | ||
* without restriction, including without limitation the rights to copy, create | ||
* derivative works of, display, perform, and distribute the Software and make, | ||
* use, sell, offer for sale, import, export, have made, and have sold the | ||
* Software and the Larger Work(s), and to sublicense the foregoing rights on | ||
* either these or other terms. | ||
* | ||
* This license is subject to the following condition: | ||
* The above copyright notice and either this complete permission notice or at | ||
* a minimum a reference to the UPL must be included in all copies or | ||
* substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { Select, SelectOption, SelectVariant, Text } from '@patternfly/react-core'; | ||
|
||
import { UserSetting } from './Settings'; | ||
import { getFromLocalStorage, saveToLocalStorage } from '@app/utils/LocalStorage'; | ||
|
||
export interface Location { | ||
key: string; | ||
description: string; | ||
} | ||
|
||
export class Locations { | ||
static readonly BROWSER_SESSION: Location = { | ||
key: 'Session (Browser Memory)', | ||
description: | ||
'Keep credentials in browser memory for the current session only. When you close this browser tab the credentials will be forgotten.', | ||
}; | ||
static readonly BACKEND: Location = { | ||
key: 'Backend', | ||
description: | ||
'Keep credentials in encrypted Cryostat backend storage. These credentials will be available to other users and will be used for Automated Rules.', | ||
}; | ||
} | ||
|
||
const locations = [Locations.BROWSER_SESSION, Locations.BACKEND]; | ||
|
||
const getLocation = (key: string): Location => { | ||
for (let l of locations) { | ||
if (l.key === key) { | ||
return l; | ||
} | ||
} | ||
return Locations.BROWSER_SESSION; | ||
}; | ||
|
||
const Component = () => { | ||
const [isExpanded, setExpanded] = React.useState(false); | ||
const [selection, setSelection] = React.useState(Locations.BROWSER_SESSION.key); | ||
|
||
const handleSelect = React.useCallback( | ||
(_, selection) => { | ||
let location = getLocation(selection); | ||
setSelection(location.key); | ||
setExpanded(false); | ||
saveToLocalStorage('JMX_CREDENTIAL_LOCATION', selection); | ||
}, | ||
[getLocation, setSelection, setExpanded, saveToLocalStorage] | ||
); | ||
|
||
React.useEffect(() => { | ||
handleSelect(undefined, getFromLocalStorage('JMX_CREDENTIAL_LOCATION', Locations.BROWSER_SESSION.key)); | ||
}, [handleSelect, getFromLocalStorage]); | ||
|
||
return ( | ||
<> | ||
<Select | ||
variant={SelectVariant.single} | ||
onToggle={setExpanded} | ||
onSelect={handleSelect} | ||
isOpen={isExpanded} | ||
selections={selection} | ||
> | ||
{locations.map((location) => ( | ||
<SelectOption key={location.key} value={location.key} description={location.description} /> | ||
))} | ||
</Select> | ||
</> | ||
); | ||
}; | ||
|
||
export const CredentialsStorage: UserSetting = { | ||
title: 'JMX Credentials Storage', | ||
description: ( | ||
<Text> | ||
When you attempt to connect to a target application which requires authentication, you will see a prompt for | ||
credentials to present to the application and complete the connection. You can choose where to persist these | ||
credentials. Any credentials added through the <Link to="/security">Security</Link> panel will always be stored in | ||
Cryostat backend encrypted storage. | ||
</Text> | ||
), | ||
content: Component, | ||
}; |
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
Oops, something went wrong.