@@ -174,35 +174,29 @@ private static ExpressionMatcher createExpressionMatcher(final ExpressionMatcher
174
174
public Optional <FeedDoc > tryCreateFeed (final String feedName ,
175
175
final UserDesc userDesc ,
176
176
final AttributeMap attributeMap ) {
177
- Objects .requireNonNull (userDesc );
178
177
LOGGER .debug ("tryCreateFeed - feedName: {}, userRef: {}, attributeMap: {}" ,
179
178
feedName , userDesc , attributeMap );
180
179
181
- if (isEligibleForAutoCreation (userDesc , attributeMap )) {
182
- // Content gets created as the configured user
183
- final UserRef runAsUserRef = getRunAsUser ();
180
+ // Content gets created as the configured user
181
+ final UserRef runAsUserRef = getRunAsUser ();
184
182
185
- final Optional <FeedDoc > optFeedDoc = securityContext .asUserResult (runAsUserRef , () ->
186
- ensureFeed (feedName , userDesc , attributeMap ));
183
+ final Optional <FeedDoc > optFeedDoc = securityContext .asUserResult (runAsUserRef , () ->
184
+ ensureFeed (feedName , userDesc , attributeMap ));
187
185
188
- LOGGER .debug ("feedName: '{}', userDesc: '{}', optFeedDoc: {}" ,
189
- feedName , userDesc , optFeedDoc );
186
+ LOGGER .debug ("feedName: '{}', userDesc: '{}', optFeedDoc: {}" ,
187
+ feedName , userDesc , optFeedDoc );
190
188
191
- return optFeedDoc ;
192
- } else {
193
- LOGGER .debug ("Not eligible for auto-creation" );
194
- return Optional .empty ();
195
- }
189
+ return optFeedDoc ;
196
190
}
197
191
198
- private boolean isEligibleForAutoCreation (final UserDesc userDesc ,
199
- final AttributeMap attributeMap ) {
200
- return NullSafe .allNonNull (userDesc , userDesc .getSubjectId (), attributeMap )
201
- && attributeMap .containsKey (StandardHeaderArguments .ACCOUNT_ID )
202
- && attributeMap .containsKey (StandardHeaderArguments .COMPONENT )
203
- && attributeMap .containsKey (StandardHeaderArguments .SCHEMA )
204
- && attributeMap .containsKey (StandardHeaderArguments .FORMAT );
205
- }
192
+ // private boolean isEligibleForAutoCreation(final UserDesc userDesc,
193
+ // final AttributeMap attributeMap) {
194
+ // return NullSafe.allNonNull(userDesc, userDesc.getSubjectId(), attributeMap)
195
+ // && attributeMap.containsKey(StandardHeaderArguments.ACCOUNT_ID)
196
+ // && attributeMap.containsKey(StandardHeaderArguments.COMPONENT)
197
+ // && attributeMap.containsKey(StandardHeaderArguments.SCHEMA)
198
+ // && attributeMap.containsKey(StandardHeaderArguments.FORMAT);
199
+ // }
206
200
207
201
private UserRef getRunAsUser () {
208
202
final AutoContentCreationConfig autoContentCreationConfig = autoContentCreationConfigProvider .get ();
@@ -265,32 +259,44 @@ private DocRef doCreateFeed(final String feedName,
265
259
final UserDesc userDesc ,
266
260
final AttributeMap attributeMap ) {
267
261
268
- final String destinationPath = cachedDestinationPathTemplator .getValue ().apply (attributeMap );
262
+ final String destinationPath = cachedDestinationPathTemplator .getValue ()
263
+ .apply (attributeMap );
269
264
final DocPath docPath = DocPath .fromPathString (destinationPath );
270
265
271
266
LOGGER .info ("Ensuring path '{}' exists" , docPath );
272
267
final ExplorerNode destFolder = explorerService .ensureFolderPath (docPath , PermissionInheritance .DESTINATION );
273
268
final DocRef destFolderRef = destFolder .getDocRef ();
269
+ final UserRef userRef ;
274
270
275
- LOGGER .info ("Ensuing user with userRef: '{}' exists" , userDesc );
276
- final User user = userService .getOrCreateUser (userDesc );
277
- final UserRef userRef = user .asRef ();
271
+ if (userDesc != null ) {
272
+ LOGGER .info ("Ensuing user with userRef: '{}' exists" , userDesc );
273
+ final User user = userService .getOrCreateUser (userDesc );
274
+ userRef = user .asRef ();
275
+ } else {
276
+ LOGGER .info ("No user details, won't ensure Stroom user or add any users to groups." );
277
+ userRef = null ;
278
+ }
278
279
279
280
final String groupName = cachedGroupTemplator .getValue ().apply (attributeMap );
280
- LOGGER .info ("Auto-creating user group '{}', and adding userRef {} to it" ,
281
- groupName , userRef );
281
+ LOGGER .info ("Auto-creating user group '{}'" , groupName );
282
282
final User group = userService .getOrCreateUserGroup (groupName );
283
283
addAppPerms (group );
284
- userService .addUserToGroup (userRef , group .asRef ());
284
+ if (userRef != null ) {
285
+ LOGGER .info ("Adding userRef {} to group '{}" , userRef , groupName );
286
+ userService .addUserToGroup (userRef , group .asRef ());
287
+ }
285
288
286
289
Optional <User > optAdditionalGroup = Optional .empty ();
287
- final String additionalGroupName = cachedAdditionalGroupTemplator .getValue ().apply (attributeMap );
290
+ final String additionalGroupName = cachedAdditionalGroupTemplator .getValue ()
291
+ .apply (attributeMap );
288
292
if (NullSafe .isNonBlankString (additionalGroupName )) {
289
- LOGGER .info ("Auto-creating additional user group '{}', and adding userRef {} to it" ,
290
- additionalGroupName , userRef );
293
+ LOGGER .info ("Auto-creating user group '{}'" , additionalGroupName );
291
294
final User additionalGroup = userService .getOrCreateUserGroup (additionalGroupName );
292
295
addAppPerms (additionalGroup );
293
- userService .addUserToGroup (userRef , additionalGroup .asRef ());
296
+ if (userRef != null ) {
297
+ LOGGER .info ("Adding userRef {} to additional group '{}" , userRef , additionalGroupName );
298
+ userService .addUserToGroup (userRef , additionalGroup .asRef ());
299
+ }
294
300
optAdditionalGroup = Optional .of (additionalGroup );
295
301
}
296
302
@@ -338,7 +344,11 @@ private void configureFeed(final FeedDoc feedDoc,
338
344
}
339
345
});
340
346
341
- feedDoc .setDescription ("Auto-created for user '" + userRef .toDisplayString () + "'" );
347
+ if (userRef != null ) {
348
+ feedDoc .setDescription ("Auto-created for user '" + userRef .toDisplayString () + "'" );
349
+ } else {
350
+ feedDoc .setDescription ("Auto-created" );
351
+ }
342
352
feedDoc .setStatus (FeedStatus .RECEIVE );
343
353
344
354
consumeAttrVal (attributeMap , StandardHeaderArguments .ENCODING , val ->
0 commit comments