18 require_once SQ_CORE_PACKAGE_PATH.
'/system/authentication/authentication/authentication.inc';
19 require_once SQ_FUDGE_PATH.
'/ldap/ldap.inc';
65 $bridge_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_BACKEND_NAV,
'ldap_bridge', TRUE);
68 if (!empty($bridge_links)) {
69 foreach($bridge_links as $bridge_info) {
70 $bridges[$bridge_info[
'sort_order']] = $bridge_info[
'minorid'];
74 foreach ($bridges as $sort_order => $bridgeid) {
75 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bridgeid);
76 if (is_null($bridge))
continue;
79 if ($bridge->status != SQ_STATUS_LIVE)
continue;
81 $ldap = $bridge->connectToLdap();
83 if (is_null($ldap))
continue;
86 if (!$entry || ($entry[
'count'] == 0)) {
89 if (isset($entry[0])) {
93 $user_type = $bridge->attr(
'user_type');
94 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($user_type);
95 $user =
new $user_type($bridge->id, $entry);
98 $success = @$ldap->connectAsUser($user->attr(
'dn'), $password);
102 if ($this->
attr(
'log_in_as') ==
'local') {
105 $auth_assetids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'authentication_default');
106 if (count($auth_assetids) > 0) {
107 $auth_default = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($auth_assetids[0]);
110 $user = $auth_default->locateUser($username);
113 if (!is_null($user)) {
114 unset($_SESSION[
'user_login_attempts']);
121 if (!is_null($user)) {
126 $return_value = NULL;
127 return $return_value;
146 $bridge_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_BACKEND_NAV,
'ldap_bridge', TRUE);
149 if (!empty($bridge_links)) {
150 foreach($bridge_links as $bridge_info) {
151 $bridges[$bridge_info[
'sort_order']] = $bridge_info[
'minorid'];
155 foreach ($bridges as $sort_order => $bridgeid) {
156 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bridgeid);
157 if (is_null($bridge))
continue;
160 if ($bridge->status != SQ_STATUS_LIVE)
continue;
163 if (!$entry || ($entry[
'count'] == 0)) {
166 if (isset($entry[0])) {
168 $user_type = $bridge->attr(
'user_type');
169 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($user_type);
170 $user =
new $user_type($bridge->id, $entry);
191 $bridge_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_BACKEND_NAV,
'ldap_bridge', TRUE);
194 if (!empty($bridge_links)) {
195 foreach($bridge_links as $bridge_info) {
196 $bridges[$bridge_info[
'sort_order']] = $bridge_info[
'minorid'];
200 foreach ($bridges as $sort_order => $bridgeid) {
201 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bridgeid);
202 if (is_null($bridge))
continue;
205 if ($bridge->status != SQ_STATUS_LIVE)
continue;
208 if (!$entry || ($entry[
'count'] == 0)) {
211 if (isset($entry[0])) {
213 $user_type = $bridge->attr(
'user_type');
214 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($user_type);
215 $user =
new $user_type($bridge->id, $entry);
234 $username = $user->attr(
'dn');
235 if (!isset($_SESSION[
'user_login_attempts'])) {
236 $_SESSION[
'user_login_attempts'] = Array();
238 if (empty($_SESSION[
'user_login_attempts'][$username])) {
239 $_SESSION[
'user_login_attempts'][$username] = 1;
241 $_SESSION[
'user_login_attempts'][$username]++;
244 if ($_SESSION[
'user_login_attempts'][$username] >= SQ_CONF_MAX_LOGIN_ATTEMPTS) {
245 if (!is_null($user) && $user->canLogin()) {
247 $ms =& $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
249 'asset_name' => $user->name,
250 'user_name' => $username,
251 'num_attempts' => (
int)SQ_CONF_MAX_LOGIN_ATTEMPTS,
253 $log = $ms->newMessage(Array(),
'system.security.login.ldap', $msg_reps);
254 $log->parameters[
'remote_addr'] = $_SERVER[
'REMOTE_ADDR'];
255 $log->parameters[
'sessionid'] = session_id();
273 SQ_LINK_TYPE_1 => Array(
274 'ldap_bridge' => Array(
276 'exclusive' => FALSE,
298 $ldap = $ldap_conn ? $ldap_conn : $bridge->connectToLdap();
300 $attrs = $bridge->attr(
'attributes');
302 if (is_null($ldap))
return $null;
307 if (trim($bridge->attr(
'auth_dn')) !==
'') {
308 $auth_base_dn = $bridge->attr(
'auth_dn');
310 $auth_base_dn = $bridge->attr(
'root_dn');
314 $username = $ldap->escape_filter_value($username);
316 $auth_filter = trim($bridge->attr(
'auth_filter'));
317 if (!empty($auth_filter)) {
321 if ($auth_filter[0] !=
'(') {
322 $auth_filter =
'('.$auth_filter.
')';
324 $filter =
'(&'.$auth_filter.
'('.$attrs[
'uid'].
'='.$username.
'))';
326 $filter =
'('.$attrs[
'uid'].
'='.$username.
')';
329 $required_attrs = array_merge(
330 array_keys(array_get_index($bridge->attr(
'user_attributes'),
'show', Array())),
331 array_values($attrs),
334 $result = $ldap->search($auth_base_dn, $filter, NULL, TRUE, TRUE, $required_attrs);
336 if (!$result)
return $null;
337 $entry = $ldap->getEntries($result);