@@ -9,15 +9,15 @@ use store::{NamedRows, Rows, Value};
99use trc:: AddContext ;
1010
1111use crate :: {
12+ Principal , QueryBy , ROLE_ADMIN , ROLE_USER , Type ,
1213 backend:: {
14+ RcptType ,
1315 internal:: {
16+ PrincipalField , PrincipalValue ,
1417 lookup:: DirectoryStore ,
1518 manage:: { self , ManageDirectory , UpdatePrincipal } ,
16- PrincipalField , PrincipalValue ,
1719 } ,
18- RcptType ,
1920 } ,
20- Principal , QueryBy , Type , ROLE_ADMIN , ROLE_USER ,
2121} ;
2222
2323use super :: { SqlDirectory , SqlMappings } ;
@@ -89,17 +89,43 @@ impl SqlDirectory {
8989 )
9090 . caused_by ( trc:: location!( ) ) ?
9191 {
92- Some ( principal)
92+ Some ( mut principal) => {
93+ // Obtain secrets
94+ if !self . mappings . query_secrets . is_empty ( ) {
95+ let secrets = self
96+ . sql_store
97+ . sql_query :: < Rows > (
98+ & self . mappings . query_secrets ,
99+ vec ! [ username. into( ) ] ,
100+ )
101+ . await
102+ . caused_by ( trc:: location!( ) ) ?;
103+
104+ if !secrets. rows . is_empty ( ) {
105+ principal. set (
106+ PrincipalField :: Secrets ,
107+ PrincipalValue :: StringList ( secrets. into ( ) ) ,
108+ ) ;
109+ }
110+ }
111+
93112 if principal
94113 . verify_secret ( secret)
95114 . await
96- . caused_by ( trc:: location!( ) ) ? =>
97- {
98- (
99- Some ( principal. with_field ( PrincipalField :: Name , username. to_string ( ) ) ) ,
100- None ,
101- )
115+ . caused_by ( trc:: location!( ) ) ?
116+ {
117+ (
118+ Some (
119+ principal
120+ . with_field ( PrincipalField :: Name , username. to_string ( ) ) ,
121+ ) ,
122+ None ,
123+ )
124+ } else {
125+ ( None , None )
126+ }
102127 }
128+
103129 _ => ( None , None ) ,
104130 }
105131 }
@@ -152,23 +178,6 @@ impl SqlDirectory {
152178 ) ;
153179 }
154180
155- // Obtain secrets
156- if !self . mappings . query_secrets . is_empty ( ) {
157- external_principal. set (
158- PrincipalField :: Secrets ,
159- PrincipalValue :: StringList (
160- self . sql_store
161- . sql_query :: < Rows > (
162- & self . mappings . query_secrets ,
163- vec ! [ external_principal. name( ) . into( ) ] ,
164- )
165- . await
166- . caused_by ( trc:: location!( ) ) ?
167- . into ( ) ,
168- ) ,
169- ) ;
170- }
171-
172181 // Obtain account ID if not available
173182 let mut principal = if let Some ( stored_principal) = stored_principal {
174183 stored_principal
0 commit comments