1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use std::{fmt::Debug, sync::Arc};

use oxinat_derive::uri_builder_alias;

use crate::{UriBuilder, Version};

uri_builder_alias!(AuthenticateUriBuilder);
ImplAuthenticateUriBuilder! {
    (String),
}

/// Represent the URI paths responsible for user
/// authentication.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}")]
pub struct AuthUriLegacyBuilder<Parent>
where
    Parent: AuthenticateUriBuilder
{
    #[parent]
    parent: Option<Arc<Parent>>
}

/// Represents the URI paths responsible for
/// specific actions meant for user authentication.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/services")]
pub struct ServicesUriBuilder<'a> {
    #[parent]
    parent: Option<&'a AuthUriLegacyBuilder<String>>
}

/// Represents the URI paths available for user
/// token management.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/tokens")]
pub struct TokensUriBuilder<'a> {
    #[parent]
    parent: Option<&'a ServicesUriBuilder<'a>>
}

/// Represents the URI paths available to issue
/// a user authentication.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/issue")]
#[match_path(path = "{parent}/issue/user/{username}")]
pub struct IssueUserUriBuilder<'a> {
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<&'a TokensUriBuilder<'a>>
}

/// Represents the URI paths available to validate
/// user tokens.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/validate/{token}/{secret}")]
pub struct ValidateUserUriBuilder<'a> {
    #[param]
    secret: Option<String>,
    #[param]
    token: Option<String>,
    #[parent]
    parent: Option<&'a TokensUriBuilder<'a>>
}

/// Represents the URI paths available to
/// invalidate user tokens.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/invalidate/{token}/{secret}")]
pub struct InValidateUserUriBuilder<'a> {
    #[param]
    secret: Option<String>,
    #[param]
    token: Option<String>,
    #[parent]
    parent: Option<&'a TokensUriBuilder<'a>>
}

impl TokensUriBuilder<'_> {
    /// Continue the builder into a
    /// `ValidateUserUriBuilder`
    pub fn invalidate(&self) -> InValidateUserUriBuilder {
        InValidateUserUriBuilder::from_parent(self)
    }

    /// Continue the builder into a
    /// `IssueUserUriBuilder`.
    pub fn issue(&self) -> IssueUserUriBuilder {
        IssueUserUriBuilder::from_parent(self)
    }

    /// Continue the builder into a
    /// `ValidateUserUriBuilder`
    pub fn validate(&self) -> ValidateUserUriBuilder {
        ValidateUserUriBuilder::from_parent(self)
    }
}

impl ServicesUriBuilder<'_> {
    /// Produces the endpoint used to request a
    /// new user session.
    pub fn build_auth(&self) -> crate::BuildResult {
        self.build_join("auth")
    }

    /// Continue the builder into a
    /// `TokensUriBuilder`.
    pub fn tokens(&self) -> TokensUriBuilder {
        TokensUriBuilder::from_parent(self)
    }
}

impl AuthUriLegacyBuilder<String> {
    /// Produces the endpoint used for managing
    /// the logged in user's session.
    pub fn build_jsessionid(&self) -> crate::BuildResult {
        self.build_join("JSESSIONID")
    }

    /// Continue the builder into a
    /// `AuthServicesUriBuilder`.
    pub fn services(&self) -> ServicesUriBuilder {
        ServicesUriBuilder::from_parent(&Arc::new(self))
    }
}

/// Represents the URI paths available for user
/// authentication.
pub trait AuthUriLegacy: Version {
    fn auth_legacy(&self) -> AuthUriLegacyBuilder<String> {
        AuthUriLegacyBuilder::from_parent(self.data_uri().into())
    }
}