@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 testSerializingUserDetailsShouldWorkCorrectly() throws IOException, ClassNotFoundException {
        UserDetails kermit = userDetailsService.loadUserByUsername("kermit");

        byte[] serialized;
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
        outputStream.writeObject(kermit);
        outputStream.close();
        serialized = buffer.toByteArray();

        ByteArrayInputStream inputStream = new ByteArrayInputStream(serialized);
        ObjectInputStream stream = new ObjectInputStream(inputStream);
        Object deserialized = stream.readObject();
        stream.close();

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

        kermit = (UserDetails) deserialized;
        assertThat(kermit.isCredentialsNonExpired()).as("credentialsNonExpired").isTrue();
        assertThat(kermit.isAccountNonLocked()).as("accountNonLocked").isTrue();
        assertThat(kermit.isAccountNonExpired()).as("accountNonExpired").isTrue();
        assertThat(kermit.isEnabled()).as("enabled").isTrue();
        assertThat(kermit.getUsername()).as("username").isEqualTo("kermit");
        assertThat(kermit.getPassword()).as("password").isEqualTo("kermit");
        assertThat(kermit.getAuthorities())
            .extracting(GrantedAuthority::getAuthority)
            .as("granted authorities")
            .containsExactly(
                "access admin application",
                "access modeler application",
                "start processes"
            );

        FlowableUserDetails kermitFlowable = (FlowableUserDetails) kermit;

        User user = kermitFlowable.getUser();
        assertThat(user.getId()).isEqualTo("kermit");
        assertThat(user.getFirstName()).isEqualTo("Kermit");
        assertThat(user.getLastName()).isEqualTo("the Frog");
        assertThat(user.getDisplayName()).isEqualTo("Kermit the Frog");
        assertThat(user.getEmail()).isEqualTo("kermit@muppetshow.com");
        assertThat(user.getPassword()).isEqualTo("kermit");

        assertThat(kermitFlowable.getGroups())
            .extracting(Group::getId, Group::getName, Group::getType)
            .as("Groups")
            .containsExactlyInAnyOrder(
                tuple("admins", "Admins", "user"),
                tuple("sales", "Sales", "user"),
                tuple("engineering", "Engineering", "tech")
            );
    }