View Javadoc
1   /*
2    * Copyright (C) 2025 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
5    */
6   
7   package org.tailormap.api.security;
8   
9   import java.io.Serializable;
10  import java.util.Collection;
11  import java.util.Collections;
12  import java.util.stream.Stream;
13  import org.springframework.security.core.userdetails.UserDetails;
14  
15  public interface TailormapUserDetails extends Serializable, UserDetails {
16  
17    default Collection<TailormapAdditionalProperty> getAdditionalProperties() {
18      return Collections.emptyList();
19    }
20  
21    Collection<TailormapAdditionalProperty> getAdditionalGroupProperties();
22  
23    /**
24     * Returns true if any user or group Boolean property with the given key is true. If beside a true value, there are
25     * also properties with the same key but with any other value than true, the true value has precedence.
26     *
27     * @param key the key to look for
28     * @return true if a Boolean property with the key is present with a true value
29     */
30    default boolean hasTruePropertyForKey(String key) {
31      return streamAllPropertiesForKey(key).anyMatch(Boolean.TRUE::equals);
32    }
33  
34    default Stream<Object> streamAllPropertiesForKey(String key) {
35      return Stream.concat(getAdditionalProperties().stream(), getAdditionalGroupProperties().stream())
36          .filter(p -> p.key().equals(key))
37          .map(TailormapAdditionalProperty::value);
38    }
39  
40    String getOrganisation();
41  }