// 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;
/*
 * Copyright (C) 2013 tarent AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.osiam.auth.login.ldap;



public class OsiamLdapUserContextMapper extends LdapUserDetailsMapper {

    private final ScimToLdapAttributeMapping scimLdapAttributes;

    public OsiamLdapUserContextMapper(ScimToLdapAttributeMapping scimToLdapAttributeMapping) {
        this.scimLdapAttributes = scimToLdapAttributeMapping;
    }

    public User mapUser(DirContextOperations ldapUserData) {

// 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;

/*
 * Copyright (C) 2013 tarent AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.osiam.auth.login.ldap;



public class OsiamLdapUserContextMapper extends LdapUserDetailsMapper {

    private final ScimToLdapAttributeMapping scimLdapAttributes;

    public OsiamLdapUserContextMapper(ScimToLdapAttributeMapping scimToLdapAttributeMapping) {
        this.scimLdapAttributes = scimToLdapAttributeMapping;
    }

    public User mapUser(DirContextOperations ldapUserData) {

        Extension extension = new Extension.Builder(LdapAuthentication.AUTH_EXTENSION)