@@ -48,6 +48,9 @@ pub async fn list_users() -> impl Responder {
48
48
pub async fn put_user ( username : web:: Path < String > ) -> Result < impl Responder , RBACError > {
49
49
let username = username. into_inner ( ) ;
50
50
validator:: user_name ( & username) ?;
51
+ if username == CONFIG . parseable . username {
52
+ return Err ( RBACError :: BadUser ) ;
53
+ }
51
54
let _ = UPDATE_LOCK . lock ( ) . await ;
52
55
if Users . contains ( & username) {
53
56
reset_password ( username) . await
@@ -81,6 +84,9 @@ pub async fn get_role(username: web::Path<String>) -> Result<impl Responder, RBA
81
84
// Handler for DELETE /api/v1/user/delete/{username}
82
85
pub async fn delete_user ( username : web:: Path < String > ) -> Result < impl Responder , RBACError > {
83
86
let username = username. into_inner ( ) ;
87
+ if username == CONFIG . parseable . username {
88
+ return Err ( RBACError :: BadUser ) ;
89
+ }
84
90
let _ = UPDATE_LOCK . lock ( ) . await ;
85
91
// fail this request if the user does not exists
86
92
if !Users . contains ( & username) {
@@ -125,6 +131,9 @@ pub async fn put_role(
125
131
role : web:: Json < serde_json:: Value > ,
126
132
) -> Result < String , RBACError > {
127
133
let username = username. into_inner ( ) ;
134
+ if username == CONFIG . parseable . username {
135
+ return Err ( RBACError :: BadUser ) ;
136
+ }
128
137
let role = role. into_inner ( ) ;
129
138
let role: HashSet < DefaultPrivilege > = serde_json:: from_value ( role) ?;
130
139
let role = role. into_iter ( ) . collect ( ) ;
@@ -169,6 +178,8 @@ async fn put_metadata(metadata: &StorageMetadata) -> Result<(), ObjectStorageErr
169
178
170
179
#[ derive( Debug , thiserror:: Error ) ]
171
180
pub enum RBACError {
181
+ #[ error( "Request cannot be allowed for this user" ) ]
182
+ BadUser ,
172
183
#[ error( "User exists already" ) ]
173
184
UserExists ,
174
185
#[ error( "User does not exist" ) ]
@@ -184,6 +195,7 @@ pub enum RBACError {
184
195
impl actix_web:: ResponseError for RBACError {
185
196
fn status_code ( & self ) -> http:: StatusCode {
186
197
match self {
198
+ Self :: BadUser => StatusCode :: BAD_REQUEST ,
187
199
Self :: UserExists => StatusCode :: BAD_REQUEST ,
188
200
Self :: UserDoesNotExist => StatusCode :: NOT_FOUND ,
189
201
Self :: SerdeError ( _) => StatusCode :: BAD_REQUEST ,
0 commit comments