View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.kim.ldap;
17  
18  import org.kuali.rice.kim.api.identity.name.EntityName;
19  import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
20  import org.springframework.ldap.core.ContextMapper;
21  import org.springframework.ldap.core.DirContextOperations;
22  
23  import javax.naming.NamingException;
24  
25  /**
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class EntityNamePrincipalNameMapper extends BaseMapper<EntityNamePrincipalName> {
30  
31      private ContextMapper defaultNameMapper;
32      
33      @Override
34      EntityNamePrincipalName mapDtoFromContext(DirContextOperations context) {
35          EntityNamePrincipalName.Builder builder = mapBuilderFromContext(context);
36          return builder != null ? builder.build() : null;
37      }
38      
39      EntityNamePrincipalName.Builder mapBuilderFromContext(DirContextOperations context) {
40          final EntityNamePrincipalName.Builder person = EntityNamePrincipalName.Builder.create();
41  
42          try {
43              person.setDefaultName((EntityName.Builder) getDefaultNameMapper().mapFromContext(context));
44          } catch (NamingException e) {
45              e.printStackTrace();
46              throw new RuntimeException(e.getMessage());
47          }
48  
49          person.setPrincipalName(context.getStringAttribute(getConstants().getKimLdapNameProperty()));
50          return person;
51      }
52  
53      /**
54       * Gets the value of defaultNameMapper
55       *
56       * @return the value of defaultNameMapper
57       */
58      public final ContextMapper getDefaultNameMapper() {
59          return this.defaultNameMapper;
60      }
61  
62      /**
63       * Sets the value of defaultNameMapper
64       *
65       * @param argDefaultNameMapper Value to assign to this.defaultNameMapper
66       */
67      public final void setDefaultNameMapper(final ContextMapper argDefaultNameMapper) {
68          this.defaultNameMapper = argDefaultNameMapper;
69      }
70  }