View Javadoc
1   /*
2    * Copyright 2019 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.dccon.repository.ldap;
18  
19  import static org.bremersee.data.ldaptive.LdaptiveEntryMapper.getAttributeValue;
20  
21  import org.bremersee.data.ldaptive.LdaptiveEntryMapper;
22  import org.bremersee.dccon.config.DomainControllerProperties;
23  import org.bremersee.dccon.model.DnsZone;
24  import org.ldaptive.AttributeModification;
25  import org.ldaptive.LdapEntry;
26  import org.ldaptive.io.StringValueTranscoder;
27  
28  /**
29   * The dns zone ldap mapper.
30   *
31   * @author Christian Bremer
32   */
33  public class DnsZoneLdapMapper extends AbstractLdapMapper implements LdaptiveEntryMapper<DnsZone> {
34  
35    private static final StringValueTranscoder STRING_VALUE_TRANSCODER = new StringValueTranscoder();
36  
37    /**
38     * Instantiates a new dns zone ldap mapper.
39     *
40     * @param properties the properties
41     */
42    public DnsZoneLdapMapper(DomainControllerProperties properties) {
43      super(properties);
44    }
45  
46    @Override
47    public String[] getObjectClasses() {
48      return new String[0];
49    }
50  
51    @Override
52    public String mapDn(final DnsZone dnsZone) {
53      return createDn(
54          getProperties().getDnsZoneRdn(),
55          dnsZone.getName(),
56          getProperties().getDnsZoneBaseDn());
57    }
58  
59    @Override
60    public DnsZone map(final LdapEntry ldapEntry) {
61      if (ldapEntry == null) {
62        return null;
63      }
64      final DnsZone destination = new DnsZone();
65      map(ldapEntry, destination);
66      return destination;
67    }
68  
69    @Override
70    public void map(
71        final LdapEntry ldapEntry,
72        final DnsZone dnsZone) {
73      if (ldapEntry == null) {
74        return;
75      }
76      mapCommonAttributes(ldapEntry, dnsZone);
77      dnsZone.setName(getAttributeValue(ldapEntry, "name", STRING_VALUE_TRANSCODER, null));
78      dnsZone.setDefaultZone(dnsZone.getName() != null
79          && dnsZone.getName().equalsIgnoreCase(getProperties().getDefaultZone()));
80      dnsZone.setReverseZone(getProperties().isReverseZone(dnsZone.getName()));
81    }
82  
83    @Override
84    public AttributeModification[] mapAndComputeModifications(
85        final DnsZone source,
86        final LdapEntry destination) {
87      return new AttributeModification[0];
88    }
89  
90  }