Skip to content
Snippets Groups Projects
Commit 796ee8c4 authored by Arthur Schiwon's avatar Arthur Schiwon
Browse files

LDAP: Implement clear mappings functionality

parent 3f1717d3
Branches
No related tags found
No related merge requests found
<?php
/**
* ownCloud - user_ldap
*
* @author Arthur Schiwon
* @copyright 2013 Arthur Schiwon blizzz@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Check user and app status
OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$subject = $_POST['ldap_clear_mapping'];
if(\OCA\user_ldap\lib\Helper::clearMapping($subject)) {
OCP\JSON::success();
} else {
$l=OC_L10N::get('user_ldap');
OCP\JSON::error(array('message' => $l->t('Failed to clear the mappings.')));
}
\ No newline at end of file
...@@ -99,6 +99,26 @@ var LdapConfiguration = { ...@@ -99,6 +99,26 @@ var LdapConfiguration = {
} }
} }
); );
},
clearMappings: function(mappingSubject) {
$.post(
OC.filePath('user_ldap','ajax','clearMappings.php'),
'ldap_clear_mapping='+mappingSubject,
function(result) {
if(result.status == 'success') {
OC.dialogs.info(
t('user_ldap', 'mappings cleared'),
t('user_ldap', 'Success')
);
} else {
OC.dialogs.alert(
result.message,
t('user_ldap', 'Error')
);
}
}
);
} }
} }
...@@ -166,6 +186,16 @@ $(document).ready(function() { ...@@ -166,6 +186,16 @@ $(document).ready(function() {
); );
}); });
$('#ldap_action_clear_user_mappings').click(function(event) {
event.preventDefault();
LdapConfiguration.clearMappings('user');
});
$('#ldap_action_clear_group_mappings').click(function(event) {
event.preventDefault();
LdapConfiguration.clearMappings('group');
});
$('#ldap_serverconfig_chooser').change(function(event) { $('#ldap_serverconfig_chooser').change(function(event) {
value = $('#ldap_serverconfig_chooser option:selected:first').attr('value'); value = $('#ldap_serverconfig_chooser option:selected:first').attr('value');
if(value == 'NEW') { if(value == 'NEW') {
......
...@@ -102,4 +102,29 @@ class Helper { ...@@ -102,4 +102,29 @@ class Helper {
return true; return true;
} }
/**
* Truncate's the given mapping table
*
* @param string $mapping either 'user' or 'group'
* @return boolean true on success, false otherwise
*/
static public function clearMapping($mapping) {
if($mapping === 'user') {
$table = '`*PREFIX*ldap_user_mapping`';
} else if ($mapping === 'group') {
$table = '`*PREFIX*ldap_group_mapping`';
} else {
return false;
}
$query = \OCP\DB::prepare('TRUNCATE '.$table);
$res = $query->execute();
if(\OCP\DB::isError($res)) {
return false;
}
return true;
}
} }
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
<p class="ldapIndent"><label for="ldap_expert_uuid_attr"><?php p($l->t('UUID Attribute:'));?></label><input type="text" id="ldap_expert_uuid_attr" name="ldap_expert_uuid_attr" data-default="<?php p($_['ldap_expert_uuid_attr_default']); ?>" /></p> <p class="ldapIndent"><label for="ldap_expert_uuid_attr"><?php p($l->t('UUID Attribute:'));?></label><input type="text" id="ldap_expert_uuid_attr" name="ldap_expert_uuid_attr" data-default="<?php p($_['ldap_expert_uuid_attr_default']); ?>" /></p>
<p><strong><?php p($l->t('Username-LDAP User Mapping'));?></strong></p> <p><strong><?php p($l->t('Username-LDAP User Mapping'));?></strong></p>
<p class="ldapIndent"><?php p($l->t('ownCloud uses usernames to store and assign (meta) data. In order to precisely identify and recognize users, each LDAP user will have a internal username. This requires a mapping from ownCloud username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found by ownCloud. The internal ownCloud name is used all over in ownCloud. Clearing the Mappings will have leftovers everywhere. Clearing the Mappings is not configuration sensitive, it affects all LDAP configurations! Do never clear the mappings in a production environment. Only clear mappings in a testing or experimental stage.'));?></p> <p class="ldapIndent"><?php p($l->t('ownCloud uses usernames to store and assign (meta) data. In order to precisely identify and recognize users, each LDAP user will have a internal username. This requires a mapping from ownCloud username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found by ownCloud. The internal ownCloud name is used all over in ownCloud. Clearing the Mappings will have leftovers everywhere. Clearing the Mappings is not configuration sensitive, it affects all LDAP configurations! Do never clear the mappings in a production environment. Only clear mappings in a testing or experimental stage.'));?></p>
<p class="ldapIndent"><button id="ldap_action_clear_mappings" name="ldap_action_clear_mappings"><?php p($l->t('Clear Username-LDAP User Mapping'));?></button></p> <p class="ldapIndent"><button id="ldap_action_clear_user_mappings" name="ldap_action_clear_user_mappings"><?php p($l->t('Clear Username-LDAP User Mapping'));?></button><br/><button id="ldap_action_clear_group_mappings" name="ldap_action_clear_group_mappings"><?php p($l->t('Clear Groupname-LDAP Group Mapping'));?></button></p>
</fieldset> </fieldset>
<input id="ldap_submit" type="submit" value="Save" /> <button id="ldap_action_test_connection" name="ldap_action_test_connection"><?php p($l->t('Test Configuration'));?></button> <a href="http://doc.owncloud.org/server/5.0/admin_manual/auth_ldap.html" target="_blank"><img src="<?php print_unescaped(OCP\Util::imagePath('', 'actions/info.png')); ?>" style="height:1.75ex" /> <?php p($l->t('Help'));?></a> <input id="ldap_submit" type="submit" value="Save" /> <button id="ldap_action_test_connection" name="ldap_action_test_connection"><?php p($l->t('Test Configuration'));?></button> <a href="http://doc.owncloud.org/server/5.0/admin_manual/auth_ldap.html" target="_blank"><img src="<?php print_unescaped(OCP\Util::imagePath('', 'actions/info.png')); ?>" style="height:1.75ex" /> <?php p($l->t('Help'));?></a>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment