// Path: src/main/java/org/osiam/auth/configuration/LdapAuthentication.java
// @Configuration
// @ConditionalOnProperty(prefix = "org.osiam.auth-server", name = "ldap.enabled")
// public class LdapAuthentication {
// 
//     public static final String LDAP_PROVIDER = "ldap";
//     public static final String AUTH_EXTENSION = "urn:org.osiam:scim:extensions:auth-server";
// 
//     @Value("${org.osiam.auth-server.ldap.server.url:}")
//     private String url;
// 
//     @Value("${org.osiam.auth-server.ldap.server.groupsearchbase:}")
//     private String groupSearchBase;
// 
//     @Value("#{'${org.osiam.auth-server.ldap.dn.patterns:}'.split(';')}")
//     private String[] dnPatterns;
// 
//     @Value("${org.osiam.auth-server.ldap.mapping:}")
//     private String[] attributeMapping;
// 
//     @Bean
//     public ScimToLdapAttributeMapping ldapToScimAttributeMapping() {
//         return new ScimToLdapAttributeMapping(attributeMapping);
//     }
// 
//     @Bean
//     public OsiamLdapAuthenticationProvider osiamLdapAuthenticationProvider() {
//         return new OsiamLdapAuthenticationProvider(
//                 bindAuthenticator(),
//                 new DefaultLdapAuthoritiesPopulator(contextSource(), groupSearchBase),
//                 new OsiamLdapUserContextMapper(ldapToScimAttributeMapping()));
//     }
// 
//     @Bean
//     public BaseLdapPathContextSource contextSource() {
//         return new DefaultSpringSecurityContextSource(url);
//     }
// 
//     @Bean
//     public LdapAuthenticator bindAuthenticator(){
//         BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource());
//         bindAuthenticator.setUserDnPatterns(dnPatterns);
//         bindAuthenticator.setUserAttributes(
//                 Iterables.toArray(ldapToScimAttributeMapping().ldapAttributes(), String.class)
//         );
//         return bindAuthenticator;
//     }
// }
// 
// Path: src/main/java/org/osiam/auth/exception/LdapConfigurationException.java
// public class LdapConfigurationException extends AuthenticationException {
//     
//     public LdapConfigurationException(String s) {
//         super(s);
//     }
// 
//     public LdapConfigurationException(String s, Throwable cause) {
//         super(s, cause);
//     }
// }


