CLI: Allow editing principal password

This commit is contained in:
Lennart
2025-04-26 10:52:23 +02:00
parent 6b9bd1226f
commit 4071ea4ff4
6 changed files with 68 additions and 22 deletions

View File

@@ -281,14 +281,17 @@ impl<AP: AuthenticationProvider> UserStore for OidcUserStore<AP> {
async fn insert_user(&self, id: &str) -> Result<(), Self::Error> {
self.0
.insert_principal(User {
id: id.to_owned(),
displayname: None,
principal_type: Default::default(),
password: None,
app_tokens: vec![],
memberships: vec![],
})
.insert_principal(
User {
id: id.to_owned(),
displayname: None,
principal_type: Default::default(),
password: None,
app_tokens: vec![],
memberships: vec![],
},
false,
)
.await
}
}

View File

@@ -9,7 +9,7 @@ pub trait AuthenticationProvider: 'static {
async fn get_principals(&self) -> Result<Vec<User>, crate::Error>;
async fn get_principal(&self, id: &str) -> Result<Option<User>, crate::Error>;
async fn remove_principal(&self, id: &str) -> Result<(), crate::Error>;
async fn insert_principal(&self, user: User) -> Result<(), crate::Error>;
async fn insert_principal(&self, user: User, overwrite: bool) -> Result<(), crate::Error>;
async fn validate_password(&self, user_id: &str, password: &str)
-> Result<Option<User>, Error>;
async fn validate_app_token(&self, user_id: &str, token: &str) -> Result<Option<User>, Error>;

View File

@@ -69,9 +69,9 @@ impl AuthenticationProvider for TomlPrincipalStore {
Ok(self.principals.read().await.get(id).cloned())
}
async fn insert_principal(&self, user: User) -> Result<(), crate::Error> {
async fn insert_principal(&self, user: User, overwrite: bool) -> Result<(), crate::Error> {
let mut principals = self.principals.write().await;
if principals.contains_key(&user.id) {
if !overwrite && principals.contains_key(&user.id) {
return Err(Error::AlreadyExists);
}
principals.insert(user.id.clone(), user);