aboutsummaryrefslogtreecommitdiffstats
path: root/src/access/token.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/access/token.rs')
-rw-r--r--src/access/token.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/access/token.rs b/src/access/token.rs
index a9fc270..153737e 100644
--- a/src/access/token.rs
+++ b/src/access/token.rs
@@ -174,11 +174,8 @@ fn issuer_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
/// In a swarm with a registry: its user registered, enabled, its tokens not revoked
/// since it was issued, its session not ended.
fn user_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
- if registry::exists(doc) {
- let user = registry::user(doc, &claims.user).ok_or(Refused::UnknownUser)?;
- if user.disabled {
- return Err(Refused::Disabled);
- }
+ user_taken(doc, &claims.user)?;
+ if let Some(user) = registry::user(doc, &claims.user) {
if claims.iat < user.tokens_not_before {
return Err(Refused::Revoked);
}
@@ -189,6 +186,19 @@ fn user_counts(doc: &impl ReadDoc, claims: &Claims) -> Result<(), Refused> {
Ok(())
}
+/// In a swarm with a registry: user `name` registered and enabled. What a stream opened
+/// by password or a proxy's header is judged by as the document changes
+/// (`api::login::streams_end`), as one opened with a token is by `still_taken`.
+pub(crate) fn user_taken(doc: &impl ReadDoc, name: &str) -> Result<(), Refused> {
+ if registry::exists(doc) {
+ let user = registry::user(doc, name).ok_or(Refused::UnknownUser)?;
+ if user.disabled {
+ return Err(Refused::Disabled);
+ }
+ }
+ Ok(())
+}
+
/// A new session's ID (8 random bytes, hex).
pub(crate) fn new_session() -> String {
registry::new_id()