diff --git a/monkey/infection_monkey/master/control_channel.py b/monkey/infection_monkey/master/control_channel.py index cdf660842..ccff3e783 100644 --- a/monkey/infection_monkey/master/control_channel.py +++ b/monkey/infection_monkey/master/control_channel.py @@ -84,7 +84,7 @@ class ControlChannel(IControlChannel): ) response.raise_for_status() - return [Credentials.from_mapping(credentials) for credentials in response.json] + return [Credentials.from_mapping(credentials) for credentials in response.json()] except ( requests.exceptions.JSONDecodeError, requests.exceptions.ConnectionError, diff --git a/monkey/monkey_island/cc/repository/mongo_credentials_repository.py b/monkey/monkey_island/cc/repository/mongo_credentials_repository.py index 5d58d510a..ee8beb13c 100644 --- a/monkey/monkey_island/cc/repository/mongo_credentials_repository.py +++ b/monkey/monkey_island/cc/repository/mongo_credentials_repository.py @@ -14,14 +14,14 @@ class MongoCredentialsRepository(ICredentialsRepository): """ def __init__(self, mongo: MongoClient, repository_encryptor: ILockableEncryptor): - self._mongo = mongo + self._database = mongo.monkeyisland self._repository_encryptor = repository_encryptor def get_configured_credentials(self) -> Sequence[Credentials]: - return self._get_credentials_from_collection(self._mongo.db.configured_credentials) + return self._get_credentials_from_collection(self._database.configured_credentials) def get_stolen_credentials(self) -> Sequence[Credentials]: - return self._get_credentials_from_collection(self._mongo.db.stolen_credentials) + return self._get_credentials_from_collection(self._database.stolen_credentials) def get_all_credentials(self) -> Sequence[Credentials]: configured_credentials = self.get_configured_credentials() @@ -31,20 +31,16 @@ class MongoCredentialsRepository(ICredentialsRepository): def save_configured_credentials(self, credentials: Sequence[Credentials]): # TODO: Fix deduplication of Credentials in mongo - self._save_credentials_to_collection(credentials, self._mongo.db.configured_credentials) + self._save_credentials_to_collection(credentials, self._database.configured_credentials) def save_stolen_credentials(self, credentials: Sequence[Credentials]): - self._save_credentials_to_collection(credentials, self._mongo.db.stolen_credentials) + self._save_credentials_to_collection(credentials, self._database.stolen_credentials) def remove_configured_credentials(self): - MongoCredentialsRepository._remove_credentials_fom_collection( - self._mongo.db.configured_credentials - ) + self._remove_credentials_fom_collection(self._database.configured_credentials) def remove_stolen_credentials(self): - MongoCredentialsRepository._remove_credentials_fom_collection( - self._mongo.db.stolen_credentials - ) + self._remove_credentials_fom_collection(self._database.stolen_credentials) def remove_all_credentials(self): self.remove_configured_credentials() diff --git a/monkey/monkey_island/cc/resources/propagation_credentials.py b/monkey/monkey_island/cc/resources/propagation_credentials.py index c5dfc42fe..2342d0f37 100644 --- a/monkey/monkey_island/cc/resources/propagation_credentials.py +++ b/monkey/monkey_island/cc/resources/propagation_credentials.py @@ -42,6 +42,22 @@ class PropagationCredentials(AbstractResource): return {}, HTTPStatus.NO_CONTENT + def put(self, collection=None): + credentials = [Credentials.from_mapping(c) for c in request.json] + + if collection == _configured_collection: + self._credentials_repository.remove_configured_credentials() + self._credentials_repository.save_configured_credentials(credentials) + elif collection == _stolen_collection: + self._credentials_repository.remove_stolen_credentials() + self._credentials_repository.save_stolen_credentials(credentials) + elif collection is None: + return {}, HTTPStatus.METHOD_NOT_ALLOWED + else: + return {}, HTTPStatus.NOT_FOUND + + return {}, HTTPStatus.NO_CONTENT + def delete(self, collection=None): if collection == _configured_collection: self._credentials_repository.remove_configured_credentials() diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/CredentialsConfig.tsx b/monkey/monkey_island/cc/ui/src/components/configuration-components/CredentialsConfig.tsx new file mode 100644 index 000000000..4e40f980b --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/CredentialsConfig.tsx @@ -0,0 +1,26 @@ +import Form from 'react-jsonschema-form-bs4'; +import React from 'react'; +import _ from 'lodash'; + +export default function CredentialsConfig(props) { + const { + schema, + uiSchema, + credentials, + onChange, + customFormats, + className + } = props; + + let credentialsCopy = _.clone(credentials); + return (<> +