Skip to content

Commit

Permalink
Fix NPE when storing user photo in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Dec 10, 2020
1 parent 422cb41 commit 448957f
Showing 1 changed file with 5 additions and 8 deletions.
Expand Up @@ -84,8 +84,9 @@ public void compileUserProfile(GuiProfiledPrincipal principal, PrismObject<Syste
collect(adminGuiConfigurations, principal, authorizationTransformer, task, result);

CompiledGuiProfile compiledGuiProfile = compileUserProfile(adminGuiConfigurations, systemConfiguration, task, result);

setupUserPhoto(principal, compiledGuiProfile, result);
if (compiledGuiProfile != null) {
setupUserPhoto(principal, compiledGuiProfile, result);
}

principal.setCompiledGuiProfile(compiledGuiProfile);
}
Expand Down Expand Up @@ -157,20 +158,16 @@ public CompiledGuiProfile compileUserProfile(@NotNull List<AdminGuiConfiguration
return composite;
}

private void setupUserPhoto(GuiProfiledPrincipal principal, CompiledGuiProfile compiledGuiProfile, OperationResult result) {
private void setupUserPhoto(GuiProfiledPrincipal principal, @NotNull CompiledGuiProfile compiledGuiProfile, OperationResult result) {
FocusType focus = principal.getFocus();
if (focus == null) {
return; // should not be null, but just to be sure
}

byte[] jpegPhoto = focus.getJpegPhoto();
if (jpegPhoto == null) {
Collection<SelectorOptions<GetOperationOptions>> options = schemaHelper.getOperationOptionsBuilder().item(FocusType.F_JPEG_PHOTO).retrieve().build();
try {
PrismObject<? extends FocusType> resolvedFocus = repositoryService.getObject(focus.getClass(), focus.getOid(), options, result);
jpegPhoto = resolvedFocus.asObjectable().getJpegPhoto();
} catch (ObjectNotFoundException | SchemaException e) {
LOGGER.trace("Failed to load photo, continue without it");
LOGGER.trace("Failed to load photo for {}, continue without it", focus, e);
}
}
compiledGuiProfile.setJpegPhoto(jpegPhoto);
Expand Down

0 comments on commit 448957f

Please sign in to comment.