mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-15 22:32:13 +00:00
rename
This commit is contained in:
1 parent
f73add81ef
commit
3792cf82f2
6 files changed
+24
-24
No files matched your search
@@ -10,7 +10,7 @@ use log::warn;
|
||||
|
||||
use crate::sessions::http_user_session_payload::HttpUserSessionPayload;
|
||||
use crate::sessions::http_user_session_payload_signer::HttpUserSessionPayloadSigner;
|
||||
use crate::sessions::session_error::SessionError;
|
||||
use crate::sessions::http_user_session_payload_error::HttpUserSessionPayloadError;
|
||||
use tokens::tokens::user_sessions::UserSessionToken;
|
||||
use tokens::tokens::users::UserToken;
|
||||
|
||||
@@ -30,7 +30,7 @@ pub struct HttpUserSessionManager {
|
||||
}
|
||||
|
||||
impl HttpUserSessionManager {
|
||||
pub fn new(cookie_domain: &str, hmac_secret: &str) -> Result<Self, SessionError> {
|
||||
pub fn new(cookie_domain: &str, hmac_secret: &str) -> Result<Self, HttpUserSessionPayloadError> {
|
||||
let payload_signer = HttpUserSessionPayloadSigner::new(hmac_secret)
|
||||
.map_err(|e| {
|
||||
warn!("Failed to construct HttpUserSessionPayloadSigner: {}", e);
|
||||
@@ -47,7 +47,7 @@ impl HttpUserSessionManager {
|
||||
&self,
|
||||
session_token: &UserSessionToken,
|
||||
user_token: &UserToken,
|
||||
) -> Result<String, SessionError> {
|
||||
) -> Result<String, HttpUserSessionPayloadError> {
|
||||
self.payload_signer.encode(session_token, user_token)
|
||||
.map_err(|e| {
|
||||
warn!("Failed to encode session payload: {}", e);
|
||||
@@ -59,7 +59,7 @@ impl HttpUserSessionManager {
|
||||
&self,
|
||||
session_token: &UserSessionToken,
|
||||
user_token: &UserToken,
|
||||
) -> Result<Cookie, SessionError> {
|
||||
) -> Result<Cookie, HttpUserSessionPayloadError> {
|
||||
let jwt_string = self.payload_signer.encode(session_token, user_token)
|
||||
.map_err(|e| {
|
||||
warn!("Failed to encode session cookie payload: {}", e);
|
||||
@@ -98,7 +98,7 @@ impl HttpUserSessionManager {
|
||||
pub fn decode_session_payload_from_request(
|
||||
&self,
|
||||
request: &HttpRequest,
|
||||
) -> Result<Option<HttpUserSessionPayload>, SessionError>
|
||||
) -> Result<Option<HttpUserSessionPayload>, HttpUserSessionPayloadError>
|
||||
{
|
||||
let signed_session_payload = self.session_payload_from_request(request)?;
|
||||
|
||||
@@ -121,7 +121,7 @@ impl HttpUserSessionManager {
|
||||
pub fn check_and_return_session_token_decodes(
|
||||
&self,
|
||||
request: &HttpRequest,
|
||||
) -> Result<Option<String>, SessionError> {
|
||||
) -> Result<Option<String>, HttpUserSessionPayloadError> {
|
||||
let signed_session_payload = self.session_payload_from_request(request)?;
|
||||
|
||||
let signed_session_payload = match signed_session_payload {
|
||||
@@ -143,7 +143,7 @@ impl HttpUserSessionManager {
|
||||
fn session_payload_from_request(
|
||||
&self,
|
||||
request: &HttpRequest,
|
||||
) -> Result<Option<String>, SessionError> {
|
||||
) -> Result<Option<String>, HttpUserSessionPayloadError> {
|
||||
let mut signed_session_payload = request.cookie(SESSION_COOKIE_NAME)
|
||||
.map(|cookie| cookie.value().to_string());
|
||||
|
||||
@@ -153,7 +153,7 @@ impl HttpUserSessionManager {
|
||||
let header_str = header.to_str()
|
||||
.map_err(|e| {
|
||||
warn!("Failed to read session HTTP header as str: {}", e);
|
||||
SessionError::HttpSessionHeaderError(e.to_string())
|
||||
HttpUserSessionPayloadError::HttpSessionHeaderError(e.to_string())
|
||||
})?;
|
||||
signed_session_payload = Some(header_str.to_string());
|
||||
}
|
||||
|
||||
+4
-4
@@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter};
|
||||
use jwt_signer::jwt_signer_error::JwtSignerError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SessionError {
|
||||
pub enum HttpUserSessionPayloadError {
|
||||
/// Error reading HTTP header
|
||||
HttpSessionHeaderError(String),
|
||||
|
||||
@@ -12,7 +12,7 @@ pub enum SessionError {
|
||||
JwtSigner(JwtSignerError),
|
||||
}
|
||||
|
||||
impl Display for SessionError {
|
||||
impl Display for HttpUserSessionPayloadError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::HttpSessionHeaderError(msg) => write!(f, "HTTP session header error: {}", msg),
|
||||
@@ -21,9 +21,9 @@ impl Display for SessionError {
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for SessionError {}
|
||||
impl Error for HttpUserSessionPayloadError {}
|
||||
|
||||
impl From<JwtSignerError> for SessionError {
|
||||
impl From<JwtSignerError> for HttpUserSessionPayloadError {
|
||||
fn from(err: JwtSignerError) -> Self {
|
||||
Self::JwtSigner(err)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::sessions::http_user_session_payload::HttpUserSessionPayload;
|
||||
use crate::sessions::session_error::SessionError;
|
||||
use crate::sessions::http_user_session_payload_error::HttpUserSessionPayloadError;
|
||||
use jwt_signer::jwt_signer::JwtSigner;
|
||||
use tokens::tokens::user_sessions::UserSessionToken;
|
||||
use tokens::tokens::users::UserToken;
|
||||
@@ -21,7 +21,7 @@ pub struct HttpUserSessionPayloadSigner {
|
||||
}
|
||||
|
||||
impl HttpUserSessionPayloadSigner {
|
||||
pub fn new(hmac_secret: &str) -> Result<Self, SessionError> {
|
||||
pub fn new(hmac_secret: &str) -> Result<Self, HttpUserSessionPayloadError> {
|
||||
Ok(Self {
|
||||
jwt_signer: JwtSigner::new(hmac_secret)?,
|
||||
})
|
||||
@@ -31,7 +31,7 @@ impl HttpUserSessionPayloadSigner {
|
||||
&self,
|
||||
session_token: &UserSessionToken,
|
||||
user_token: &UserToken,
|
||||
) -> Result<String, SessionError> {
|
||||
) -> Result<String, HttpUserSessionPayloadError> {
|
||||
let mut claims: BTreeMap<&str, &str> = BTreeMap::new();
|
||||
let payload_version = PAYLOAD_VERSION.to_string();
|
||||
|
||||
@@ -46,7 +46,7 @@ impl HttpUserSessionPayloadSigner {
|
||||
pub fn decode(
|
||||
&self,
|
||||
session_payload_contents: &str,
|
||||
) -> Result<HttpUserSessionPayload, SessionError> {
|
||||
) -> Result<HttpUserSessionPayload, HttpUserSessionPayloadError> {
|
||||
let claims = self.jwt_signer.jwt_to_claims(session_payload_contents)?;
|
||||
|
||||
let session_token = claims["session_token"].clone();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod http_user_session_manager;
|
||||
pub mod http_user_session_payload;
|
||||
pub mod http_user_session_payload_signer;
|
||||
pub mod session_error;
|
||||
pub mod http_user_session_payload_error;
|
||||
pub mod http_user_session_payload_signer;
|
||||
+2
-2
@@ -194,8 +194,8 @@ impl From<RequireUserSessionError> for AdvancedCommonWebError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix_artcraft::sessions::session_error::SessionError> for AdvancedCommonWebError {
|
||||
fn from(_value: actix_artcraft::sessions::session_error::SessionError) -> Self {
|
||||
impl From<actix_artcraft::sessions::http_user_session_payload_error::HttpUserSessionPayloadError> for AdvancedCommonWebError {
|
||||
fn from(_value: actix_artcraft::sessions::http_user_session_payload_error::HttpUserSessionPayloadError) -> Self {
|
||||
// Any session error (bad header, bad JWT, construction failure) becomes 401.
|
||||
Self::NotAuthorized
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use actix_artcraft::sessions::session_error::SessionError;
|
||||
use actix_artcraft::sessions::http_user_session_payload_error::HttpUserSessionPayloadError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SessionCheckerError {
|
||||
@@ -9,7 +9,7 @@ pub enum SessionCheckerError {
|
||||
/// Rate of failures can point to the cause:
|
||||
/// - One-off errors: probably session forgeries
|
||||
/// - Lots of errors: maybe the wrong hmac secret
|
||||
Session(SessionError),
|
||||
Session(HttpUserSessionPayloadError),
|
||||
|
||||
/// Error looking up the session from the database.
|
||||
Sqlx(sqlx::Error),
|
||||
@@ -30,8 +30,8 @@ impl Display for SessionCheckerError {
|
||||
|
||||
impl Error for SessionCheckerError {}
|
||||
|
||||
impl From<SessionError> for SessionCheckerError {
|
||||
fn from(err: SessionError) -> Self {
|
||||
impl From<HttpUserSessionPayloadError> for SessionCheckerError {
|
||||
fn from(err: HttpUserSessionPayloadError) -> Self {
|
||||
Self::Session(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user