public Optional<String> getUserIdAttribute() {
        final Map<Object, Object> attributes = getAttributes();
        if (attributes == null) {
            return Optional.empty();
        }

        final Object sessionId;

        // A subject can have more than one principal. If that's the case, the user ID is required to be the first one.
        final Object principals = attributes.get(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
        if (principals instanceof Iterable) {
            sessionId = Iterables.getFirst((Iterable<?>) principals, null);
        } else {
            sessionId = principals;
        }
        return Optional.ofNullable(sessionId).map(String::valueOf);
    }
@Test
    public void noPrincipal() {
        assertThat(new MongoDbSession(fields).getUserIdAttribute()).isEmpty();
    }