Bläddra i källkod

Remove files not in module tree.

Kestrel 7 månader sedan
förälder
incheckning
4fdd3022bc
2 ändrade filer med 0 tillägg och 232 borttagningar
  1. 0 107
      src/group_management.rs
  2. 0 125
      src/token_management.rs

+ 0 - 107
src/group_management.rs

@@ -1,107 +0,0 @@
-use crate::{schema, UIDCError};
-use microrm::prelude::*;
-
-pub fn create_group(realm: &Stored<schema::Realm>, name: &str) -> Result<(), UIDCError> {
-    realm.groups.insert(schema::Group {
-        realm: realm.id(),
-        shortname: name.into(),
-        roles: Default::default(),
-        users: Default::default(),
-    })?;
-    Ok(())
-}
-
-pub fn list_groups(realm: &schema::Realm) -> Result<(), UIDCError> {
-    for group in realm.groups.get()? {
-        println!("{}", group.shortname);
-    }
-    Ok(())
-}
-
-pub fn list_members(realm: &schema::Realm, name: &str) -> Result<(), UIDCError> {
-    for member in realm.groups.with(schema::Group::Shortname, name).first().join(schema::Group::Users).get()? {
-        println!("- {}", member.username);
-    }
-
-    Ok(())
-}
-
-pub fn list_roles(realm: &schema::Realm, name: &String) -> Result<(), UIDCError> {
-    for role in realm.groups.with(schema::Group::Shortname, name).join(schema::Group::Roles).get()? {
-        println!("- {}", role.shortname);
-    }
-
-    Ok(())
-}
-
-pub fn attach_user(
-    realm: &schema::Realm,
-    group_name: &String,
-    username: &String,
-) -> Result<(), UIDCError> {
-    let group = realm.groups.with(schema::Group::Shortname, group_name).first().get()?;
-    let user = realm.users.with(schema::User::Username, username).first().get()?;
-
-    match (group, user) {
-        (None, _) => Err(UIDCError::Abort("no such group")),
-        (_, None) => Err(UIDCError::Abort("no such user")),
-        (Some(group), Some(user)) => {
-            group.users.connect_to(user.id())?;
-            Ok(())
-        }
-    }
-}
-
-pub fn detach_user(
-    realm: &schema::Realm,
-    group_name: &String,
-    username: &String,
-) -> Result<(), UIDCError> {
-    let group = realm.groups.keyed(group_name).get()?;
-    let user = realm.users.keyed(username).get()?;
-
-    match (group, user) {
-        (None, _) => Err(UIDCError::Abort("no such group")),
-        (_, None) => Err(UIDCError::Abort("no such user")),
-        (Some(group), Some(user)) => {
-            group.users.disconnect_from(user.id())?;
-            Ok(())
-        }
-    }
-}
-
-pub fn attach_role(
-    realm: &schema::Realm,
-    group_name: &String,
-    role_name: &String,
-) -> Result<(), UIDCError> {
-    let group = realm.groups.keyed(group_name).get()?;
-    let role = realm.roles.keyed(role_name).get()?;
-
-    match (group, role) {
-        (None, _) => Err(UIDCError::Abort("no such group")),
-        (_, None) => Err(UIDCError::Abort("no such role")),
-        (Some(group), Some(role)) => {
-            group.roles.connect_to(role.id())?;
-            Ok(())
-        }
-    }
-}
-
-pub fn detach_role(
-    realm: &schema::Realm,
-    group_name: &String,
-    role_name: &String,
-) -> Result<(), UIDCError> {
-    let group = realm.groups.keyed(group_name).get()?;
-    let role = realm.roles.keyed(role_name).get()?;
-
-    match (group, role) {
-        (None, _) => Err(UIDCError::Abort("no such group")),
-        (_, None) => Err(UIDCError::Abort("no such role")),
-        (Some(group), Some(role)) => {
-            group.roles.disconnect_from(role.id())?;
-            Ok(())
-        }
-    }
-}

+ 0 - 125
src/token_management.rs

@@ -1,125 +0,0 @@
-use crate::{config::Config, key, schema, UIDCError};
-use microrm::prelude::*;
-
-pub fn create_auth_token(
-    realm: &schema::Realm,
-    config: &Config,
-    client: &String,
-    username: &String,
-    scopes: &String,
-) -> Result<String, UIDCError> {
-    token::generate_access_token(
-        config,
-        realm,
-        &realm
-            .clients
-            .with(schema::Client::Shortname, client)
-            .first()
-            .get()?
-            .ok_or(UIDCError::Abort("no such client"))?
-            .wrapped(),
-        &realm
-            .users
-            .with(schema::User::Username, username)
-            .first()
-            .get()?
-            .ok_or(UIDCError::Abort("no such user"))?
-            .wrapped(),
-        scopes.split_whitespace(),
-    )
-}
-
-pub fn create_refresh_token(
-    realm: &schema::Realm,
-    config: &Config,
-    client: &String,
-    username: &String,
-    scopes: &String,
-) -> Result<String, UIDCError> {
-    token::generate_refresh_token(
-        config,
-        realm,
-        &realm
-            .clients
-            .with(schema::Client::Shortname, client)
-            .first()
-            .get()?
-            .ok_or(UIDCError::Abort("no such client"))?
-            .wrapped(),
-        &realm
-            .users
-            .with(schema::User::Username, username)
-            .first()
-            .get()?
-            .ok_or(UIDCError::Abort("no such user"))?
-            .wrapped(),
-        scopes.split_whitespace(),
-    )
-}
-
-pub fn inspect_token(
-    _config: &Config,
-    realm: &schema::Realm,
-    token: Option<&String>,
-) -> Result<(), UIDCError> {
-
-    todo!()
-
-    /*
-    let token = match token {
-        Some(token) => token.clone(),
-        None => rpassword::prompt_password("Enter token: ").unwrap(),
-    };
-
-    let header = jwt::JWTHeader::parse(token.as_str())
-        .ok_or(UIDCError::Abort("failed to parse JWT header"))?;
-
-    let mut realmkeys = key::RealmKeys::new(realm.clone());
-
-    let mut pk = None;
-
-    if let Some(kid) = header.kid {
-        pk = realmkeys.by_key_id(&kid)?;
-    }
-    if pk.is_none() {
-        if let Some(_alg) = header.alg {
-            todo!("algorithm fallback")
-            // pk = realmkeys.by_type(&kid)?;
-        }
-    }
-
-    let jwt = if let Some(key) = pk {
-        jwt::JWT::verify(&key, token.as_str())
-    } else {
-        println!("No matching realm key found!");
-        return Ok(());
-    };
-
-    // let jwt = jwt::JWT::verify(&pubkey, token.as_str());
-    if jwt.is_none() {
-        println!("Signature validation against realm key failed!");
-    } else if let Some(claims) = jwt.as_ref().and_then(jwt::JWT::claims) {
-        println!("Base claims:");
-        println!(" - issuer      : {}", claims.iss);
-        println!(" - audience    : {}", claims.aud);
-        println!(" - subject     : {}", claims.sub);
-        println!(
-            " - issued at   : {} [{}]",
-            claims.iat,
-            time::OffsetDateTime::from_unix_timestamp(claims.iat as i64).unwrap()
-        );
-        println!(
-            " - expires at  : {} [{}]",
-            claims.exp,
-            time::OffsetDateTime::from_unix_timestamp(claims.exp as i64).unwrap()
-        );
-        for claim in claims.extras {
-            println!(" - {:12}: {}", claim.0, claim.1);
-        }
-    } else {
-        println!("Claim parsing failed!");
-    }
-
-    Ok(())
-    */
-}