class LoadLinkedUserAuthorizationGenerator implements AuthorizationGenerator {

    private ProfileService profileService;

    private boolean failIfLinkedUserNotFound = true;

    /**
     * <p>Constructor for LoadLinkedUserAuthorizationGenerator.</p>
     */
    public LoadLinkedUserAuthorizationGenerator() {}

    /**
     * <p>Constructor for LoadLinkedUserAuthorizationGenerator.</p>
     *
     * @param profileService a {@link ProfileService} object
     */
    public LoadLinkedUserAuthorizationGenerator(final ProfileService profileService) {
        this.profileService = profileService;
    }

    /** {@inheritDoc} */
    @Override
    public Optional<UserProfile> generate(final CallContext ctx, final UserProfile profile) {<FILL_FUNCTION_BODY>}
}

        CommonHelper.assertNotNull("profileService", profileService);

        val linkedProfile = profileService.findByLinkedId(profile.getId());

        if (linkedProfile != null) {
            return Optional.ofNullable(linkedProfile);
        } else {
            if (failIfLinkedUserNotFound) {
                throw new TechnicalException("No linked account found for: " + profile);
            } else {
                // fallback to the original account
                return Optional.ofNullable(profile);
            }
        }
    
<no_super_class>