Skip to main content

openstack_keystone_core/token/
error.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//! Token provider errors.
15
16use std::num::TryFromIntError;
17
18use thiserror::Error;
19
20use crate::error::BuilderError;
21
22/// Token provider error.
23#[derive(Error, Debug)]
24pub enum TokenProviderError {
25    /// Actor has no roles on the target scope.
26    #[error("actor has no roles on scope")]
27    ActorHasNoRolesOnTarget,
28
29    /// Application Credential has expired.
30    #[error("application credential has expired")]
31    ApplicationCredentialExpired,
32
33    /// Application Credential used in the token is not found.
34    #[error("application credential with id: {0} not found")]
35    ApplicationCredentialNotFound(String),
36
37    /// Application credential provider error.
38    #[error(transparent)]
39    ApplicationCredentialProvider {
40        /// The source of the error.
41        #[from]
42        source: crate::application_credential::error::ApplicationCredentialProviderError,
43    },
44
45    /// Application Credential is bound to the other project.
46    #[error("application credential is bound to another project")]
47    ApplicationCredentialScopeMismatch,
48
49    /// Assignment provider error.
50    #[error(transparent)]
51    AssignmentProvider {
52        /// The source of the error.
53        #[from]
54        source: crate::assignment::error::AssignmentProviderError,
55    },
56
57    /// AuditID must be urlsafe base64 encoded value.
58    #[error("audit_id must be urlsafe base64 encoded value")]
59    AuditIdWrongFormat,
60
61    /// Authentication error.
62    #[error(transparent)]
63    Authentication(#[from] crate::auth::AuthenticationError),
64
65    /// Base64 Decode error.
66    #[error("b64 decryption error")]
67    Base64Decode(#[from] base64::DecodeError),
68
69    /// Conflict.
70    #[error("{message}")]
71    Conflict { message: String, context: String },
72
73    ///// Database error.
74    //#[error(transparent)]
75    //Database(#[from] DatabaseError),
76    /// The domain is disabled.
77    #[error("domain is disabled")]
78    DomainDisabled(String),
79
80    /// Driver error.
81    #[error("backend driver error: {0}")]
82    Driver(String),
83
84    /// Expired token.
85    #[error("token expired")]
86    Expired,
87
88    /// Expiry calculation error.
89    #[error("token expiry calculation failed")]
90    ExpiryCalculation,
91
92    /// Federated payload missing data error.
93    #[error("federated payload must contain idp_id and protocol_id")]
94    FederatedPayloadMissingData,
95
96    /// Fernet Decryption.
97    #[error("fernet decryption error")]
98    FernetDecryption(#[from] fernet::DecryptionError),
99
100    /// Missing fernet keys.
101    #[error("no usable fernet keys has been found")]
102    FernetKeysMissing,
103
104    /// Fernet key read error.
105    #[error("fernet key read error: {}", source)]
106    FernetKeyRead {
107        /// The source of the error.
108        source: std::io::Error,
109        /// Key file name.
110        path: std::path::PathBuf,
111    },
112
113    /// Identity provider error.
114    #[error(transparent)]
115    IdentityProvider(#[from] crate::identity::error::IdentityProviderError),
116
117    /// Invalid token data.
118    #[error("invalid token error")]
119    InvalidToken,
120
121    /// Unsupported token version.
122    #[error("token version {0} is not supported")]
123    InvalidTokenType(u8),
124
125    /// Unsupported token uuid.
126    #[error("token uuid is not supported")]
127    InvalidTokenUuid,
128
129    /// Unsupported token uuid coding.
130    #[error("token uuid coding {0:?} is not supported")]
131    InvalidTokenUuidMarker(rmp::Marker),
132
133    /// IO error.
134    #[error("io error: {}", source)]
135    Io {
136        /// The source of the error.
137        #[from]
138        source: std::io::Error,
139    },
140
141    /// Nix errno.
142    #[error("unix error {source} while {context}")]
143    NixErrno {
144        /// Context.
145        context: String,
146        /// The source of the error.
147        source: nix::errno::Errno,
148    },
149
150    /// tempfile persisting error.
151    #[error(transparent)]
152    Persist(#[from] tempfile::PersistError),
153
154    /// The project is disabled.
155    #[error("project disabled")]
156    ProjectDisabled(String),
157
158    /// Resource provider error.
159    #[error(transparent)]
160    ResourceProvider(#[from] crate::resource::error::ResourceProviderError),
161
162    /// Restricted token project scoped error.
163    #[error("token with restrictions can be only project scoped")]
164    RestrictedTokenNotProjectScoped,
165
166    /// Revoke Provider error.
167    #[error(transparent)]
168    RevokeProvider(#[from] crate::revoke::error::RevokeProviderError),
169
170    /// MSGPack Encryption.
171    #[error("rmp value encoding error")]
172    RmpEncode(String),
173
174    /// MSGPack Decryption.
175    #[error("rmp value error")]
176    RmpValueRead(#[from] rmp::decode::ValueReadError),
177
178    /// Role provider error.
179    #[error(transparent)]
180    RoleProvider {
181        /// The source of the error.
182        #[from]
183        source: crate::role::error::RoleProviderError,
184    },
185
186    /// Target scope information is not found in the token.
187    #[error("scope information missing")]
188    ScopeMissing,
189
190    /// Structures builder error.
191    #[error(transparent)]
192    StructBuilder(#[from] BuilderError),
193
194    /// Target subject information is not found in the token.
195    #[error("subject information missing")]
196    SubjectMissing,
197
198    /// Fernet payload timestamp overflow error.
199    #[error("fernet payload timestamp overflow ({value}): {}", source)]
200    TokenTimestampOverflow {
201        /// Token timestamp.
202        value: u64,
203        /// The source of the error.
204        source: std::num::TryFromIntError,
205    },
206
207    /// Token restriction not found error.
208    #[error("token restriction {0} not found")]
209    TokenRestrictionNotFound(String),
210
211    /// Revoked token error.
212    #[error("token has been revoked")]
213    TokenRevoked,
214
215    /// Trust provider error.
216    #[error(transparent)]
217    TrustProvider(#[from] crate::trust::TrustProviderError),
218
219    /// The user domain of the trustee is disabled.
220    #[error("trustee domain disabled")]
221    TrustorDomainDisabled,
222
223    /// Integer conversion error.
224    #[error("int parse")]
225    TryFromIntError(#[from] TryFromIntError),
226
227    /// Unsupported authentication methods in token payload.
228    #[error("unsupported authentication methods {0} in token payload")]
229    UnsupportedAuthMethods(String),
230
231    /// Unsupported token restriction driver.
232    #[error("driver `{0}` is not supported for the token restriction provider")]
233    UnsupportedTRDriver(String),
234
235    /// The user is disabled.
236    #[error("user disabled")]
237    UserDisabled(String),
238
239    /// The user domain is disabled.
240    #[error("user domain disabled")]
241    UserDomainDisabled,
242
243    /// The user is not trustee.
244    #[error("the token subject user is not trustee of the trust")]
245    UserIsNotTrustee,
246
247    /// The user cannot be found error.
248    #[error("user cannot be found: {0}")]
249    UserNotFound(String),
250
251    /// UUID decryption error.
252    #[error("uuid decryption error")]
253    Uuid(#[from] uuid::Error),
254
255    /// Validation error.
256    #[error("Token validation error: {0}")]
257    Validation(#[from] validator::ValidationErrors),
258}