3030import org .apache .nifi .migration .PropertyConfiguration ;
3131import org .apache .nifi .processor .exception .ProcessException ;
3232import org .apache .nifi .processor .util .StandardValidators ;
33+ import org .apache .nifi .services .azure .util .OAuth2AccessTokenAdapter ;
34+ import reactor .core .publisher .Mono ;
3335
3436import java .util .List ;
3537
@@ -47,12 +49,15 @@ public class StandardAzureCredentialsControllerService extends AbstractControlle
4749 public static AllowableValue MANAGED_IDENTITY = new AllowableValue ("managed-identity" ,
4850 "Managed Identity" ,
4951 "Azure Virtual Machine Managed Identity (it can only be used when NiFi is running on Azure)" );
52+ public static AllowableValue OAUTH2 = new AllowableValue ("oauth2-access-token" ,
53+ "OAuth2 Access Token" ,
54+ "Uses an OAuth2 Access Token Provider controller service to obtain access tokens for Azure clients." );
5055 public static final PropertyDescriptor CREDENTIAL_CONFIGURATION_STRATEGY = new PropertyDescriptor .Builder ()
5156 .name ("Credential Configuration Strategy" )
5257 .expressionLanguageSupported (ExpressionLanguageScope .NONE )
5358 .required (true )
5459 .sensitive (false )
55- .allowableValues (DEFAULT_CREDENTIAL , MANAGED_IDENTITY )
60+ .allowableValues (DEFAULT_CREDENTIAL , MANAGED_IDENTITY , OAUTH2 )
5661 .defaultValue (DEFAULT_CREDENTIAL )
5762 .build ();
5863
@@ -67,9 +72,18 @@ public class StandardAzureCredentialsControllerService extends AbstractControlle
6772 .dependsOn (CREDENTIAL_CONFIGURATION_STRATEGY , MANAGED_IDENTITY )
6873 .build ();
6974
75+ public static final PropertyDescriptor OAUTH2_ACCESS_TOKEN_PROVIDER = new PropertyDescriptor .Builder ()
76+ .name ("Azure Identity Federation Token Provider" )
77+ .description ("Controller Service used to obtain Azure access tokens via workload identity federation." )
78+ .identifiesControllerService (AzureIdentityFederationTokenProvider .class )
79+ .required (true )
80+ .dependsOn (CREDENTIAL_CONFIGURATION_STRATEGY , OAUTH2 )
81+ .build ();
82+
7083 private static final List <PropertyDescriptor > PROPERTY_DESCRIPTORS = List .of (
7184 CREDENTIAL_CONFIGURATION_STRATEGY ,
72- MANAGED_IDENTITY_CLIENT_ID
85+ MANAGED_IDENTITY_CLIENT_ID ,
86+ OAUTH2_ACCESS_TOKEN_PROVIDER
7387 );
7488
7589 private TokenCredential credentials ;
@@ -92,6 +106,8 @@ public void onConfigured(final ConfigurationContext context) {
92106 credentials = getDefaultAzureCredential ();
93107 } else if (MANAGED_IDENTITY .getValue ().equals (configurationStrategy )) {
94108 credentials = getManagedIdentityCredential (context );
109+ } else if (OAUTH2 .getValue ().equals (configurationStrategy )) {
110+ credentials = getOAuth2Credential (context );
95111 } else {
96112 final String errorMsg = String .format ("Configuration Strategy [%s] not recognized" , configurationStrategy );
97113 getLogger ().error (errorMsg );
@@ -117,6 +133,13 @@ private TokenCredential getManagedIdentityCredential(final ConfigurationContext
117133 .build ();
118134 }
119135
136+ private TokenCredential getOAuth2Credential (final ConfigurationContext context ) {
137+ final AzureIdentityFederationTokenProvider oauth2AccessTokenProvider = context .getProperty (OAUTH2_ACCESS_TOKEN_PROVIDER )
138+ .asControllerService (AzureIdentityFederationTokenProvider .class );
139+ return tokenRequestContext -> Mono .fromSupplier (() ->
140+ OAuth2AccessTokenAdapter .toAzureAccessToken (oauth2AccessTokenProvider .getAccessDetails ()));
141+ }
142+
120143 @ Override
121144 public String toString () {
122145 return "StandardAzureCredentialsControllerService[id=" + getIdentifier () + "]" ;
0 commit comments