@@ -89,7 +89,7 @@ namespace
8989 }
9090}
9191
92- bool GoogleTokenProcessor::resolveAndValidate (const TokenCredentials & credentials) const
92+ bool GoogleTokenProcessor::resolveAndValidate (TokenCredentials & credentials) const
9393{
9494 const String & token = credentials.getToken ();
9595
@@ -106,14 +106,11 @@ bool GoogleTokenProcessor::resolveAndValidate(const TokenCredentials & credentia
106106
107107 String user_name = user_info[username_claim];
108108
109-
110- // / Credentials are passed as const everywhere up the flow, so we have to comply,
111- // / in this case const_cast looks acceptable.
112- const_cast <TokenCredentials &>(credentials).setUserName (user_name);
109+ credentials.setUserName (user_name);
113110
114111 auto token_info = getObjectFromURI (Poco::URI (" https://www.googleapis.com/oauth2/v3/tokeninfo" ), token);
115112 if (token_info.contains (" exp" ))
116- const_cast <TokenCredentials &>( credentials) .setExpiresAt (std::chrono::system_clock::from_time_t ((getValueByKey<time_t >(token_info, " exp" ).value ())));
113+ credentials.setExpiresAt (std::chrono::system_clock::from_time_t ((getValueByKey<time_t >(token_info, " exp" ).value ())));
117114
118115 // / Groups info can only be retrieved if user email is known.
119116 // / If no email found in user info, we skip this step and there are no external roles for the user.
@@ -152,7 +149,7 @@ bool GoogleTokenProcessor::resolveAndValidate(const TokenCredentials & credentia
152149 }
153150 }
154151
155- const_cast <TokenCredentials &>( credentials) .setGroups (external_groups_names);
152+ credentials.setGroups (external_groups_names);
156153 }
157154 catch (const Exception & e)
158155 {
@@ -166,7 +163,7 @@ bool GoogleTokenProcessor::resolveAndValidate(const TokenCredentials & credentia
166163 return true ;
167164}
168165
169- bool AzureTokenProcessor::resolveAndValidate (const TokenCredentials & credentials) const
166+ bool AzureTokenProcessor::resolveAndValidate (TokenCredentials & credentials) const
170167{
171168 // / Token is a JWT in this case, but we cannot directly verify it against Azure AD JWKS.
172169 // / We will not trust user data in this token except for 'exp' value to determine caching duration.
@@ -180,12 +177,9 @@ bool AzureTokenProcessor::resolveAndValidate(const TokenCredentials & credential
180177 {
181178 picojson::object user_info_json = getObjectFromURI (Poco::URI (" https://graph.microsoft.com/oidc/userinfo" ), token);
182179 String username = getValueByKey (user_info_json, username_claim).value ();
180+
183181 if (!username.empty ())
184- {
185- // / Credentials are passed as const everywhere up the flow, so we have to comply,
186- // / in this case const_cast looks acceptable.
187- const_cast <TokenCredentials &>(credentials).setUserName (username);
188- }
182+ credentials.setUserName (username);
189183 else
190184 LOG_TRACE (getLogger (" TokenAuthentication" ), " {}: Failed to get username with token" , processor_name);
191185
@@ -197,7 +191,7 @@ bool AzureTokenProcessor::resolveAndValidate(const TokenCredentials & credential
197191
198192 try
199193 {
200- const_cast <TokenCredentials &>( credentials) .setExpiresAt (jwt::decode (token).get_expires_at ());
194+ credentials.setExpiresAt (jwt::decode (token).get_expires_at ());
201195 }
202196 catch (...) {
203197 LOG_TRACE (getLogger (" TokenAuthentication" ),
@@ -250,8 +244,7 @@ bool AzureTokenProcessor::resolveAndValidate(const TokenCredentials & credential
250244 return true ;
251245 }
252246
253- const_cast <TokenCredentials &>(credentials).setGroups (external_groups_names);
254-
247+ credentials.setGroups (external_groups_names);
255248 return true ;
256249}
257250
@@ -309,7 +302,7 @@ OpenIdTokenProcessor::OpenIdTokenProcessor(const String & processor_name_,
309302 }
310303}
311304
312- bool OpenIdTokenProcessor::resolveAndValidate (const TokenCredentials & credentials) const
305+ bool OpenIdTokenProcessor::resolveAndValidate (TokenCredentials & credentials) const
313306{
314307 const String & token = credentials.getToken ();
315308 String username;
@@ -325,7 +318,7 @@ bool OpenIdTokenProcessor::resolveAndValidate(const TokenCredentials & credentia
325318
326319 // / TODO: Now we work only with Keycloak -- and it provides expires_at in token itself. Need to add actual token introspection logic for other OIDC providers.
327320 if (decoded_token.has_expires_at ())
328- const_cast <TokenCredentials &>( credentials) .setExpiresAt (decoded_token.get_expires_at ());
321+ credentials.setExpiresAt (decoded_token.get_expires_at ());
329322 }
330323 catch (const std::exception & ex)
331324 {
@@ -359,9 +352,7 @@ bool OpenIdTokenProcessor::resolveAndValidate(const TokenCredentials & credentia
359352 return false ;
360353 }
361354
362- // / Credentials are passed as const everywhere up the flow, so we have to comply,
363- // / in this case const_cast is acceptable.
364- const_cast <TokenCredentials &>(credentials).setUserName (username);
355+ credentials.setUserName (username);
365356
366357 // / For now, list of groups is expected in a claim with specified name either in token itself or in userinfo response (Keycloak works this way)
367358 // / TODO: add support for custom endpoints for retrieving groups. Keycloak lists groups in /userinfo and token itself, which is not always the case.
@@ -382,7 +373,7 @@ bool OpenIdTokenProcessor::resolveAndValidate(const TokenCredentials & credentia
382373 if (group.is <std::string>())
383374 external_groups_names.insert (group.get <std::string>());
384375 }
385- const_cast <TokenCredentials &>( credentials) .setGroups (external_groups_names);
376+ credentials.setGroups (external_groups_names);
386377 }
387378
388379 return true ;
0 commit comments