Commit 30b86a0b authored by Björn Fischer's avatar Björn Fischer

enables identity lookup for caldav

parent db5a7026
...@@ -59,6 +59,9 @@ class BackendCalDAV extends BackendDiff { ...@@ -59,6 +59,9 @@ class BackendCalDAV extends BackendDiff {
*/ */
public function Logon($username, $domain, $password) { public function Logon($username, $domain, $password) {
$this->_caldav_path = str_replace('%u', $username, CALDAV_PATH); $this->_caldav_path = str_replace('%u', $username, CALDAV_PATH);
if(strpos($this->_caldav_path, "%i") !== false) {
$this->_caldav_path = $this->LookupUserIdentifierInLdap($this->_caldav_path, $username, $domain);
}
$url = sprintf("%s://%s:%d%s", CALDAV_PROTOCOL, CALDAV_SERVER, CALDAV_PORT, $this->_caldav_path); $url = sprintf("%s://%s:%d%s", CALDAV_PROTOCOL, CALDAV_SERVER, CALDAV_PORT, $this->_caldav_path);
$this->_caldav = new CalDAVClient($url, $username, $password); $this->_caldav = new CalDAVClient($url, $username, $password);
if ($connected = $this->_caldav->CheckConnection()) { if ($connected = $this->_caldav->CheckConnection()) {
...@@ -77,6 +80,50 @@ class BackendCalDAV extends BackendDiff { ...@@ -77,6 +80,50 @@ class BackendCalDAV extends BackendDiff {
return $connected; return $connected;
} }
private function LookupUserIdentifierInLdap($caldav_path, $username, $domain) {
$ldap_conn = null;
try {
$ldap_conn = ldap_connect(CALDAV_IDENTITY_LDAP_SERVER, CALDAV_IDENTITY_LDAP_SERVER_PORT);
if ($ldap_conn) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - Connected to LDAP"));
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
$ldap_bind = ldap_bind($ldap_conn, CALDAV_IDENTITY_LDAP_USER, CALDAV_IDENTITY_LDAP_PASSWORD);
if ($ldap_bind) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - Authenticated in LDAP"));
$filter = str_replace('#username', $username, str_replace('#domain', $domain, CALDAV_IDENTITY_LDAP_QUERY));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - Searching From with filter: %s", $filter));
$search = ldap_search($ldap_conn, CALDAV_IDENTITY_LDAP_BASE, $filter, array(CALDAV_IDENTITY_LDAP_IDENTIFIER));
$items = ldap_get_entries($ldap_conn, $search);
if ($items['count'] > 0) {
$ret_value = $identity;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - Found entry in LDAP. Generating From"));
// We get the first object. It's your responsability to make the query unique
$caldav_path = str_replace('%i', $items[0][$field][CALDAV_IDENTITY_LDAP_IDENTIFIER], $caldav_path);
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - No entry found in LDAP"));
}
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - Not authenticated in LDAP server"));
}
}
else {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getIdentityFromLdap() - Not connected to LDAP server"));
}
}
catch(Exception $ex) {
ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->getIdentityFromLdap() - Error getting From value from LDAP server: %s", $ex));
}
if ($ldap_conn != null) {
ldap_close($ldap_conn);
}
return $caldav_path;
}
/** /**
* The connections to CalDAV are always directly closed. So nothing special needs to happen here. * The connections to CalDAV are always directly closed. So nothing special needs to happen here.
* @see IBackend::Logoff() * @see IBackend::Logoff()
......
...@@ -53,4 +53,19 @@ define('CALDAV_SUPPORTS_SYNC', false); ...@@ -53,4 +53,19 @@ define('CALDAV_SUPPORTS_SYNC', false);
// Maximum period to sync. // Maximum period to sync.
// Some servers don't support more than 10 years so you will need to change this // Some servers don't support more than 10 years so you will need to change this
define('CALDAV_MAX_SYNC_PERIOD', 2147483647); define('CALDAV_MAX_SYNC_PERIOD', 2147483647);
\ No newline at end of file
// SERVER: ldap server
// SERVER_PORT: ldap port
// USER: dn to use for connecting
// PASSWORD: password
// QUERY: query to execute
// FIELDS: columns in the query
// FROM: string that will be the from, replacing the field names with the values
define('CALDAV_IDENTITY_LDAP_SERVER', 'localhost');
define('CALDAV_IDENTITY_LDAP_SERVER_PORT', '389');
define('CALDAV_IDENTITY_LDAP_USER', 'cn=zpush,ou=servers,dc=zpush,dc=org');
define('CALDAV_IDENTITY_LDAP_PASSWORD', 'password');
define('CALDAV_IDENTITY_LDAP_BASE', 'dc=zpush,dc=org');
define('CALDAV_IDENTITY_LDAP_QUERY', '(sAMAccountName=#username)');
define('CALDAV_IDENTITY_LDAP_IDENTIFIER', "objectGUID");
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment