protected function configure(array $params)
    {
        $required = array('hostname', 'base_dn');
        $missing = array();
        foreach ($required as $key) {
            if (! array_key_exists($key, $params)) {
                $missing[] = $key;
            }
        }
        if (count($missing) > 0) {
            throw new \InvalidArgumentException(
                'Required parameters missing: ' . implode(', ', $missing)
            );
        }

        $idx = strpos($params['hostname'], '://');
        $enforceSSL = false;
        if (false !== $idx) {
            $prefix = strtolower(substr($params['hostname'], 0, $idx));
            if ($prefix === 'ldaps') {
                $enforceSSL = true;
            }
            $params['hostname'] = substr($params['hostname'], $idx+3);
        }

        $params['withSSL'] = false;
        $params['withTLS'] = false;
        if (array_key_exists('security', $params)) {
            switch($params['security']) {
            case 'SSL':
                $params['withSSL'] = true;
                break;
            case 'TLS':
                $params['withTLS'] = true;
                break;
            default:
                throw new \InvalidArgumentException(
                    sprintf(
                        'Security mode %s not supported - only SSL or TLS are supported',
                        $params['security']
                    )
                );
            }
        } elseif ($enforceSSL) {
            $params['withSSL'] = true;
        }

        if (! array_key_exists('port', $params)) {
            if ($params['withSSL']) {
                $params['port'] = 636;
            } else {
                $params['port'] = 389;
            }
        }

        if (! array_key_exists('options', $params)) {
            $params['options'] = array();
        }

        $params['bind_anonymous'] = false;
        if ((! array_key_exists('bind_dn', $params)) || (strlen(trim($params['bind_dn'])) == 0)) {
            $params['bind_anonymous'] = true;
            $params['bind_dn']        = '';
            $params['bind_password']  = '';
        }
        if (! array_key_exists('bind_password', $params)) {
            $params['bind_password']  = '';
        }

        $this->configuration = $params;
    }