import com.google.common.base.Strings;
import org.osiam.auth.configuration.LdapAuthentication;
import org.osiam.auth.exception.LdapConfigurationException;
import org.osiam.resources.scim.Address;
import org.osiam.resources.scim.Email;
import org.osiam.resources.scim.Entitlement;
import org.osiam.resources.scim.Extension;
import org.osiam.resources.scim.Im;
import org.osiam.resources.scim.Name;
import org.osiam.resources.scim.PhoneNumber;
import org.osiam.resources.scim.Photo;
import org.osiam.resources.scim.Role;
import org.osiam.resources.scim.UpdateUser;
import org.osiam.resources.scim.User;
import org.osiam.resources.scim.X509Certificate;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
                break;
            case "im":
                Im.Builder imBuilder = new Im.Builder().setValue(ldapValue)
                        .setType(new Im.Type(LdapAuthentication.LDAP_PROVIDER));
                List<Im> ims = new ArrayList<>();
                ims.add(imBuilder.build());
                builder.addIms(ims);
                break;
            case "locale":
                builder.setLocale(ldapValue);
                break;
            case "nickName":
                builder.setNickName(ldapValue);
                break;
            case "phoneNumber":
                PhoneNumber.Builder phoneNumberBuilder = new PhoneNumber.Builder().setValue(ldapValue)
                        .setType(new PhoneNumber.Type(LdapAuthentication.LDAP_PROVIDER));
                List<PhoneNumber> phoneNumbers = new ArrayList<>();
                phoneNumbers.add(phoneNumberBuilder.build());
                builder.addPhoneNumbers(phoneNumbers);
                break;
            case "photo":
                Photo.Builder photoBuilder;
                try {
                    photoBuilder = new Photo.Builder().setValue(new URI(ldapValue))
                            .setType(new Photo.Type(LdapAuthentication.LDAP_PROVIDER));
                    List<Photo> photos = new ArrayList<>();
                    photos.add(photoBuilder.build());
                    builder.addPhotos(photos);
                } catch (URISyntaxException e) {
// Path: src/main/java/org/osiam/auth/configuration/LdapAuthentication.java
// @Configuration
// @ConditionalOnProperty(prefix = "org.osiam.auth-server", name = "ldap.enabled")
// public class LdapAuthentication {
// 
//     public static final String LDAP_PROVIDER = "ldap";
//     public static final String AUTH_EXTENSION = "urn:org.osiam:scim:extensions:auth-server";
// 
//     @Value("${org.osiam.auth-server.ldap.server.url:}")
//     private String url;
// 
//     @Value("${org.osiam.auth-server.ldap.server.groupsearchbase:}")
//     private String groupSearchBase;
// 
//     @Value("#{'${org.osiam.auth-server.ldap.dn.patterns:}'.split(';')}")
//     private String[] dnPatterns;
// 
//     @Value("${org.osiam.auth-server.ldap.mapping:}")
//     private String[] attributeMapping;
// 
//     @Bean
//     public ScimToLdapAttributeMapping ldapToScimAttributeMapping() {
//         return new ScimToLdapAttributeMapping(attributeMapping);
//     }
// 
//     @Bean
//     public OsiamLdapAuthenticationProvider osiamLdapAuthenticationProvider() {
//         return new OsiamLdapAuthenticationProvider(
//                 bindAuthenticator(),
//                 new DefaultLdapAuthoritiesPopulator(contextSource(), groupSearchBase),
//                 new OsiamLdapUserContextMapper(ldapToScimAttributeMapping()));
//     }
// 
//     @Bean
//     public BaseLdapPathContextSource contextSource() {
//         return new DefaultSpringSecurityContextSource(url);
//     }
// 
//     @Bean
//     public LdapAuthenticator bindAuthenticator(){
//         BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource());
//         bindAuthenticator.setUserDnPatterns(dnPatterns);
//         bindAuthenticator.setUserAttributes(
//                 Iterables.toArray(ldapToScimAttributeMapping().ldapAttributes(), String.class)
//         );
//         return bindAuthenticator;
//     }
// }
// 
// Path: src/main/java/org/osiam/auth/exception/LdapConfigurationException.java
// public class LdapConfigurationException extends AuthenticationException {
//     
//     public LdapConfigurationException(String s) {
//         super(s);
//     }
// 
//     public LdapConfigurationException(String s, Throwable cause) {
//         super(s, cause);
//     }
// }


// Path: src/main/java/org/osiam/auth/login/ldap/OsiamLdapUserContextMapper.java
import com.google.common.base.Strings;
import org.osiam.auth.configuration.LdapAuthentication;
import org.osiam.auth.exception.LdapConfigurationException;
import org.osiam.resources.scim.Address;
import org.osiam.resources.scim.Email;
import org.osiam.resources.scim.Entitlement;
import org.osiam.resources.scim.Extension;
import org.osiam.resources.scim.Im;
import org.osiam.resources.scim.Name;
import org.osiam.resources.scim.PhoneNumber;
import org.osiam.resources.scim.Photo;
import org.osiam.resources.scim.Role;
import org.osiam.resources.scim.UpdateUser;
import org.osiam.resources.scim.User;
import org.osiam.resources.scim.X509Certificate;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

                break;
            case "im":
                Im.Builder imBuilder = new Im.Builder().setValue(ldapValue)
                        .setType(new Im.Type(LdapAuthentication.LDAP_PROVIDER));
                List<Im> ims = new ArrayList<>();
                ims.add(imBuilder.build());
                builder.addIms(ims);
                break;
            case "locale":
                builder.setLocale(ldapValue);
                break;
            case "nickName":
                builder.setNickName(ldapValue);
                break;
            case "phoneNumber":
                PhoneNumber.Builder phoneNumberBuilder = new PhoneNumber.Builder().setValue(ldapValue)
                        .setType(new PhoneNumber.Type(LdapAuthentication.LDAP_PROVIDER));
                List<PhoneNumber> phoneNumbers = new ArrayList<>();
                phoneNumbers.add(phoneNumberBuilder.build());
                builder.addPhoneNumbers(phoneNumbers);
                break;
            case "photo":
                Photo.Builder photoBuilder;
                try {
                    photoBuilder = new Photo.Builder().setValue(new URI(ldapValue))
                            .setType(new Photo.Type(LdapAuthentication.LDAP_PROVIDER));
                    List<Photo> photos = new ArrayList<>();
                    photos.add(photoBuilder.build());
                    builder.addPhotos(photos);
                } catch (URISyntaxException e) {
                    throw new LdapConfigurationException("Could not map the ldap attibute '"