View Javadoc
1   /*
2    * Copyright 2024-2026 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.spring.security.ldaptive.userdetails;
18  
19  import java.util.Collection;
20  import java.util.List;
21  import org.bremersee.spring.security.core.NormalizedPrincipal;
22  import org.immutables.serial.Serial;
23  import org.immutables.value.Value;
24  import org.jspecify.annotations.NonNull;
25  import org.jspecify.annotations.NullMarked;
26  import org.jspecify.annotations.Nullable;
27  import org.springframework.security.core.GrantedAuthority;
28  import org.springframework.security.core.userdetails.UserDetails;
29  
30  /**
31   * The ldaptive user details.
32   *
33   * @author Christian Bremer
34   */
35  @Value.Style(
36      visibility = Value.Style.ImplementationVisibility.PACKAGE,
37      overshadowImplementation = true,
38      depluralize = true,
39      jdk9Collections = true,
40      get = {"get*", "is*"})
41  @Value.Immutable
42  @Serial.Version(1L)
43  public interface LdaptiveUserDetails extends UserDetails, NormalizedPrincipal {
44  
45    /**
46     * Gets the distinguished name.
47     *
48     * @return the distinguished name
49     */
50    String getDn();
51  
52    @Value.Default
53    @NonNull
54    @Override
55    default Collection<? extends GrantedAuthority> getAuthorities() {
56      return List.of();
57    }
58  
59    @Nullable
60    @Override
61    String getPassword();
62  
63    @Override
64    @NullMarked
65    String getUsername();
66  
67    @Value.Default
68    @Override
69    default boolean isAccountNonExpired() {
70      return true;
71    }
72  
73    @Value.Default
74    @Override
75    default boolean isAccountNonLocked() {
76      return true;
77    }
78  
79    @Value.Default
80    @Override
81    default boolean isCredentialsNonExpired() {
82      return true;
83    }
84  
85    @Value.Default
86    @Override
87    default boolean isEnabled() {
88      return true;
89    }
90  
91    @Value.Lazy
92    @Override
93    default String getName() {
94      return getUsername();
95    }
96  
97    @Nullable
98    @Override
99    String getFirstName();
100 
101   @Nullable
102   @Override
103   String getLastName();
104 
105   @Nullable
106   @Override
107   String getEmail();
108 
109   /**
110    * Empty ldaptive user details.
111    *
112    * @return the ldaptive user details
113    */
114   @NonNull
115   static LdaptiveUserDetails empty() {
116     return LdaptiveUserDetails.builder()
117         .username("")
118         .build();
119   }
120 
121   /**
122    * Gets builder.
123    *
124    * @return the builder
125    */
126   static Builder builder() {
127     return new Builder();
128   }
129 
130   /**
131    * The immutable builder.
132    */
133   class Builder extends ImmutableLdaptiveUserDetails.Builder {
134 
135     /**
136      * Instantiates a new builder.
137      */
138     public Builder() {
139       super();
140     }
141 
142   }
143 
144 }