@Override
    public UserDetails loadUserByUsername(String userId)
            throws UsernameNotFoundException {
        User user = null;
        try {
            user = this.identityService.createUserQuery()
                    .userId(userId)
                    .singleResult();
        } catch (FlowableException ex) {
            // don't care
        }

        if (null == user) {
            throw new UsernameNotFoundException(
                    String.format("user (%s) could not be found", userId));
        }

        return createFlowableUser(user);
    }
@Test
    public void testLoadingKnownUserWithSomePrivileges() {
        UserDetails fozzie = userDetailsService.loadUserByUsername("fozzie");

        assertThat(fozzie).isNotNull();
        assertThat(fozzie.isCredentialsNonExpired()).as("credentialsNonExpired").isTrue();
        assertThat(fozzie.isAccountNonLocked()).as("accountNonLocked").isTrue();
        assertThat(fozzie.isAccountNonExpired()).as("accountNonExpired").isTrue();
        assertThat(fozzie.isEnabled()).as("enabled").isTrue();
        assertThat(fozzie.getUsername()).as("username").isEqualTo("fozzie");
        assertThat(fozzie.getPassword()).as("password").isEqualTo("fozzie");
        assertThat(fozzie.getAuthorities())
            .extracting(GrantedAuthority::getAuthority)
            .as("granted authorities")
            .containsExactly(
                "start processes"
            );

        assertThat(fozzie).isInstanceOf(FlowableUserDetails.class);

        FlowableUserDetails fozzieFlowable = (FlowableUserDetails) fozzie;

        User user = fozzieFlowable.getUser();
        assertThat(user.getId()).isEqualTo("fozzie");
        assertThat(user.getFirstName()).isEqualTo("Fozzie");
        assertThat(user.getLastName()).isEqualTo("Bear");
        assertThat(user.getDisplayName()).isEqualTo("Fozzie Bear");
        assertThat(user.getEmail()).isEqualTo("fozzie@muppetshow.com");
        assertThat(user.getPassword()).isEqualTo("fozzie");

        user.setId("test");
        user.setFirstName("test");
        user.setLastName("test");
        user.setDisplayName("test");
        user.setEmail("test");

        assertThat(user.getId()).isEqualTo("fozzie");
        assertThat(user.getFirstName()).isEqualTo("Fozzie");
        assertThat(user.getLastName()).isEqualTo("Bear");
        assertThat(user.getDisplayName()).isEqualTo("Fozzie Bear");
        assertThat(user.getEmail()).isEqualTo("fozzie@muppetshow.com");

        assertThat(fozzieFlowable.getGroups())
            .extracting(Group::getId, Group::getName, Group::getType)
            .as("Groups")
            .containsExactlyInAnyOrder(
                tuple("sales", "Sales", "user")
            );
    }