View Javadoc
1   /*
2    * Copyright 2014 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.authentication.provider;
18  
19  import java.util.function.Function;
20  import java.util.function.UnaryOperator;
21  import org.bremersee.spring.security.ldaptive.authentication.LdaptiveAuthenticationProperties;
22  import org.mapstruct.Mapper;
23  import org.mapstruct.NullValueCheckStrategy;
24  import org.mapstruct.factory.Mappers;
25  
26  /**
27   * The templates for ldap authentication.
28   *
29   * @author Christian Bremer
30   */
31  public enum Template {
32  
33    /**
34     * Active directory template.
35     */
36    ACTIVE_DIRECTORY(TemplateMapper.INSTANCE::toActiveDirectory),
37  
38    /**
39     * Open ldap template.
40     */
41    OPEN_LDAP(TemplateMapper.INSTANCE::toOpenLdap),
42  
43    /**
44     * User contains groups template.
45     */
46    USER_CONTAINS_GROUPS(TemplateMapper.INSTANCE::toUserGroup),
47  
48    /**
49     * Group contains users template.
50     */
51    GROUP_CONTAINS_USERS(TemplateMapper.INSTANCE::toGroupUser);
52  
53    private final UnaryOperator<LdaptiveAuthenticationProperties> mapFn;
54  
55    Template(UnaryOperator<LdaptiveAuthenticationProperties> mapFn) {
56      this.mapFn = mapFn;
57    }
58  
59    /**
60     * Apply template ldaptive authentication properties.
61     *
62     * @param source the source
63     * @return the ldaptive authentication properties
64     */
65    public LdaptiveAuthenticationProperties applyTemplate(LdaptiveAuthenticationProperties source) {
66      return mapFn.apply(source);
67    }
68  
69    /**
70     * The interface Template mapper.
71     */
72    @Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
73    public interface TemplateMapper {
74  
75      /**
76       * The constant INSTANCE.
77       */
78      TemplateMapper INSTANCE = Mappers.getMapper(TemplateMapper.class);
79  
80      /**
81       * To active directory template.
82       *
83       * @param props the props
84       * @return the active directory template
85       */
86      ActiveDirectoryTemplate toActiveDirectory(LdaptiveAuthenticationProperties props);
87  
88      /**
89       * To open ldap template.
90       *
91       * @param props the props
92       * @return the open ldap template
93       */
94      OpenLdapTemplate toOpenLdap(LdaptiveAuthenticationProperties props);
95  
96      /**
97       * To user contains groups template.
98       *
99       * @param props the props
100      * @return the user contains groups template
101      */
102     UserContainsGroupsTemplate toUserGroup(LdaptiveAuthenticationProperties props);
103 
104     /**
105      * To group contains users template.
106      *
107      * @param props the props
108      * @return the group contains users template
109      */
110     GroupContainsUsersTemplate toGroupUser(LdaptiveAuthenticationProperties props);
111   }
112 
113 }