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.stream.Stream;
12  import org.springframework.security.core.userdetails.UserDetails;
13  
14  public interface TailormapUserDetails extends Serializable, UserDetails {
15  
16    Collection<TailormapAdditionalProperty> getAdditionalProperties();
17  
18    Collection<TailormapAdditionalProperty> getAdditionalGroupProperties();
19  
20    /**
21     * Returns true if any user or group Boolean property with the given key is true. If beside a true value, there are
22     * also properties with the same key but with any other value than true, the true value has precedence.
23     *
24     * @param key the key to look for
25     * @return true if a Boolean property with the key is present with a true value
26     */
27    default boolean hasTruePropertyForKey(String key) {
28      return streamAllPropertiesForKey(key).anyMatch(Boolean.TRUE::equals);
29    }
30  
31    default Stream<Object> streamAllPropertiesForKey(String key) {
32      return Stream.concat(getAdditionalProperties().stream(), getAdditionalGroupProperties().stream())
33          .filter(p -> p.key().equals(key))
34          .map(TailormapAdditionalProperty::value);
35    }
36  
37    String getOrganisation();
38  }