7
7
import io .camunda .identity .sdk .IdentityConfiguration ;
8
8
import io .camunda .identity .sdk .Identity ;
9
9
import io .camunda .zeebe .spring .client .properties .*;
10
+ import org .slf4j .Logger ;
10
11
import org .springframework .beans .factory .annotation .Autowired ;
11
12
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
12
13
import org .springframework .context .annotation .Bean ;
16
17
@ EnableConfigurationProperties ({CommonConfigurationProperties .class , ZeebeSelfManagedProperties .class })
17
18
public class CommonClientConfiguration {
18
19
20
+ private final static Logger LOG = org .slf4j .LoggerFactory .getLogger (CommonClientConfiguration .class );
21
+
19
22
20
23
@ Autowired (required = false )
21
24
CommonConfigurationProperties commonConfigurationProperties ;
@@ -120,26 +123,39 @@ private JwtConfig configureJwtConfig() {
120
123
JwtConfig jwtConfig = new JwtConfig ();
121
124
// ZEEBE
122
125
if (zeebeClientConfigurationProperties .getCloud ().getClientId () != null && zeebeClientConfigurationProperties .getCloud ().getClientSecret () != null ) {
126
+ LOG .info ("Using Cloud properties to determine credentials for Zeebe" );
123
127
jwtConfig .addProduct (Product .ZEEBE , new JwtCredential (
124
128
zeebeClientConfigurationProperties .getCloud ().getClientId (),
125
129
zeebeClientConfigurationProperties .getCloud ().getClientSecret (),
126
130
zeebeClientConfigurationProperties .getCloud ().getAudience (),
127
131
zeebeClientConfigurationProperties .getCloud ().getAuthUrl ())
128
132
);
129
133
} else if (zeebeSelfManagedProperties .getClientId () != null && zeebeSelfManagedProperties .getClientSecret () != null ) {
134
+ LOG .info ("Using Self Managed properties to determine credentials for Zeebe" );
130
135
jwtConfig .addProduct (Product .ZEEBE , new JwtCredential (
131
136
zeebeSelfManagedProperties .getClientId (),
132
137
zeebeSelfManagedProperties .getClientSecret (),
133
138
zeebeSelfManagedProperties .getAudience (),
134
139
zeebeSelfManagedProperties .getAuthServer ())
135
140
);
136
141
} else if (commonConfigurationProperties .getClientId () != null && commonConfigurationProperties .getClientSecret () != null ) {
142
+ LOG .info ("Using Common properties to determine credentials for Zeebe" );
137
143
jwtConfig .addProduct (Product .ZEEBE , new JwtCredential (
138
144
commonConfigurationProperties .getClientId (),
139
145
commonConfigurationProperties .getClientSecret (),
140
146
zeebeClientConfigurationProperties .getCloud ().getAudience (),
141
147
zeebeClientConfigurationProperties .getCloud ().getAuthUrl ())
142
148
);
149
+ } else if (identityConfigurationFromProperties != null
150
+ && hasText (identityConfigurationFromProperties .getClientId ())
151
+ && hasText (identityConfigurationFromProperties .getClientSecret ())) {
152
+ LOG .info ("Using Identity SDK credentials for Zeebe" );
153
+ jwtConfig .addProduct (Product .ZEEBE , new JwtCredential (
154
+ identityConfigurationFromProperties .getClientId (),
155
+ identityConfigurationFromProperties .getClientSecret (),
156
+ identityConfigurationFromProperties .getAudience (),
157
+ identityConfigurationFromProperties .getIssuerBackendUrl ())
158
+ );
143
159
}
144
160
145
161
// OPERATE
@@ -160,20 +176,25 @@ private JwtConfig configureJwtConfig() {
160
176
}
161
177
162
178
if (operateClientConfigurationProperties .getClientId () != null && operateClientConfigurationProperties .getClientSecret () != null ) {
179
+ LOG .info ("Using Operate Client properties to determine credentials for Operate" );
163
180
jwtConfig .addProduct (Product .OPERATE , new JwtCredential (operateClientConfigurationProperties .getClientId (), operateClientConfigurationProperties .getClientSecret (), operateAudience , operateAuthUrl ));
164
181
} else if (identityConfigurationFromProperties != null && hasText (identityConfigurationFromProperties .getClientId ()) && hasText (identityConfigurationFromProperties .getClientSecret ())) {
182
+ LOG .info ("Using Identity SDK credentials for Operate" );
165
183
jwtConfig .addProduct (Product .OPERATE , new JwtCredential (identityConfigurationFromProperties .getClientId (), identityConfigurationFromProperties .getClientSecret (), identityConfigurationFromProperties .getAudience (), identityConfigurationFromProperties .getIssuerBackendUrl ()));
166
184
}
167
185
else if (commonConfigurationProperties .getClientId () != null && commonConfigurationProperties .getClientSecret () != null ) {
186
+ LOG .info ("Using Common properties to determine credentials for Operate" );
168
187
jwtConfig .addProduct (Product .OPERATE , new JwtCredential (
169
188
commonConfigurationProperties .getClientId (),
170
189
commonConfigurationProperties .getClientSecret (),
171
190
operateAudience ,
172
191
operateAuthUrl )
173
192
);
174
193
} else if (zeebeClientConfigurationProperties .getCloud ().getClientId () != null && zeebeClientConfigurationProperties .getCloud ().getClientSecret () != null ) {
194
+ LOG .info ("Using Zeebe Cloud properties to determine credentials for Operate" );
175
195
jwtConfig .addProduct (Product .OPERATE , new JwtCredential (zeebeClientConfigurationProperties .getCloud ().getClientId (), zeebeClientConfigurationProperties .getCloud ().getClientSecret (), operateAudience , operateAuthUrl ));
176
196
} else if (zeebeSelfManagedProperties .getClientId () != null && zeebeSelfManagedProperties .getClientSecret () != null ) {
197
+ LOG .info ("Using Zeebe Self Managed properties to determine credentials for Operate" );
177
198
jwtConfig .addProduct (Product .OPERATE , new JwtCredential (zeebeSelfManagedProperties .getClientId (), zeebeSelfManagedProperties .getClientSecret (), operateAudience , operateAuthUrl ));
178
199
} else {
179
200
throw new SdkException ("Unable to determine OPERATE credentials" );
@@ -191,6 +212,11 @@ private IdentityConfig configureIdentities(JwtConfig jwtConfig) {
191
212
IdentityContainer operateIdentityContainer = configureOperateIdentityContainer (jwtConfig );
192
213
identityConfig .addProduct (Product .OPERATE , operateIdentityContainer );
193
214
}
215
+ // ZEEBE
216
+ if (zeebeClientConfigurationProperties != null ) {
217
+ IdentityContainer zeebeIdentityContainer = configureZeebeIdentityContainer (jwtConfig );
218
+ identityConfig .addProduct (Product .ZEEBE , zeebeIdentityContainer );
219
+ }
194
220
return identityConfig ;
195
221
}
196
222
@@ -227,4 +253,32 @@ private IdentityContainer configureOperateIdentityContainer(JwtConfig jwtConfig)
227
253
Identity operateIdentity = new Identity (operateIdentityConfiguration );
228
254
return new IdentityContainer (operateIdentity , operateIdentityConfiguration );
229
255
}
256
+
257
+ private IdentityContainer configureZeebeIdentityContainer (JwtConfig jwtConfig ) {
258
+ String issuer ;
259
+ String issuerBackendUrl ;
260
+ if (hasText (identityConfigurationFromProperties .getIssuer ())) {
261
+ issuer = identityConfigurationFromProperties .getIssuer ();
262
+ } else {
263
+ issuer = jwtConfig .getProduct (Product .ZEEBE ).getAuthUrl ();
264
+ }
265
+
266
+ if (hasText (identityConfigurationFromProperties .getIssuerBackendUrl ())) {
267
+ issuerBackendUrl = identityConfigurationFromProperties .getIssuerBackendUrl ();
268
+ } else {
269
+ issuerBackendUrl = jwtConfig .getProduct (Product .ZEEBE ).getAuthUrl ();
270
+ }
271
+
272
+ IdentityConfiguration zeebeIdentityConfiguration = new IdentityConfiguration .Builder ()
273
+ .withBaseUrl (identityConfigurationFromProperties .getBaseUrl ())
274
+ .withIssuer (issuer )
275
+ .withIssuerBackendUrl (issuerBackendUrl )
276
+ .withClientId (jwtConfig .getProduct (Product .ZEEBE ).getClientId ())
277
+ .withClientSecret (jwtConfig .getProduct (Product .ZEEBE ).getClientSecret ())
278
+ .withAudience (jwtConfig .getProduct (Product .ZEEBE ).getAudience ())
279
+ .withType (identityConfigurationFromProperties .getType ().name ())
280
+ .build ();
281
+ Identity zeebeIdentity = new Identity (zeebeIdentityConfiguration );
282
+ return new IdentityContainer (zeebeIdentity , zeebeIdentityConfiguration );
283
+ }
230
284
}
0 commit comments