Faxtomail-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
June 2014
- 6 participants
- 194 discussions
r201 - in trunk/faxtomail-ui-web/src/main: java/com/franciaflex/faxtomail/web/action/admin webapp/js
by echatellier@users.forge.codelutin.com 12 Jun '14
by echatellier@users.forge.codelutin.com 12 Jun '14
12 Jun '14
Author: echatellier
Date: 2014-06-12 17:23:11 +0200 (Thu, 12 Jun 2014)
New Revision: 201
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/201
Log:
Display folder full path
Modified:
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java
trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js
trunk/faxtomail-ui-web/src/main/webapp/js/user-folder.js
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java 2014-06-12 15:00:44 UTC (rev 200)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java 2014-06-12 15:23:11 UTC (rev 201)
@@ -76,7 +76,7 @@
@Override
@Action("user-folder-input")
public String input() throws Exception {
- mailFolders = mailFolderService.getAllMailFolders();
+ mailFolders = mailFolderService.getRootMailFolders();
users = configurationService.getUserManagedUsers(getSession().getAuthenticatedFaxToMailUser());
// build display map
Modified: trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-06-12 15:00:44 UTC (rev 200)
+++ trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-06-12 15:23:11 UTC (rev 201)
@@ -45,7 +45,7 @@
$scope.mailFolders = ConfigurationData.mailFolders;
// {Map} Mail folder usage
$scope.mailFoldersUsage = ConfigurationData.mailFoldersUsage;
- //{Map<MailFolder id, Array<MailFolder>>} liste des
+ //{Map<MailFolder id, Array<MailFolder>>} liste des dossier (a plat, par dossier racine)
$scope.flatMailFolders;
//{Array} All application users
$scope.users = ConfigurationData.users;
Modified: trunk/faxtomail-ui-web/src/main/webapp/js/user-folder.js
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/js/user-folder.js 2014-06-12 15:00:44 UTC (rev 200)
+++ trunk/faxtomail-ui-web/src/main/webapp/js/user-folder.js 2014-06-12 15:23:11 UTC (rev 201)
@@ -33,28 +33,45 @@
$scope.mailFolders = UserFolderData.mailFolders;
// {Array} Liste des utilisateurs ldap
$scope.users = UserFolderData.users;
+ //{Map<MailFolder id, Array<MailFolder>>} liste des
+ $scope.flatMailFolders;
//{Map} Topia id : mailFolders
$scope.userFolders = UserFolderData.userFolders;
//{Array} Group list
$scope.groups = UserFolderData.groups;
-
- // method privée recursive pour retourner l'ensemble des dossiers
- var recursiveAddMailFolder = function(result, mailFolders) {
+
+ // method privée recursive pour retourner l'ensemble des dossiers en les modifiant pour ajouter
+ // des metadata (full path from root, and root node instance)
+ var recursiveAddMailFolder = function(result, mailFolders, rootFolder, prefix, parent) {
if (mailFolders) {
angular.forEach(mailFolders, function(mailFolder) {
+
+ // warning modify input object :(
+ // use $ from this, even not recommended because angular exlude those fields when jsonify
+ mailFolder.$fullPath = prefix + "/" + mailFolder.name;
+ // ha la la, modify input object again :(
+ // use $ from this, even not recommended because angular exlude those fields when jsonify
+ mailFolder.$rootFolder = rootFolder;
+ // encore pour le parent
+ mailFolder.$parent = parent;
+
result.push(mailFolder);
- recursiveAddMailFolder(result, mailFolder.children);
+ recursiveAddMailFolder(result, mailFolder.children, rootFolder, mailFolder.$fullPath, mailFolder);
});
}
};
- // Retourne l'ensemble de l'arbre des dossiers "à plat"
- $scope.flatMailFolders = function() {
- var flatMailFolders = [];
- recursiveAddMailFolder(flatMailFolders, $scope.mailFolders);
- return flatMailFolders;
+ // update $scope.flatMailFolders when $scope.mailFolders changes
+ $scope._updateFlatMailFolders = function() {
+ console.log("Update flatMailFolders map");
+ $scope.flatMailFolders = {};
+ angular.forEach($scope.mailFolders, function(mailFolder) {
+ $scope.flatMailFolders[mailFolder.topiaId] = [];
+ recursiveAddMailFolder($scope.flatMailFolders[mailFolder.topiaId], mailFolder.children, mailFolder, mailFolder.name, mailFolder);
+ });
};
-
+ $scope._updateFlatMailFolders();
+
// fonction retournant l'ensemble des options disponibles
$scope.getObjectsData = function(term, result) {
var resultArray = [];
@@ -62,7 +79,20 @@
// select 2 require an id field
mailFolder.id = mailFolder.topiaId;
// select 2 can use 'name' for display, so it's ok
+
+ // push root
resultArray.push(mailFolder);
+
+ // build children map
+ if ($scope.flatMailFolders.hasOwnProperty(mailFolder.topiaId)) {
+ angular.forEach($scope.flatMailFolders[mailFolder.topiaId], function(childFolder) {
+ childFolder.id = childFolder.topiaId;
+ // defined text for display
+ childFolder.text = childFolder.$fullPath;
+ resultArray.push(childFolder);
+ });
+ }
+
});
result(resultArray);
};
1
0
r200 - trunk/faxtomail-ui-web/src/main/resources/i18n
by echatellier@users.forge.codelutin.com 12 Jun '14
by echatellier@users.forge.codelutin.com 12 Jun '14
12 Jun '14
Author: echatellier
Date: 2014-06-12 17:00:44 +0200 (Thu, 12 Jun 2014)
New Revision: 200
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/200
Log:
Renommage d'une valeur d'enum
Modified:
trunk/faxtomail-ui-web/src/main/resources/i18n/faxtomail-ui-web_fr_FR.properties
Modified: trunk/faxtomail-ui-web/src/main/resources/i18n/faxtomail-ui-web_fr_FR.properties
===================================================================
--- trunk/faxtomail-ui-web/src/main/resources/i18n/faxtomail-ui-web_fr_FR.properties 2014-06-12 14:59:17 UTC (rev 199)
+++ trunk/faxtomail-ui-web/src/main/resources/i18n/faxtomail-ui-web_fr_FR.properties 2014-06-12 15:00:44 UTC (rev 200)
@@ -30,7 +30,7 @@
com.franciaflex.faxtomail.persistence.entities.MailField.RECEPTION_DATE=Date de réception
com.franciaflex.faxtomail.persistence.entities.MailField.RECIPIENT=Destinataire
com.franciaflex.faxtomail.persistence.entities.MailField.REFERENCE=Référence
-com.franciaflex.faxtomail.persistence.entities.MailField.REPLY=Réponses
+com.franciaflex.faxtomail.persistence.entities.MailField.REPLIES=Réponses
com.franciaflex.faxtomail.persistence.entities.MailField.SAV_NB=Quantité de SAV
com.franciaflex.faxtomail.persistence.entities.MailField.SENDER=Expéditeur
com.franciaflex.faxtomail.persistence.entities.MailField.TAKEN_BY=Pris par
1
0
r199 - in trunk/faxtomail-ui-web/src/main/webapp: WEB-INF/content/admin js
by echatellier@users.forge.codelutin.com 12 Jun '14
by echatellier@users.forge.codelutin.com 12 Jun '14
12 Jun '14
Author: echatellier
Date: 2014-06-12 16:59:17 +0200 (Thu, 12 Jun 2014)
New Revision: 199
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/199
Log:
Correction de la gestion des droits.
Ajout de prototype utilisataires indexOfByTopiaId, containsByTopiaId
Modified:
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration-input.jsp
trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js
trunk/faxtomail-ui-web/src/main/webapp/js/faxtomail.js
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration-input.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration-input.jsp 2014-06-12 13:40:31 UTC (rev 198)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration-input.jsp 2014-06-12 14:59:17 UTC (rev 199)
@@ -88,7 +88,7 @@
</div>
<div class="form-group">
- Actions autorisées lorsque la demande n'a pas d'état d'attente et est <strong>invalide</strong> :
+ Actions autorisées lorsque la demande n'a pas d'état d'attente est <strong>invalide</strong> :
<label class="checkbox" ng-repeat="(mailAction,label) in mailActions">
<input type="checkbox" ng-checked="configuration.invalidFormDisabledActions.indexOf(mailAction) == -1"
ng-click="changeInvalidAction(mailAction)"> {{label}}
@@ -556,7 +556,7 @@
Hériter des états d'attente déclarés sur les dossiers parent :
</label>
<label class="checkbox" ng-repeat="etatAttente in etatAttentes" ng-if="selectedMailFolder.$parent && !selectedMailFolder.useCurrentLevelEtatAttente">
- <input type="checkbox" ng-checked="parentScopeValues.etatAttentes.indexOf(etatAttente) != -1"
+ <input type="checkbox" ng-checked="parentScopeValues.etatAttentes.containsByTopiaId(etatAttente)"
disabled> {{etatAttente.label}}
</label>
<label>
@@ -565,7 +565,7 @@
Définir des états d'attente pour ce dossier :
</label>
<label class="checkbox" ng-repeat="etatAttente in etatAttentes" ng-if="selectedMailFolder.useCurrentLevelEtatAttente || !selectedMailFolder.$parent">
- <input type="checkbox" ng-checked="selectedMailFolder.etatAttentes.indexOf(etatAttente) != -1"
+ <input type="checkbox" ng-checked="selectedMailFolder.etatAttentes.containsByTopiaId(etatAttente)"
ng-click="changeFolderEtatAttente(etatAttente)"> {{etatAttente.label}}
</label>
</div>
@@ -661,9 +661,9 @@
<span class="fa fa-users"></span> {{group.fullPath}}
</td>
<td>
- <label><input type="checkbox" ng-checked="parentScopeValues.readRightGroups.indexOf(group) != -1" disabled> Lecture</label>
- <label><input type="checkbox" ng-checked="parentScopeValues.writeRightGroups.indexOf(group) != -1" disabled> Écriture</label>
- <label><input type="checkbox" ng-checked="parentScopeValues.moveRightGroups.indexOf(group) != -1" disabled> Déplacement</label>
+ <label><input type="checkbox" ng-checked="parentScopeValues.readRightGroups.containsByTopiaId(group)" disabled> Lecture</label>
+ <label><input type="checkbox" ng-checked="parentScopeValues.writeRightGroups.containsByTopiaId(group)" disabled> Écriture</label>
+ <label><input type="checkbox" ng-checked="parentScopeValues.moveRightGroups.containsByTopiaId(group)" disabled> Déplacement</label>
</td>
</tr>
<tr ng-repeat="user in parentScopeValues.rightUsers" class="parentInfos">
@@ -671,9 +671,9 @@
<span class="fa fa-user"></span> {{user.firstName}} {{user.lastName}}
</td>
<td>
- <label><input type="checkbox" ng-checked="parentScopeValues.readRightUsers.indexOf(user) != -1" disabled> Lecture</label>
- <label><input type="checkbox" ng-checked="parentScopeValues.writeRightUsers.indexOf(user) != -1" disabled> Écriture</label>
- <label><input type="checkbox" ng-checked="parentScopeValues.moveRightUsers.indexOf(user) != -1" disabled> Déplacement</label>
+ <label><input type="checkbox" ng-checked="parentScopeValues.readRightUsers.containsByTopiaId(user)" disabled> Lecture</label>
+ <label><input type="checkbox" ng-checked="parentScopeValues.writeRightUsers.containsByTopiaId(user)" disabled> Écriture</label>
+ <label><input type="checkbox" ng-checked="parentScopeValues.moveRightUsers.containsByTopiaId(user)" disabled> Déplacement</label>
</td>
</tr>
</tbody>
@@ -681,50 +681,50 @@
<tr ng-repeat="group in selectedMailFolder.rightGroups">
<td>
<span class="fa fa-users"></span> {{group.fullPath}}
- <a class="pull-right btn btn-danger btn-xs pull-right" ng-click="removeWriteRightGroup($index)">
+ <a class="pull-right btn btn-danger btn-xs pull-right" ng-click="removeRightGroup($index, group)">
<span class="glyphicon glyphicon-remove"></span>
</a>
</td>
<td>
<label><input type="checkbox"
ng-model="readRightGroup"
- ng-checked="selectedMailFolder.readRightGroups.indexOf(group) != -1"
- ng-disabled="parentScopeValues.readRightGroups.indexOf(group) != -1"
+ ng-checked="selectedMailFolder.readRightGroups.containsByTopiaId(group)"
+ ng-disabled="parentScopeValues.readRightGroups.containsByTopiaId(group)"
ng-change="changeReadRightGroup(group)"> Lecture</label>
<label><input type="checkbox"
ng-model="writeRightGroup"
- ng-checked="selectedMailFolder.writeRightGroups.indexOf(group) != -1"
- ng-disabled="parentScopeValues.writeRightGroups.indexOf(group) != -1"
+ ng-checked="selectedMailFolder.writeRightGroups.containsByTopiaId(group)"
+ ng-disabled="parentScopeValues.writeRightGroups.containsByTopiaId(group)"
ng-change="changeWriteRightGroup(group)"> Écriture</label>
<label><input type="checkbox"
ng-model="moveRightGroup"
- ng-checked="selectedMailFolder.moveRightGroups.indexOf(group) != -1"
- ng-disabled="parentScopeValues.moveRightGroups.indexOf(group) != -1"
+ ng-checked="selectedMailFolder.moveRightGroups.containsByTopiaId(group)"
+ ng-disabled="parentScopeValues.moveRightGroups.containsByTopiaId(group)"
ng-change="changeMoveRightGroup(group)"> Déplacement</label>
</td>
</tr>
<tr ng-repeat="user in selectedMailFolder.rightUsers">
<td>
<span class="fa fa-user"></span> {{user.firstName}} {{user.lastName}}
- <a class="pull-right btn btn-danger btn-xs pull-right" ng-click="removeWriteRightUser($index)">
+ <a class="pull-right btn btn-danger btn-xs pull-right" ng-click="removeRightUser($index, user)">
<span class="glyphicon glyphicon-remove"></span>
</a>
</td>
<td>
<label><input type="checkbox"
ng-model="readRightUser"
- ng-checked="selectedMailFolder.readRightUsers.indexOf(user) != -1"
- ng-disabled="parentScopeValues.readRightUsers.indexOf(user) != -1"
+ ng-checked="selectedMailFolder.readRightUsers.containsByTopiaId(user)"
+ ng-disabled="parentScopeValues.readRightUsers.containsByTopiaId(user)"
ng-change="changeReadRightUser(user)"> Lecture</label>
<label><input type="checkbox"
ng-model="writeRightUser"
- ng-checked="selectedMailFolder.writeRightUsers.indexOf(user) != -1"
- ng-disabled="parentScopeValues.writeRightUsers.indexOf(user) != -1"
+ ng-checked="selectedMailFolder.writeRightUsers.containsByTopiaId(user)"
+ ng-disabled="parentScopeValues.writeRightUsers.containsByTopiaId(user)"
ng-change="changeWriteRightUser(user)"> Écriture</label>
<label><input type="checkbox"
ng-model="moveRightUser"
- ng-checked="selectedMailFolder.moveRightUsers.indexOf(user) != -1"
- ng-disabled="parentScopeValues.moveRightUsers.indexOf(user) != -1"
+ ng-checked="selectedMailFolder.moveRightUsers.containsByTopiaId(user)"
+ ng-disabled="parentScopeValues.moveRightUsers.containsByTopiaId(user)"
ng-change="changeMoveRightUser(user)"> Déplacement</label>
</td>
</tr>
Modified: trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-06-12 13:40:31 UTC (rev 198)
+++ trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-06-12 14:59:17 UTC (rev 199)
@@ -103,6 +103,11 @@
ConfigurationModule.controller('ConfigurationMiscController', ['$scope', '$window', 'ConfigurationData',
function($scope, $window, ConfigurationData) {
+ // initialisation de la configuration
+ if ($scope.configuration.invalidFormDisabledActions) {
+ $scope.configuration.invalidFormDisabledActions = [];
+ }
+
// selection/deselection d'une action
$scope.changeInvalidAction = function(action) {
var index = $scope.configuration.invalidFormDisabledActions.indexOf(action);
@@ -362,19 +367,6 @@
});
});
- // change instance (for indexOf() to work)
- if ($scope.selectedMailFolder.etatAttentes) {
- var newArray = [];
- angular.forEach($scope.selectedMailFolder.etatAttentes, function(folderEtatAttente) {
- angular.forEach($scope.etatAttentes, function(etatAttente) {
- if (etatAttente.topiaId == folderEtatAttente.topiaId) {
- newArray.push(etatAttente);
- }
- });
- });
- $scope.selectedMailFolder.etatAttentes = newArray;
- }
-
// right
$scope.selectedMailFolder.rightUsers = [];
$scope.selectedMailFolder.rightGroups = [];
@@ -666,7 +658,7 @@
// selection/deselection d'un état d'attente possible pour ce dossier
$scope.changeFolderEtatAttente = function(etatAttente) {
- var index = $scope.selectedMailFolder.etatAttentes.indexOf(etatAttente);
+ var index = $scope.selectedMailFolder.etatAttentes.indexOfByTopiaId(etatAttente);
if (index != -1) {
$scope.selectedMailFolder.etatAttentes.splice(index, 1);
} else {
@@ -674,7 +666,7 @@
}
};
- // initialise la liste des actions possibles avec celle des niveaux supérieurs
+ // initialise la liste des colonnes sélectionnées avec celle des niveaux supérieurs
$scope.initFolderColumns = function() {
if ($scope.selectedMailFolder.useCurrentLevelTableColumns) {
if ($scope.parentScopeValues.folderTableColumns) {
@@ -697,13 +689,27 @@
// add user write right
$scope.addRightUser = function() {
$scope.selectedMailFolder.rightUsers.push($scope.newRightUser);
- delete $scope.newWriteRightUser;
+ delete $scope.newRightUser;
};
// remove user write right
- $scope.removeRightUser = function(index) {
+ $scope.removeRightUser = function(index, user) {
if ($window.confirm("Êtes-vous sur de vouloir supprimer les droits de cet utilisateur ?")) {
$scope.selectedMailFolder.rightUsers.splice(index, 1);
+
+ // suppression des droits réels
+ var index = $scope.selectedMailFolder.readRightUsers.indexOfByTopiaId(user);
+ if (index != -1) {
+ $scope.selectedMailFolder.readRightUsers.splice(index, 1);
+ }
+ var index = $scope.selectedMailFolder.writeRightUsers.indexOfByTopiaId(user);
+ if (index != -1) {
+ $scope.selectedMailFolder.writeRightUsers.splice(index, 1);
+ }
+ var index = $scope.selectedMailFolder.moveRightUsers.indexOfByTopiaId(user);
+ if (index != -1) {
+ $scope.selectedMailFolder.moveRightUsers.splice(index, 1);
+ }
}
};
@@ -714,55 +720,74 @@
};
// remove group write right
- $scope.removeWriteRightGroup = function(index) {
+ $scope.removeRightGroup = function(index, group) {
if ($window.confirm("Êtes-vous sur de vouloir supprimer les droits de ce groupe ?")) {
$scope.selectedMailFolder.rightGroups.splice(index, 1);
+
+ // suppression des droits réels
+ var index = $scope.selectedMailFolder.readRightGroups.indexOfByTopiaId(group);
+ if (index != -1) {
+ $scope.selectedMailFolder.readRightGroups.splice(index, 1);
+ }
+ index = $scope.selectedMailFolder.writeRightGroups.indexOfByTopiaId(group);
+ if (index != -1) {
+ $scope.selectedMailFolder.writeRightGroups.splice(index, 1);
+ }
+ index = $scope.selectedMailFolder.moveRightGroups.indexOfByTopiaId(group);
+ if (index != -1) {
+ $scope.selectedMailFolder.moveRightGroups.splice(index, 1);
+ }
}
};
- //
+ // change le droit de lecture du groupe
$scope.changeReadRightGroup = function(group) {
- var index = $scope.selectedMailFolder.readRightGroups.indexOf(group);
+ var index = $scope.selectedMailFolder.readRightGroups.indexOfByTopiaId(group);
if (index != -1) {
$scope.selectedMailFolder.readRightGroups.splice(index, 1);
} else {
$scope.selectedMailFolder.readRightGroups.push(group);
}
};
+ // change le droit d'écriture du groupe
$scope.changeWriteRightGroup = function(group) {
- var index = $scope.selectedMailFolder.writeRightGroups.indexOf(group);
+ var index = $scope.selectedMailFolder.writeRightGroups.indexOfByTopiaId(group);
if (index != -1) {
$scope.selectedMailFolder.writeRightGroups.splice(index, 1);
} else {
$scope.selectedMailFolder.writeRightGroups.push(group);
}
};
+ // change le droit de déplacement du groupe
$scope.changeMoveRightGroup = function(group) {
- var index = $scope.selectedMailFolder.moveRightGroups.indexOf(group);
+ var index = $scope.selectedMailFolder.moveRightGroups.indexOfByTopiaId(group);
if (index != -1) {
$scope.selectedMailFolder.moveRightGroups.splice(index, 1);
} else {
$scope.selectedMailFolder.moveRightGroups.push(group);
}
};
+ // change le droit de lecture d'un utilisateur
$scope.changeReadRightUser = function(user) {
- var index = $scope.selectedMailFolder.readRightUsers.indexOf(user);
+ var index = $scope.selectedMailFolder.readRightUsers.indexOfByTopiaId(user);
if (index != -1) {
$scope.selectedMailFolder.readRightUsers.splice(index, 1);
} else {
$scope.selectedMailFolder.readRightUsers.push(user);
}
};
+ // change le droit d'écriture d'un utilisateur
$scope.changeWriteRightUser = function(user) {
- var index = $scope.selectedMailFolder.writeRightUsers.indexOf(user);
+ var index = $scope.selectedMailFolder.writeRightUsers.indexOfByTopiaId(user);
if (index != -1) {
$scope.selectedMailFolder.writeRightUsers.splice(index, 1);
} else {
$scope.selectedMailFolder.writeRightUsers.push(user);
}
};
+ // change le droit de déplacement d'un utilisateur
$scope.changeMoveRightUser = function(user) {
- var index = $scope.selectedMailFolder.moveRightUsers.indexOf(user);
+ var index = $scope.selectedMailFolder.moveRightUsers.indexOfByTopiaId(user);
if (index != -1) {
$scope.selectedMailFolder.moveRightUsers.splice(index, 1);
} else {
@@ -784,7 +809,7 @@
//{Object} New accout empty filter
$scope.newFilter = {};
- // replace filter instance with mailFolder filter instance to use same objects
+ // replace filter instance with mailFolder filter instance to use same objects (filled with fullPathInfo)
var updateMetaFilter = function() {
angular.forEach($scope.mailFilters, function(filter) {
// root folder
@@ -807,6 +832,7 @@
console.log("Udpate MetaFilter");
$scope.rootFolderMailFilters = {};
updateMetaFilter();
+ console.log($scope.rootFolderMailFilters);
});
// option de la configuration 'sortable'
@@ -823,6 +849,9 @@
// add new filter action
$scope.addNewFilter = function(rootMailFolder) {
$scope.mailFilters.push($scope.newFilter);
+ if (!$scope.rootFolderMailFilters.hasOwnProperty(rootMailFolder.topiaId)) {
+ $scope.rootFolderMailFilters[rootMailFolder.topiaId] = [];
+ }
$scope.rootFolderMailFilters[rootMailFolder.topiaId].push($scope.newFilter);
// clear form
$scope.newFilter = {};
Modified: trunk/faxtomail-ui-web/src/main/webapp/js/faxtomail.js
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/js/faxtomail.js 2014-06-12 13:40:31 UTC (rev 198)
+++ trunk/faxtomail-ui-web/src/main/webapp/js/faxtomail.js 2014-06-12 14:59:17 UTC (rev 199)
@@ -37,5 +37,30 @@
return _p8() + _p8(true) + _p8(true) + _p8();
}
+console.log("abc" === "abc");// true
+console.log("abc" === new String("abc")); // false
+console.log(new String("abc") === new String("abc")); // false
+
+/**
+ * Même fonction que indexOf mais qui compare par topiaId au lieu des références.
+ */
+Array.prototype.indexOfByTopiaId = function(obj) {
+ var i = this.length;
+ while (i--) {
+ if (this[i].topiaId == obj.topiaId) {
+ return i;
+ }
+ }
+ return -1;
+};
+
+/**
+ * Method contains par topiaId.
+ */
+Array.prototype.containsByTopiaId = function(obj) {
+ return this.indexOfByTopiaId(obj) != -1;
+};
+
+
/** Mail faxtomail application module. */
var FaxToMailModule = angular.module('FaxToMail', ['ui.bootstrap']);
1
0
r198 - trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin
by echatellier@users.forge.codelutin.com 12 Jun '14
by echatellier@users.forge.codelutin.com 12 Jun '14
12 Jun '14
Author: echatellier
Date: 2014-06-12 15:40:31 +0200 (Thu, 12 Jun 2014)
New Revision: 198
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/198
Log:
Ajout d'explication concernant l'import ldap
Modified:
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/ldap-input.jsp
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/ldap-input.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/ldap-input.jsp 2014-06-12 13:32:28 UTC (rev 197)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/ldap-input.jsp 2014-06-12 13:40:31 UTC (rev 198)
@@ -28,6 +28,14 @@
<html>
<head>
<title>Ldap</title>
+
+ <script type="text/javascript">
+ function disableAndSubmit() {
+ $("#submit_button").attr("disabled", true);
+ $("#submit_button").text("Mise à jour en cours...");
+ $("#main_form").submit();
+ }
+ </script>
</head>
<body>
@@ -37,14 +45,11 @@
<h1 class="page-header">Ldap</h1>
<s:form id="main_form" action="ldap" method="post">
-
- <button type="submit" class="btn btn-primary navbar-btn">Mettre à jour les groupes et utilisateurs LDAP</button>
- <nav class="navbar navbar-default navbar-fixed-bottom">
- <!-- <div class="container">
- <button type="submit" class="btn btn-primary navbar-btn pull-right">Valider</button>
- </div> -->
- </nav>
+ Cette action permet d'importer tout les utilisateurs et les groupes du serveur Active Directory dans l'application FaxToMail. Cette action peut prendre quelques minutes.
+
+ <button id="submit_button" type="button" class="btn btn-primary navbar-btn" onclick="disableAndSubmit()">Mettre à jour les groupes et utilisateurs LDAP</button>
+
</s:form>
</div>
</body>
1
0
r197 - in trunk: faxtomail-persistence/src/main/java/com/franciaflex/faxtomail faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin faxtomail-ui-web/src/main/webapp/WEB-INF/content faxtomail-ui-web/src/main/webapp/WEB-INF/decorators
by echatellier@users.forge.codelutin.com 12 Jun '14
by echatellier@users.forge.codelutin.com 12 Jun '14
12 Jun '14
Author: echatellier
Date: 2014-06-12 15:32:28 +0200 (Thu, 12 Jun 2014)
New Revision: 197
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/197
Log:
Autorisation d'acces ?\195?\160 la partie admin suivant le groupe d?\195?\169fini dans la config
Modified:
trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java
trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/IndexAction.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportAction.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/index.jsp
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp
Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java
===================================================================
--- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -255,7 +255,11 @@
public String getLdapBaseDn() {
return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_BASEDN.getKey());
}
-
+
+ public String getLdapAdminGroup() {
+ return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_ADMIN_GROUP.getKey());
+ }
+
public String getLdapPrincipalDomain() {
return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_PRINCIPAL_DOMAIN.getKey());
}
Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java
===================================================================
--- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -107,9 +107,13 @@
"faxtomail.ldap.basedn",
"Mot de passe pour la connexion au serveur LDAP", "DC=mac-groupe,DC=net", String.class),
+ LDAP_ADMIN_GROUP(
+ "faxtomail.ldap.admin.group",
+ "DN du groupe ldap ayant les autorisations d'accéder à la partie admin de l'interface web", null, String.class),
+
LDAP_PRINCIPAL_DOMAIN(
"faxtomail.ldap.principal.domain",
- "Mot de passe pour la connexion au serveur LDAP", "mac-groupe.net", String.class),
+ "Domaine des principals utilisés par l'authentification kerberos", "mac-groupe.net", String.class),
LDAP_TEST_PRINCIPAL(
"faxtomail.ldap.test.principal",
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailActionSupport.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -85,6 +85,10 @@
return session.getAuthenticatedFaxToMailUser() != null;
}
+ public boolean isAdmin() {
+ return session.isAdmin();
+ }
+
public FaxToMailUser getAuthenticatedUser() {
return session.getAuthenticatedFaxToMailUser();
}
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailInterceptor.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -38,6 +38,7 @@
import com.franciaflex.faxtomail.FaxToMailConfiguration;
import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaPersistenceContext;
import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser;
+import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup;
import com.franciaflex.faxtomail.services.FaxToMailService;
import com.franciaflex.faxtomail.services.FaxToMailServiceContext;
import com.franciaflex.faxtomail.services.service.LdapService;
@@ -63,7 +64,6 @@
@Override
public String intercept(ActionInvocation invocation) throws Exception {
-
Object action = invocation.getAction();
if (action instanceof FaxToMailActionSupport) {
@@ -140,8 +140,17 @@
LdapService ldapService = serviceContext.newService(LdapService.class);
FaxToMailUser user = ldapService.getUserBean(faxToMailSession.getAuthenticatedUserId());
faxToMailSession.setAuthenticatedFaxToMailUser(user);
+
+ // test si l'utilisateur est admin
+ String adminGroup = serviceContext.getApplicationConfig().getLdapAdminGroup();
+ if (StringUtils.isNotBlank(adminGroup) && user.getUserGroups() != null) {
+ for (FaxToMailUserGroup group : user.getUserGroups()) {
+ if (adminGroup.equals(group.getFullPath())) {
+ faxToMailSession.setAdmin(true);
+ }
+ }
+ }
}
-
}
protected void saveLastAction(ActionInvocation invocation) {
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -41,6 +41,8 @@
protected String authenticatedUserId;
protected transient FaxToMailUser authenticatedFaxToMailUser;
+
+ protected transient boolean admin;
public Collection<String> getMessages() {
if (messages == null) {
@@ -84,4 +86,12 @@
setAuthenticatedUserId(null);
setAuthenticatedFaxToMailUser(null);
}
+
+ public boolean isAdmin() {
+ return admin;
+ }
+
+ public void setAdmin(boolean admin) {
+ this.admin = admin;
+ }
}
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/IndexAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/IndexAction.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/IndexAction.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -32,8 +32,9 @@
import org.apache.struts2.convention.annotation.InterceptorRefs;
@InterceptorRefs({
+ @InterceptorRef("faxToMailInterceptor"),
@InterceptorRef("loginInterceptor"),
- @InterceptorRef("faxToMailStack")
+ @InterceptorRef("paramsPrepareParamsStack")
})
public class IndexAction extends FaxToMailActionSupport {
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -64,7 +64,7 @@
@Override
@Action(results = {
- @Result(type = "redirectAction", params = {"actionName", "configuration-input", "namespace", "/admin"})})
+ @Result(type = "redirectAction", params = {"actionName", "index", "namespace", "/"})})
public String execute() {
String result = SUCCESS;
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -30,6 +30,7 @@
import java.util.Map;
import com.franciaflex.faxtomail.persistence.entities.MailField;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
@@ -59,8 +60,9 @@
* @since x.x
*/
@InterceptorRefs({
+ @InterceptorRef("faxToMailInterceptor"),
@InterceptorRef("loginInterceptor"),
- @InterceptorRef("faxToMailStack")
+ @InterceptorRef("paramsPrepareParamsStack")
})
public class ConfigurationAction extends FaxToMailActionSupport implements Preparable {
@@ -94,7 +96,10 @@
@Override
public void prepare() throws Exception {
-
+ // check authorization
+ if (!getSession().isAdmin()) {
+ throw new RuntimeException("Not authorized");
+ }
}
@Override
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportAction.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportAction.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -37,12 +37,14 @@
import com.franciaflex.faxtomail.services.service.ReferentielService;
import com.franciaflex.faxtomail.web.FaxToMailActionSupport;
+import com.opensymphony.xwork2.Preparable;
@InterceptorRefs({
+ @InterceptorRef("faxToMailInterceptor"),
@InterceptorRef("loginInterceptor"),
- @InterceptorRef("faxToMailStack")
+ @InterceptorRef("paramsPrepareParamsStack")
})
-public class ImportAction extends FaxToMailActionSupport {
+public class ImportAction extends FaxToMailActionSupport implements Preparable {
private static final Log log = LogFactory.getLog(ImportAction.class);
@@ -79,6 +81,14 @@
}
@Override
+ public void prepare() throws Exception {
+ // check authorization
+ if (!getSession().isAdmin()) {
+ throw new RuntimeException("Not authorized");
+ }
+ }
+
+ @Override
@Action("import-input")
public String input() throws Exception {
return INPUT;
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/LdapAction.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -33,12 +33,14 @@
import com.franciaflex.faxtomail.services.service.LdapService;
import com.franciaflex.faxtomail.web.FaxToMailActionSupport;
+import com.opensymphony.xwork2.Preparable;
@InterceptorRefs({
+ @InterceptorRef("faxToMailInterceptor"),
@InterceptorRef("loginInterceptor"),
- @InterceptorRef("faxToMailStack")
+ @InterceptorRef("paramsPrepareParamsStack")
})
-public class LdapAction extends FaxToMailActionSupport {
+public class LdapAction extends FaxToMailActionSupport implements Preparable {
private static final Log log = LogFactory.getLog(LdapAction.class);
@@ -49,6 +51,14 @@
}
@Override
+ public void prepare() throws Exception {
+ // check authorization
+ if (!getSession().isAdmin()) {
+ throw new RuntimeException("Not authorized");
+ }
+ }
+
+ @Override
@Action("ldap-input")
public String input() throws Exception {
return INPUT;
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/UserFolderAction.java 2014-06-12 13:32:28 UTC (rev 197)
@@ -44,10 +44,12 @@
import com.franciaflex.faxtomail.services.service.MailFolderService;
import com.franciaflex.faxtomail.web.FaxToMailActionSupport;
import com.google.gson.reflect.TypeToken;
+import com.opensymphony.xwork2.Preparable;
@InterceptorRefs({
+ @InterceptorRef("faxToMailInterceptor"),
@InterceptorRef("loginInterceptor"),
- @InterceptorRef("faxToMailStack")
+ @InterceptorRef("paramsPrepareParamsStack")
})
public class UserFolderAction extends FaxToMailActionSupport {
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/index.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/index.jsp 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/index.jsp 2014-06-12 13:32:28 UTC (rev 197)
@@ -33,12 +33,14 @@
<h1 class="page-header">Administration FaxToMail</h1>
<ul>
- <li><a href="<s:url action='ldap-input' namespace="/admin" />">
- <span class="fa fa-database"></span> Ldap</a></li>
- <li><a href="<s:url action='configuration-input' namespace="/admin" />">
- <span class="fa fa-cog"></span> Configuration</a></li>
- <li><a href="<s:url action='import-input' namespace="/admin" />">
- <span class="fa fa-upload"></span> Import</a></li>
+ <s:if test="admin">
+ <li><a href="<s:url action='ldap-input' namespace="/admin" />">
+ <span class="fa fa-database"></span> Ldap</a></li>
+ <li><a href="<s:url action='configuration-input' namespace="/admin" />">
+ <span class="fa fa-cog"></span> Configuration</a></li>
+ <li><a href="<s:url action='import-input' namespace="/admin" />">
+ <span class="fa fa-upload"></span> Import</a></li>
+ </s:if>
<li><a href="<s:url action='user-folder-input' namespace="/admin" />">
<span class="fa fa-folder-open"></span> Dossiers utilisateur</a></li>
</ul>
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp 2014-06-12 13:32:28 UTC (rev 197)
@@ -40,7 +40,7 @@
<div class="form-group">
<label for="loginField" class="col-sm-2 control-label">Identifiant LDAP :</label>
<div class="col-sm-10">
- <input type="text" name="login" class="form-control" id="loginField" placeholder="nom.prenom(a)franciaflex.fr" required>
+ <input type="text" name="login" class="form-control" id="loginField" placeholder="ex: dupont" required>
</div>
</div>
<div class="form-group">
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2014-06-12 12:33:22 UTC (rev 196)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2014-06-12 13:32:28 UTC (rev 197)
@@ -55,12 +55,16 @@
<s:if test="authenticated">
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
- <li><a href="<s:url action='ldap-input' namespace="/admin" />">
- <span class="fa fa-database"></span> Ldap</a></li>
- <li><a href="<s:url action='configuration-input' namespace="/admin" />">
- <span class="fa fa-cog"></span> Configuration</a></li>
- <li><a href="<s:url action='import-input' namespace="/admin" />">
- <span class="fa fa-upload"></span> Import</a></li>
+
+ <s:if test="admin">
+ <li><a href="<s:url action='ldap-input' namespace="/admin" />">
+ <span class="fa fa-database"></span> Ldap</a></li>
+ <li><a href="<s:url action='configuration-input' namespace="/admin" />">
+ <span class="fa fa-cog"></span> Configuration</a></li>
+ <li><a href="<s:url action='import-input' namespace="/admin" />">
+ <span class="fa fa-upload"></span> Import</a></li>
+ </s:if>
+
<li><a href="<s:url action='user-folder-input' namespace="/admin" />">
<span class="fa fa-folder-open"></span> Dossiers utilisateur</a></li>
</ul>
1
0
r196 - trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service
by echatellier@users.forge.codelutin.com 12 Jun '14
by echatellier@users.forge.codelutin.com 12 Jun '14
12 Jun '14
Author: echatellier
Date: 2014-06-12 14:33:22 +0200 (Thu, 12 Jun 2014)
New Revision: 196
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/196
Log:
Fix npe
Modified:
trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
===================================================================
--- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 17:03:55 UTC (rev 195)
+++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-12 12:33:22 UTC (rev 196)
@@ -174,28 +174,30 @@
userDN = searchEntry.getDN();
}
adminConnect.close();
- } else {
- throw new AuthenticationException("Utilisateur inconnu : " + login);
}
- // ouvre une connexion avec l'identification de l'utilisateur qui essaye de se connecter
- // à l'application (ca permet de vérifier l'authentification)
- LDAPConnection userConnect = new LDAPConnection();
- userConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
- userConnect.bind(userDN, password);
-
- if (userConnect.isConnected()) {
- // update in database
- FaxToMailUser user = updateUserFormLdap(searchEntry, login);
- getPersistenceContext().commit();
-
- // return copy without sensible informations
- Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
- result = new FaxToMailUserImpl();
- faxToMailUserBinder.copyExcluding(user, result);
- userConnect.close();
+ if (searchEntry != null) {
+ // ouvre une connexion avec l'identification de l'utilisateur qui essaye de se connecter
+ // à l'application (ca permet de vérifier l'authentification)
+ LDAPConnection userConnect = new LDAPConnection();
+ userConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
+ userConnect.bind(userDN, password);
+
+ if (userConnect.isConnected()) {
+ // update in database
+ FaxToMailUser user = updateUserFormLdap(searchEntry, login);
+ getPersistenceContext().commit();
+
+ // return copy without sensible informations
+ Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
+ result = new FaxToMailUserImpl();
+ faxToMailUserBinder.copyExcluding(user, result);
+ userConnect.close();
+ } else {
+ throw new AuthenticationException("Not connected");
+ }
} else {
- throw new AuthenticationException("Not connected");
+ throw new AuthenticationException("Utilisateur inconnu : " + login);
}
} catch (LDAPException ex) {
1
0
r195 - in trunk: faxtomail-persistence/src/main/java/com/franciaflex/faxtomail faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ldap faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service
by echatellier@users.forge.codelutin.com 11 Jun '14
by echatellier@users.forge.codelutin.com 11 Jun '14
11 Jun '14
Author: echatellier
Date: 2014-06-11 19:03:55 +0200 (Wed, 11 Jun 2014)
New Revision: 195
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/195
Log:
Import des utilisateurs et groupe du ldap (tous !!!)
Removed:
trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ldap/LdapUser.java
trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/LdapServiceTest.java
Modified:
trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java
trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java
trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java
trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java
===================================================================
--- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-11 16:00:34 UTC (rev 194)
+++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-11 17:03:55 UTC (rev 195)
@@ -251,6 +251,14 @@
public String getLdapPassword() {
return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_PASSWORD.getKey());
}
+
+ public String getLdapBaseDn() {
+ return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_BASEDN.getKey());
+ }
+
+ public String getLdapPrincipalDomain() {
+ return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_PRINCIPAL_DOMAIN.getKey());
+ }
public String getLdapTestPrincipal() {
return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_TEST_PRINCIPAL.getKey());
Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java
===================================================================
--- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-11 16:00:34 UTC (rev 194)
+++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-11 17:03:55 UTC (rev 195)
@@ -103,6 +103,14 @@
"faxtomail.ldap.password",
"Mot de passe pour la connexion au serveur LDAP", null, String.class),
+ LDAP_BASEDN(
+ "faxtomail.ldap.basedn",
+ "Mot de passe pour la connexion au serveur LDAP", "DC=mac-groupe,DC=net", String.class),
+
+ LDAP_PRINCIPAL_DOMAIN(
+ "faxtomail.ldap.principal.domain",
+ "Mot de passe pour la connexion au serveur LDAP", "mac-groupe.net", String.class),
+
LDAP_TEST_PRINCIPAL(
"faxtomail.ldap.test.principal",
"Principal de test pour forcer un utilsateur particulier", null, String.class),
Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java
===================================================================
--- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java 2014-06-11 16:00:34 UTC (rev 194)
+++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java 2014-06-11 17:03:55 UTC (rev 195)
@@ -211,7 +211,7 @@
public List<FaxToMailUser> getAllUsers() {
FaxToMailUserTopiaDao faxToMailUserDao = getPersistenceContext().getFaxToMailUserDao();
- return faxToMailUserDao.forAll().setOrderByArguments(FaxToMailUser.PROPERTY_FIRST_NAME, FaxToMailUser.PROPERTY_LAST_NAME).find(0, 50);
+ return faxToMailUserDao.forAll().setOrderByArguments(FaxToMailUser.PROPERTY_FIRST_NAME, FaxToMailUser.PROPERTY_LAST_NAME).findAll();
}
public void saveUserFolders(Map<String, Collection<MailFolder>> userFolders) {
Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
===================================================================
--- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 16:00:34 UTC (rev 194)
+++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 17:03:55 UTC (rev 195)
@@ -42,7 +42,6 @@
import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao;
import com.franciaflex.faxtomail.services.FaxToMailServiceSupport;
import com.franciaflex.faxtomail.services.service.ldap.AuthenticationException;
-import com.franciaflex.faxtomail.services.service.ldap.LdapUser;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPSearchException;
@@ -55,82 +54,42 @@
private static final Log log = LogFactory.getLog(LdapService.class);
/**
- * Get ldap connection.
- *
- * @return
- * @throws LDAPException
+ * Update all user and group from ldap.
*/
- protected LDAPConnection getLDAPConnection() throws LDAPException {
- // host, port, username and password
- return new LDAPConnection(getApplicationConfig().getLdapHost(),
- getApplicationConfig().getLdapPort(),
- getApplicationConfig().getLdapUser(),
- getApplicationConfig().getLdapPassword());
- }
+ public void updateLdapData() {
- /**
- * Get all user from ldap.
- *
- * @return ldap users with group infos
- */
- public Collection<LdapUser> getAllLdapUsers() {
- Collection<LdapUser> results = new ArrayList<>();
-
- // ldapsearch -h ldap.codelutin.home -b "ou=People,DC=codelutin,DC=home" "objectClass=posixGroup"
- // ldapsearch -h ldap.codelutin.home -b "ou=People,DC=codelutin,DC=home" "objectClass=account"
- String[] baseDNs = {
- "OU=Utilisateurs,OU=Faber,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=OU Informatique,OU=France-Fermetures,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
-
- // OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net
- "OU=Utilisateurs,OU=Carros,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=Checy,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=Guipry,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=LeRheu,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=Luzech,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=MaisonAlfort,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=Mauguio,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=Migennes,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=Nomades,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net",
- "OU=Utilisateurs,OU=RocheToirin,OU=Franciaflex,OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net"
- };
- String filter = "(objectClass=user)";
-
LDAPConnection connection = null;
try {
- connection = getLDAPConnection();
+ connection = new LDAPConnection(getApplicationConfig().getLdapHost(),
+ getApplicationConfig().getLdapPort(),
+ getApplicationConfig().getLdapUser(),
+ getApplicationConfig().getLdapPassword());
if (connection.isConnected()) {
- for (String baseDN : baseDNs) {
- SearchResult searchResult = connection.search(baseDN, SearchScope.ONE, filter);
+ String baseDN = "OU=Utilisateurs,OU=Mac-Groupe,DC=mac-groupe,DC=net";
+ // on recupere d'abord les organisationUnit
+ SearchResult unitResult = connection.search(baseDN, SearchScope.SUB, "(objectClass=organizationalUnit)");
+ List<SearchResultEntry> unitEntries = unitResult.getSearchEntries();
+ for (SearchResultEntry unitEntry : unitEntries) {
+ if (log.isDebugEnabled()) {
+ log.debug("Search for unit " + unitEntry.getDN());
+ }
+ SearchResult userResult = connection.search(unitEntry.getDN(), SearchScope.ONE, "(objectClass=user)");
- List<SearchResultEntry> searchEntries = searchResult.getSearchEntries();
- for (SearchResultEntry searchEntry : searchEntries) {
- LdapUser user = new LdapUser();
- user.setLogin(searchEntry.getAttributeValue("sn"));
+ List<SearchResultEntry> userEntries = userResult.getSearchEntries();
+ for (SearchResultEntry userEntry : userEntries) {
- // Parse name
- String fullName = searchEntry.getAttributeValue("name");
- if (fullName.indexOf(' ') != -1) {
- String lastName = fullName.substring(0, fullName.indexOf(' '));
- String firstName = fullName.substring(fullName.indexOf(' ') + 1);
- user.setFirstName(firstName);
- user.setLastName(lastName);
+ String login = userEntry.getAttributeValue("sn");
+ if (login == null) {
+ if (log.isWarnEnabled()) {
+ log.warn("Null sn for DN " + userEntry.getDN());
+ }
} else {
- user.setFirstName("");
- user.setLastName(fullName);
+ updateUserFormLdap(userEntry, login);
}
-
- // parse groups
- String[] groups = searchEntry.getAttributeValues("memberOf");
- if (ArrayUtils.isNotEmpty(groups)) {
- for (String group : groups) {
- user.addGroup(group);
- }
- }
-
- results.add(user);
}
}
+
+ getPersistenceContext().commit();
}
} catch (LDAPException ex) {
throw new RuntimeException("Can't connect to ldap", ex);
@@ -139,72 +98,9 @@
connection.close();
}
}
-
- return results;
}
/**
- * Recupere les utilisateurs/groupes du ldap et met à jour la base locale.
- */
- public void updateLdapData() {
- if (StringUtils.isBlank(getApplicationConfig().getLdapHost())) {
- if (log.isDebugEnabled()) {
- log.debug("Ldap service not configured !");
- }
- return;
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Updating user data from ldap");
- }
- }
-
- Collection<LdapUser> ldapUsers = getAllLdapUsers();
-
- FaxToMailUserTopiaDao faxtomailUserDao = getPersistenceContext().getFaxToMailUserDao();
- FaxToMailUserGroupTopiaDao faxToMailUserGroupDao = getPersistenceContext().getFaxToMailUserGroupDao();
- Binder<FaxToMailUser, FaxToMailUser> userBinder = BinderFactory.newBinder(FaxToMailUser.class);
- for (LdapUser ldapUser : ldapUsers) {
-
- // manage user from login
- FaxToMailUser user = faxtomailUserDao.forLoginEquals(ldapUser.getLogin()).findUniqueOrNull();
- if (user == null) {
- user = new FaxToMailUserImpl();
- }
-
- // FIXME echatellier 20140601 : it's not necessary to save user in database if information didn't change
- userBinder.copyExcluding(ldapUser, user,
- FaxToMailUser.PROPERTY_TOPIA_ID,
- FaxToMailUser.PROPERTY_TOPIA_CREATE_DATE,
- FaxToMailUser.PROPERTY_TOPIA_VERSION,
- FaxToMailUser.PROPERTY_USER_GROUPS);
-
- // manage user group
- Collection<String> groups = ldapUser.getGroups();
- user.clearUserGroups();
- for (String group : groups) {
- String groupPath = getGroupFullPath(group);
- String groupName = StringUtils.substringAfterLast(groupPath, "/");
- FaxToMailUserGroup userGroup = faxToMailUserGroupDao.forNameEquals(groupName).findUniqueOrNull();
- if (userGroup == null) {
- userGroup = faxToMailUserGroupDao.create(
- FaxToMailUserGroup.PROPERTY_NAME, groupName,
- FaxToMailUserGroup.PROPERTY_FULL_PATH, groupPath);
- }
- user.addUserGroups(userGroup);
- }
-
- // persist user
- if (user.isPersisted()) {
- faxtomailUserDao.update(user);
- } else {
- faxtomailUserDao.create(user);
- }
- }
-
- getPersistenceContext().commit();
- }
-
- /**
* Transform group CN to group path.
*
* Example:
@@ -215,10 +111,18 @@
* @return
*/
protected String getGroupFullPath(String groupCN) {
- String[] part = groupCN.split(",");
- ArrayUtils.reverse(part);
- String result = StringUtils.join(part, '/');
- return result;
+ String[] parts = groupCN.split(",");
+ ArrayUtils.reverse(parts);
+
+ // join tab
+ String separator = "";
+ StringBuilder result = new StringBuilder();
+ for (String part : parts) {
+ result.append(separator);
+ result.append(StringUtils.substringAfter(part, "="));
+ separator = "/";
+ }
+ return result.toString();
}
/**
@@ -241,7 +145,7 @@
}
/**
- * Authenticate user.
+ * Authenticate and update ldap user.
*
* @param login login
* @param password password
@@ -262,34 +166,36 @@
String userDN = null;
SearchResultEntry searchEntry = null;
if (adminConnect.isConnected()) {
+ // sn est le login interne à franciaflex
String filter = String.format("(sn=%s)", login);
- SearchResult searchResult = adminConnect.search("DC=mac-groupe,DC=net", SearchScope.SUB, filter);
+ SearchResult searchResult = adminConnect.search(getApplicationConfig().getLdapBaseDn(), SearchScope.SUB, filter);
if (!searchResult.getSearchEntries().isEmpty()) {
searchEntry = searchResult.getSearchEntries().get(0);
userDN = searchEntry.getDN();
}
adminConnect.close();
+ } else {
+ throw new AuthenticationException("Utilisateur inconnu : " + login);
}
- if (searchEntry != null) {
- // ouvre une connexion avec l'identification de l'utilisateur qui essaye de se connecter
- // à l'application (ca permet de vérifier l'authentification)
- LDAPConnection userConnect = new LDAPConnection();
- userConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
- userConnect.bind(userDN, password);
-
- if (userConnect.isConnected()) {
- FaxToMailUser user = updateUserFormLdap(searchEntry, login);
-
- Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
- result = new FaxToMailUserImpl();
- faxToMailUserBinder.copyExcluding(user, result);
- userConnect.close();
- } else {
- throw new AuthenticationException("Not connected");
- }
+ // ouvre une connexion avec l'identification de l'utilisateur qui essaye de se connecter
+ // à l'application (ca permet de vérifier l'authentification)
+ LDAPConnection userConnect = new LDAPConnection();
+ userConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
+ userConnect.bind(userDN, password);
+
+ if (userConnect.isConnected()) {
+ // update in database
+ FaxToMailUser user = updateUserFormLdap(searchEntry, login);
+ getPersistenceContext().commit();
+
+ // return copy without sensible informations
+ Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
+ result = new FaxToMailUserImpl();
+ faxToMailUserBinder.copyExcluding(user, result);
+ userConnect.close();
} else {
- throw new AuthenticationException("Utilisateur inconnu : " + login);
+ throw new AuthenticationException("Not connected");
}
} catch (LDAPException ex) {
@@ -300,42 +206,16 @@
}
return result;
}
-
- protected FaxToMailUser updateUserFormLdap(SearchResultEntry searchEntry, String login) throws LDAPSearchException {
- FaxToMailUser result = null;
-
- // create or
- FaxToMailUserTopiaDao faxtomailUserDao = getPersistenceContext().getFaxToMailUserDao();
- result = faxtomailUserDao.forLoginEquals(login).findUniqueOrNull();
-
- if (result == null) {
- result = new FaxToMailUserImpl();
- result.setLogin(login);
- }
-
- // update other ldap fields
- String fullName = searchEntry.getAttributeValue("name");
- if (fullName.indexOf(' ') != -1) {
- String lastName = fullName.substring(0, fullName.indexOf(' '));
- String firstName = fullName.substring(fullName.indexOf(' ') + 1);
- result.setFirstName(firstName);
- result.setLastName(lastName);
- } else {
- result.setFirstName("");
- result.setLastName(fullName);
- }
-
- if (result.isPersisted()) {
- result = faxtomailUserDao.update(result);
- } else {
- result = faxtomailUserDao.create(result);
- }
- getPersistenceContext().commit();
-
- return result;
- }
-
+ /**
+ * Retreive user from principal and updated user database instance.
+ *
+ * This method doesn't require any password.
+ *
+ * @param principal user principal (without domain)
+ * @return user instance
+ * @throws AuthenticationException is user can't be found in ldap
+ */
public FaxToMailUser getUserFromPrincipal(String principal) throws AuthenticationException {
FaxToMailUser result = null;
@@ -350,25 +230,29 @@
String login = null;
SearchResultEntry searchEntry = null;
if (adminConnect.isConnected()) {
- String filter = String.format("(userPrincipalName=%s@%s)", principal, "mac-groupe.net");
- SearchResult searchResult = adminConnect.search("DC=mac-groupe,DC=net", SearchScope.SUB, filter);
+ // userPrincipalName est l'identifiant kerberos
+ // xxx(a)mac-groupe.net
+ String filter = String.format("(userPrincipalName=%s@%s)", principal, getApplicationConfig().getLdapPrincipalDomain());
+ SearchResult searchResult = adminConnect.search(getApplicationConfig().getLdapBaseDn(), SearchScope.SUB, filter);
if (!searchResult.getSearchEntries().isEmpty()) {
searchEntry = searchResult.getSearchEntries().get(0);
+ // sn est le 'login' interne a franciaflex
login = searchEntry.getAttributeValue("sn");
}
adminConnect.close();
- }
-
- if (searchEntry != null) {
- FaxToMailUser user = updateUserFormLdap(searchEntry, login);
-
- Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
- result = new FaxToMailUserImpl();
- faxToMailUserBinder.copyExcluding(user, result);
} else {
throw new AuthenticationException("Utilisateur inconnu : " + principal);
}
+ // update in database
+ FaxToMailUser user = updateUserFormLdap(searchEntry, login);
+ getPersistenceContext().commit();
+
+ // return copy without sensible informations
+ Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
+ result = new FaxToMailUserImpl();
+ faxToMailUserBinder.copyExcluding(user, result);
+
} catch (LDAPException ex) {
if (log.isWarnEnabled()) {
log.warn("Can't login to ldap", ex);
@@ -377,4 +261,64 @@
}
return result;
}
+
+ /**
+ * Update user (or create) in database from ldap search result entry.
+ *
+ * @param searchEntry entry containing data
+ * @param login login
+ * @return updated user
+ * @throws LDAPSearchException
+ */
+ protected FaxToMailUser updateUserFormLdap(SearchResultEntry searchEntry, String login) throws LDAPSearchException {
+
+ FaxToMailUser user = null;
+
+ // create or
+ FaxToMailUserTopiaDao faxtomailUserDao = getPersistenceContext().getFaxToMailUserDao();
+ FaxToMailUserGroupTopiaDao faxtomailUserGroupDao = getPersistenceContext().getFaxToMailUserGroupDao();
+ user = faxtomailUserDao.forLoginEquals(login).findUniqueOrNull();
+
+ if (user == null) {
+ user = new FaxToMailUserImpl();
+ user.setLogin(login);
+ }
+
+ // update other ldap fields
+ String fullName = searchEntry.getAttributeValue("name");
+ if (fullName.indexOf(' ') != -1) {
+ String lastName = fullName.substring(0, fullName.indexOf(' '));
+ String firstName = fullName.substring(fullName.indexOf(' ') + 1);
+ user.setFirstName(firstName);
+ user.setLastName(lastName);
+ } else {
+ user.setFirstName("");
+ user.setLastName(fullName);
+ }
+
+ // manage user groups
+ user.clearUserGroups();
+ String[] groups = searchEntry.getAttributeValues("memberOf");
+ if (ArrayUtils.isNotEmpty(groups)) {
+ for (String group : groups) {
+ String groupPath = getGroupFullPath(group);
+ String groupName = StringUtils.substringAfterLast(groupPath, "/");
+ FaxToMailUserGroup userGroup = faxtomailUserGroupDao.forNameEquals(groupName).findUniqueOrNull();
+ if (userGroup == null) {
+ userGroup = faxtomailUserGroupDao.create(
+ FaxToMailUserGroup.PROPERTY_NAME, groupName,
+ FaxToMailUserGroup.PROPERTY_FULL_PATH, groupPath);
+ }
+ user.addUserGroups(userGroup);
+ }
+ }
+
+ if (user.isPersisted()) {
+ user = faxtomailUserDao.update(user);
+ } else {
+ user = faxtomailUserDao.create(user);
+ }
+
+ return user;
+ }
}
Deleted: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ldap/LdapUser.java
===================================================================
--- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ldap/LdapUser.java 2014-06-11 16:00:34 UTC (rev 194)
+++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ldap/LdapUser.java 2014-06-11 17:03:55 UTC (rev 195)
@@ -1,47 +0,0 @@
-package com.franciaflex.faxtomail.services.service.ldap;
-
-/*
- * #%L
- * FaxToMail :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2014 Franciaflex, Code Lutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserImpl;
-
-public class LdapUser extends FaxToMailUserImpl {
-
- protected Collection<String> groups = new ArrayList<>();
-
- public Collection<String> getGroups() {
- return groups;
- }
-
- public void setGroups(Collection<String> groups) {
- this.groups = groups;
- }
-
- public void addGroup(String group) {
- this.groups.add(group);
- }
-}
Deleted: trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/LdapServiceTest.java
===================================================================
--- trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/LdapServiceTest.java 2014-06-11 16:00:34 UTC (rev 194)
+++ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/LdapServiceTest.java 2014-06-11 17:03:55 UTC (rev 195)
@@ -1,66 +0,0 @@
-package com.franciaflex.faxtomail.services.service;
-
-/*
- * #%L
- * FaxToMail :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2014 Franciaflex, Code Lutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.franciaflex.faxtomail.FaxToMailConfigurationOption;
-import com.franciaflex.faxtomail.services.service.ldap.LdapUser;
-
-public class LdapServiceTest extends AbstractFaxToMailServiceTest {
-
- protected LdapService ldapService;
-
- @Before
- public void setUp() throws IOException {
- ldapService = newService(LdapService.class);
-
- // n'effectue pas les tests si la connexion n'est pas possible
- Assume.assumeTrue(StringUtils.isNotBlank(getApplicationConfig().getLdapHost()));
- }
-
- @Test
- public void testGetUsers() {
-
- Collection<LdapUser> ldapUsers = ldapService.getAllLdapUsers();
- Collection<String> groups = new HashSet<>();
- int user = 0;
- for (LdapUser ldapUser : ldapUsers) {
- System.out.println("User : " + ldapUser.getLogin());
- for (String group : ldapUser.getGroups()) {
- groups.add(group);
- }
- user++;
- }
- System.out.println(String.format("%d users, %d groups", user, groups.size()));
- }
-}
1
0
r194 - in trunk: faxtomail-persistence/src/main/java/com/franciaflex/faxtomail faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing
by echatellier@users.forge.codelutin.com 11 Jun '14
by echatellier@users.forge.codelutin.com 11 Jun '14
11 Jun '14
Author: echatellier
Date: 2014-06-11 18:00:34 +0200 (Wed, 11 Jun 2014)
New Revision: 194
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/194
Log:
R?\195?\169cup?\195?\169ration de l'utilsateur connect?\195?\169 via les variables d'env et le ldap
Modified:
trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java
trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java
trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java
trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java
Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java
===================================================================
--- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-11 15:29:45 UTC (rev 193)
+++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-11 16:00:34 UTC (rev 194)
@@ -252,6 +252,10 @@
return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_PASSWORD.getKey());
}
+ public String getLdapTestPrincipal() {
+ return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_TEST_PRINCIPAL.getKey());
+ }
+
public String getInstanceUrl() {
return applicationConfig.getOption(FaxToMailConfigurationOption.INSTANCE_URL.getKey());
}
Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java
===================================================================
--- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-11 15:29:45 UTC (rev 193)
+++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-11 16:00:34 UTC (rev 194)
@@ -103,6 +103,10 @@
"faxtomail.ldap.password",
"Mot de passe pour la connexion au serveur LDAP", null, String.class),
+ LDAP_TEST_PRINCIPAL(
+ "faxtomail.ldap.test.principal",
+ "Principal de test pour forcer un utilsateur particulier", null, String.class),
+
// TRANSIENT CONFIG
VERSION(
"faxtomail.version",
Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
===================================================================
--- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 15:29:45 UTC (rev 193)
+++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 16:00:34 UTC (rev 194)
@@ -335,4 +335,46 @@
return result;
}
+
+ public FaxToMailUser getUserFromPrincipal(String principal) throws AuthenticationException {
+
+ FaxToMailUser result = null;
+
+ try {
+ // first connexion to get full user login
+ LDAPConnection adminConnect = new LDAPConnection();
+ adminConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
+ adminConnect.bind(getApplicationConfig().getLdapUser(), getApplicationConfig().getLdapPassword());
+
+ // search user in ldap
+ String login = null;
+ SearchResultEntry searchEntry = null;
+ if (adminConnect.isConnected()) {
+ String filter = String.format("(userPrincipalName=%s@%s)", principal, "mac-groupe.net");
+ SearchResult searchResult = adminConnect.search("DC=mac-groupe,DC=net", SearchScope.SUB, filter);
+ if (!searchResult.getSearchEntries().isEmpty()) {
+ searchEntry = searchResult.getSearchEntries().get(0);
+ login = searchEntry.getAttributeValue("sn");
+ }
+ adminConnect.close();
+ }
+
+ if (searchEntry != null) {
+ FaxToMailUser user = updateUserFormLdap(searchEntry, login);
+
+ Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
+ result = new FaxToMailUserImpl();
+ faxToMailUserBinder.copyExcluding(user, result);
+ } else {
+ throw new AuthenticationException("Utilisateur inconnu : " + principal);
+ }
+
+ } catch (LDAPException ex) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't login to ldap", ex);
+ }
+ throw new AuthenticationException(ex.getResultCode().getName(), ex);
+ }
+ return result;
+ }
}
Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java
===================================================================
--- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java 2014-06-11 15:29:45 UTC (rev 193)
+++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/FaxToMailUIContext.java 2014-06-11 16:00:34 UTC (rev 194)
@@ -22,7 +22,45 @@
* #L%
*/
+import static org.nuiton.i18n.I18n.t;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+import jaxx.runtime.swing.editor.bean.BeanDoubleList;
+import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
+import jaxx.runtime.swing.session.BeanDoubleListState;
+import jaxx.runtime.swing.session.BeanFilterableComboBoxState;
+import jaxx.runtime.swing.session.State;
+import jaxx.runtime.swing.session.SwingSession;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.beans.AbstractBean;
+import org.nuiton.i18n.I18n;
+import org.nuiton.i18n.init.ClassPathI18nInitializer;
+import org.nuiton.jaxx.application.ApplicationConfiguration;
+import org.nuiton.jaxx.application.swing.ApplicationUIContext;
+import org.nuiton.jaxx.application.swing.action.ApplicationActionEngine;
+import org.nuiton.jaxx.application.swing.action.ApplicationActionFactory;
+import org.nuiton.jaxx.application.swing.action.ApplicationActionUI;
+import org.nuiton.jaxx.application.swing.util.ApplicationErrorHelper;
+import org.nuiton.util.converter.ConverterUtil;
+
import com.franciaflex.faxtomail.FaxToMailConfiguration;
+import com.franciaflex.faxtomail.persistence.RessourceClassLoader;
import com.franciaflex.faxtomail.persistence.entities.Configuration;
import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaApplicationContext;
import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaPersistenceContext;
@@ -30,14 +68,15 @@
import com.franciaflex.faxtomail.persistence.entities.MailFolder;
import com.franciaflex.faxtomail.services.DecoratorService;
import com.franciaflex.faxtomail.services.FaxToMailServiceContext;
-import com.franciaflex.faxtomail.persistence.RessourceClassLoader;
import com.franciaflex.faxtomail.services.service.ConfigurationService;
import com.franciaflex.faxtomail.services.service.EmailService;
import com.franciaflex.faxtomail.services.service.InitFaxToMailService;
+import com.franciaflex.faxtomail.services.service.LdapService;
import com.franciaflex.faxtomail.services.service.MailFolderService;
import com.franciaflex.faxtomail.services.service.ReferentielService;
import com.franciaflex.faxtomail.services.service.UserService;
import com.franciaflex.faxtomail.services.service.ValidationService;
+import com.franciaflex.faxtomail.services.service.ldap.AuthenticationException;
import com.franciaflex.faxtomail.ui.swing.content.MainUI;
import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel;
import com.franciaflex.faxtomail.ui.swing.content.search.SearchUIModel;
@@ -46,46 +85,6 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import jaxx.runtime.swing.editor.bean.BeanDoubleList;
-import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
-import jaxx.runtime.swing.session.BeanDoubleListState;
-import jaxx.runtime.swing.session.BeanFilterableComboBoxState;
-import jaxx.runtime.swing.session.State;
-import jaxx.runtime.swing.session.SwingSession;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.beans.AbstractBean;
-import org.nuiton.i18n.I18n;
-import org.nuiton.i18n.init.ClassPathI18nInitializer;
-import org.nuiton.i18n.init.DefaultI18nInitializer;
-import org.nuiton.i18n.init.UserI18nInitializer;
-import org.nuiton.jaxx.application.ApplicationConfiguration;
-import org.nuiton.jaxx.application.ApplicationIOUtil;
-import org.nuiton.jaxx.application.swing.ApplicationUIContext;
-import org.nuiton.jaxx.application.swing.action.ApplicationActionEngine;
-import org.nuiton.jaxx.application.swing.action.ApplicationActionFactory;
-import org.nuiton.jaxx.application.swing.action.ApplicationActionUI;
-import org.nuiton.jaxx.application.swing.util.ApplicationErrorHelper;
-import org.nuiton.util.converter.ConverterUtil;
-
-import javax.swing.*;
-
-import java.awt.*;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.List;
-
-import static org.nuiton.i18n.I18n.t;
-
/**
* UI application context.
*
@@ -150,13 +149,6 @@
protected final ApplicationErrorHelper errorHelper;
/**
- * Shared data context.
- *
- * @since 1.0.2
- */
-// protected TuttiDataContext dataContext;
-
- /**
* Current screen displayed in ui.
*
* @since 0.1
@@ -197,20 +189,6 @@
private JFrame secondaryFrame;
- /**
- * Flag to know if there is an exsiting db.
- *
- * @since 1.0
- */
- private boolean dbExist;
-
- /**
- * Flag to know if there is a loaded db.
- *
- * @since 1.0
- */
- private boolean dbLoaded;
-
private final ApplicationActionFactory faxToMailActionFactory;
private final ApplicationActionEngine faxToMailActionEngine;
@@ -370,52 +348,19 @@
I18n.init(new ClassPathI18nInitializer(), i18nLocale);
-// //--------------------------------------------------------------------//
-// // init help
-// //--------------------------------------------------------------------//
-//
-// File helpDirectory = config.getHelpDirectory();
-//
-// if (!config.isFullLaunchMode()) {
-//
-// if (!helpDirectory.exists()) {
-// helpDirectory = new File(config.getDataDirectory(), "help");
-// }
-// }
-//
-// if (log.isDebugEnabled()) {
-// log.debug("Help directory: " + helpDirectory);
-// }
-// TuttiIOUtil.forceMkdir(
-// helpDirectory,
-// _("tutti.help.mkDir.error", helpDirectory));
-//
-// // load help mapping
-// String mappingProperties =
-// "/tutti-help-" + i18nLocale.getLanguage() + ".properties";
-// try {
-//
-// InputStream resourceAsStream =
-// getClass().getResourceAsStream(mappingProperties);
-// helpMapping = new Properties();
-// helpMapping.load(resourceAsStream);
-//
-// } catch (Exception eee) {
-// log.error("Failed to load help mapping file at '" +
-// mappingProperties + "'", eee);
-// }
-// if (log.isInfoEnabled()) {
-// log.info(String.format("Starts help with locale at [%s]",
-// helpDirectory));
-// }
-//
+ // try to get user from ldap
+ try {
+ String principal = getLoggedInUsername();
+ FaxToMailUser currentUser = getLdapService().getUserFromPrincipal(principal);
+ if (log.isInfoEnabled()) {
+ log.info("Connected as " + currentUser.getFirstName() + " " + currentUser.getLastName());
+ }
+ setCurrentUser(currentUser);
+ } catch (AuthenticationException ex) {
+ throw new RuntimeException(ex);
+ }
+
-// Company franciaflex = getCompanyService().getCompanyByName("Franciaflex");
-// setCurrentCompany(franciaflex);
-
- FaxToMailUser currentUser = getUserService().getUserByLogin("cbaillet");
- setCurrentUser(currentUser);
-
Configuration config = getConfigurationService().getConfiguration();
setFaxToMailConfiguration(config);
@@ -425,6 +370,14 @@
setActionUI(new ApplicationActionUI(null, this));
}
+ protected String getLoggedInUsername() {
+ String result = getConfig().getLdapTestPrincipal();
+ if (StringUtils.isBlank(result)) {
+ result = System.getProperty("user.name");
+ }
+ return result;
+ }
+
public void open() {
setLocale(config.getI18nLocale());
@@ -497,6 +450,10 @@
public UserService getUserService() {
return serviceContext.newService(UserService.class);
}
+
+ public LdapService getLdapService() {
+ return serviceContext.newService(LdapService.class);
+ }
public EmailService getEmailService() {
return serviceContext.newService(EmailService.class);
Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java
===================================================================
--- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java 2014-06-11 15:29:45 UTC (rev 193)
+++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/RunFaxToMail.java 2014-06-11 16:00:34 UTC (rev 194)
@@ -27,15 +27,6 @@
import com.franciaflex.faxtomail.ui.swing.content.MainUIHandler;
import com.franciaflex.faxtomail.ui.swing.actions.StartAction;
import com.franciaflex.faxtomail.ui.swing.util.FaxToMailExceptionHandler;
-import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil;
-import com.itextpdf.text.*;
-import com.itextpdf.text.Image;
-import com.itextpdf.text.Rectangle;
-import com.itextpdf.text.pdf.ColumnText;
-import com.itextpdf.text.pdf.PdfContentByte;
-import com.itextpdf.text.pdf.PdfReader;
-import com.itextpdf.text.pdf.PdfStamper;
-import com.itextpdf.text.pdf.PdfWriter;
import jaxx.runtime.SwingUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -43,10 +34,7 @@
import javax.swing.*;
import javax.swing.plaf.BorderUIResource;
import java.awt.*;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.URL;
import java.util.Arrays;
/**
@@ -101,29 +89,6 @@
log.info("Full launch mode, try to update.");
}
- // check application url is reachable
-// boolean canUpdateApplication = context.checkUpdateApplicationReachable();
-
-// if (canUpdateApplication) {
-// // try to update jre - i18n - application - help and exit if so
-// UpdateApplicationAction logicAction = TuttiActionHelper.createLogicAction(new MainUIHandler(context),
-// UpdateApplicationAction.class);
-// TuttiActionHelper.runActionAndWait(logicAction);
-//
-// reload = logicAction.isReload();
-// }
-
- // check data url is reachable
-// boolean canUpdateData = context.checkUpdateDataReachable();
-
-// if (canUpdateData) {
-// // try to update report and exit if so
-// UpdateReportAction logicAction = TuttiActionHelper.createLogicAction(new MainUIHandler(context),
-// UpdateReportAction.class);
-// TuttiActionHelper.runActionAndWait(logicAction);
-//
-// reload |= logicAction.isReload();
-// }
}
if (!reload) {
1
0
r193 - in trunk: faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action faxtomail-ui-web/src/main/webapp/WEB-INF/content faxtomail-ui-web/src/main/webapp/WEB-INF/decorators
by echatellier@users.forge.codelutin.com 11 Jun '14
by echatellier@users.forge.codelutin.com 11 Jun '14
11 Jun '14
Author: echatellier
Date: 2014-06-11 17:29:45 +0200 (Wed, 11 Jun 2014)
New Revision: 193
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/193
Log:
Connexion ?\195?\160 l'application web ?\195?\160 partir du ldap
Modified:
trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java
trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp
trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp
Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java
===================================================================
--- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 15:28:27 UTC (rev 192)
+++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/LdapService.java 2014-06-11 15:29:45 UTC (rev 193)
@@ -45,6 +45,7 @@
import com.franciaflex.faxtomail.services.service.ldap.LdapUser;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
+import com.unboundid.ldap.sdk.LDAPSearchException;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchScope;
@@ -105,7 +106,7 @@
List<SearchResultEntry> searchEntries = searchResult.getSearchEntries();
for (SearchResultEntry searchEntry : searchEntries) {
LdapUser user = new LdapUser();
- user.setLogin(searchEntry.getAttributeValue("userPrincipalName"));
+ user.setLogin(searchEntry.getAttributeValue("sn"));
// Parse name
String fullName = searchEntry.getAttributeValue("name");
@@ -248,14 +249,90 @@
* @throws AuthenticationException if authentication fails
*/
public FaxToMailUser authenticateUser(String login, String password) throws AuthenticationException {
+
+ FaxToMailUser result = null;
+
+ try {
+ // first connexion to get full user login
+ LDAPConnection adminConnect = new LDAPConnection();
+ adminConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
+ adminConnect.bind(getApplicationConfig().getLdapUser(), getApplicationConfig().getLdapPassword());
+
+ // search user in ldap
+ String userDN = null;
+ SearchResultEntry searchEntry = null;
+ if (adminConnect.isConnected()) {
+ String filter = String.format("(sn=%s)", login);
+ SearchResult searchResult = adminConnect.search("DC=mac-groupe,DC=net", SearchScope.SUB, filter);
+ if (!searchResult.getSearchEntries().isEmpty()) {
+ searchEntry = searchResult.getSearchEntries().get(0);
+ userDN = searchEntry.getDN();
+ }
+ adminConnect.close();
+ }
+
+ if (searchEntry != null) {
+ // ouvre une connexion avec l'identification de l'utilisateur qui essaye de se connecter
+ // à l'application (ca permet de vérifier l'authentification)
+ LDAPConnection userConnect = new LDAPConnection();
+ userConnect.connect(getApplicationConfig().getLdapHost(), getApplicationConfig().getLdapPort());
+ userConnect.bind(userDN, password);
+
+ if (userConnect.isConnected()) {
+ FaxToMailUser user = updateUserFormLdap(searchEntry, login);
+
+ Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
+ result = new FaxToMailUserImpl();
+ faxToMailUserBinder.copyExcluding(user, result);
+ userConnect.close();
+ } else {
+ throw new AuthenticationException("Not connected");
+ }
+ } else {
+ throw new AuthenticationException("Utilisateur inconnu : " + login);
+ }
+
+ } catch (LDAPException ex) {
+ if (log.isWarnEnabled()) {
+ log.warn("Can't login to ldap", ex);
+ }
+ throw new AuthenticationException(ex.getResultCode().getName(), ex);
+ }
+ return result;
+ }
+
+ protected FaxToMailUser updateUserFormLdap(SearchResultEntry searchEntry, String login) throws LDAPSearchException {
+
+ FaxToMailUser result = null;
+
+ // create or
FaxToMailUserTopiaDao faxtomailUserDao = getPersistenceContext().getFaxToMailUserDao();
- FaxToMailUser user = faxtomailUserDao.forAll().findAnyOrNull();
- FaxToMailUser result = null;
- if (user != null) {
- Binder<FaxToMailUser, FaxToMailUser> faxToMailUserBinder = BinderFactory.newBinder(FaxToMailUser.class);
+ result = faxtomailUserDao.forLoginEquals(login).findUniqueOrNull();
+
+ if (result == null) {
result = new FaxToMailUserImpl();
- faxToMailUserBinder.copyExcluding(user, result);
+ result.setLogin(login);
}
+
+ // update other ldap fields
+ String fullName = searchEntry.getAttributeValue("name");
+ if (fullName.indexOf(' ') != -1) {
+ String lastName = fullName.substring(0, fullName.indexOf(' '));
+ String firstName = fullName.substring(fullName.indexOf(' ') + 1);
+ result.setFirstName(firstName);
+ result.setLastName(lastName);
+ } else {
+ result.setFirstName("");
+ result.setLastName(fullName);
+ }
+
+ if (result.isPersisted()) {
+ result = faxtomailUserDao.update(result);
+ } else {
+ result = faxtomailUserDao.create(result);
+ }
+ getPersistenceContext().commit();
+
return result;
}
}
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java 2014-06-11 15:28:27 UTC (rev 192)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java 2014-06-11 15:29:45 UTC (rev 193)
@@ -30,6 +30,7 @@
import com.franciaflex.faxtomail.services.service.FaxToMailWebApplicationContext;
import com.franciaflex.faxtomail.services.service.InitFaxToMailService;
import com.franciaflex.faxtomail.web.DefaultFaxToMailWebApplicationContext;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.LogManager;
@@ -37,6 +38,8 @@
import java.io.File;
+import javassist.expr.NewArray;
+
public class FaxToMailApplicationContext {
private static Log log = LogFactory.getLog(FaxToMailApplicationContext.class);
@@ -133,6 +136,14 @@
// LocalizedTextUtil.addDefaultResourceBundle("i18n.faxtomail-web");
+ FaxToMailTopiaApplicationContext topiaAppContext = getTopiaApplicationContext();
+ if (topiaAppContext.isSchemaEmpty()) {
+ if (log.isInfoEnabled()) {
+ log.info("Create application schema");
+ }
+ topiaAppContext.createSchema();
+ }
+
FaxToMailTopiaPersistenceContext persistenceContext = newPersistenceContext();
FaxToMailServiceContext serviceContext = newServiceContext(persistenceContext);
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java 2014-06-11 15:28:27 UTC (rev 192)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/FaxToMailSession.java 2014-06-11 15:29:45 UTC (rev 193)
@@ -25,12 +25,10 @@
*/
import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser;
-import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserImpl;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.Collection;
-import java.util.UUID;
public class FaxToMailSession implements Serializable {
@@ -67,26 +65,19 @@
}
public String getAuthenticatedUserId() {
- //return authenticatedUserId;
- return UUID.randomUUID().toString();
+ return authenticatedUserId;
}
public void setAuthenticatedUserId(String authenticatedUserId) {
- //this.authenticatedUserId = authenticatedUserId;
+ this.authenticatedUserId = authenticatedUserId;
}
public FaxToMailUser getAuthenticatedFaxToMailUser() {
- //return authenticatedFaxToMailUser;
- FaxToMailUser result = new FaxToMailUserImpl();
- result.setTopiaId(UUID.randomUUID().toString());
- result.setFirstName("Demo");
- result.setLastName("Demo");
- result.setLogin("demo");
- return result;
+ return authenticatedFaxToMailUser;
}
public void setAuthenticatedFaxToMailUser(FaxToMailUser authenticatedFaxToMailUser) {
- //this.authenticatedFaxToMailUser = authenticatedFaxToMailUser;
+ this.authenticatedFaxToMailUser = authenticatedFaxToMailUser;
}
public void logout() {
Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java
===================================================================
--- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java 2014-06-11 15:28:27 UTC (rev 192)
+++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/LoginAction.java 2014-06-11 15:29:45 UTC (rev 193)
@@ -70,10 +70,10 @@
String result = SUCCESS;
try {
FaxToMailUser user = ldapService.authenticateUser(login, password);
- //getSession().setAuthenticatedUserId(user.getTopiaId());
+ getSession().setAuthenticatedUserId(user.getTopiaId());
} catch (AuthenticationException ex) {
- result = ERROR;
- addActionError("Can't login");
+ result = INPUT;
+ addActionError("Impossible de se connecter (" + ex.getMessage() + ")");
}
return result;
}
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp 2014-06-11 15:28:27 UTC (rev 192)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/login-input.jsp 2014-06-11 15:29:45 UTC (rev 193)
@@ -34,22 +34,19 @@
<h1 class="page-header">Connexion</h1>
<s:form id="main_form" action="login" method="post" role="form" class="form-horizontal">
-
- <div class="alert alert-warning">
- <strong>Attention!</strong> Le formulaire de connexion n'est pas encore branché sur le serveur LDAP.
- Entrez n'importe quelles informations de connexion pour le moment.
- </div>
+ <s:actionerror/>
+
<div class="form-group">
<label for="loginField" class="col-sm-2 control-label">Identifiant LDAP :</label>
<div class="col-sm-10">
- <input type="email" class="form-control" id="loginField" placeholder="nom.prenom(a)franciaflex.fr">
+ <input type="text" name="login" class="form-control" id="loginField" placeholder="nom.prenom(a)franciaflex.fr" required>
</div>
</div>
<div class="form-group">
<label for="passwordField" class="col-sm-2 control-label">Mot de passe :</label>
<div class="col-sm-10">
- <input type="password" class="form-control" id="passwordField" placeholder="password">
+ <input type="password" name="password" class="form-control" id="passwordField" placeholder="password" required>
</div>
</div>
<!-- <div class="form-group">
Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp
===================================================================
--- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2014-06-11 15:28:27 UTC (rev 192)
+++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2014-06-11 15:29:45 UTC (rev 193)
@@ -45,10 +45,7 @@
<div id="wrap-global">
<div id="wrap-main" class="<decorator:getProperty property="page.wide-display"/>">
<div id="faxtomail-body">
- <s:actionerror theme="bootstrap"/>
- <s:actionmessage theme="bootstrap"/>
- <s:fielderror theme="bootstrap"/>
-
+
<!-- navbar -->
<header class="navbar navbar-inverse navbar-static-top" role="banner">
<div class="container">
1
0
r192 - trunk/faxtomail-persistence/src/main/resources
by echatellier@users.forge.codelutin.com 11 Jun '14
by echatellier@users.forge.codelutin.com 11 Jun '14
11 Jun '14
Author: echatellier
Date: 2014-06-11 17:28:27 +0200 (Wed, 11 Jun 2014)
New Revision: 192
Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/192
Log:
Passage d'hibernate en validate
Modified:
trunk/faxtomail-persistence/src/main/resources/faxToMail.properties
Modified: trunk/faxtomail-persistence/src/main/resources/faxToMail.properties
===================================================================
--- trunk/faxtomail-persistence/src/main/resources/faxToMail.properties 2014-06-11 14:35:55 UTC (rev 191)
+++ trunk/faxtomail-persistence/src/main/resources/faxToMail.properties 2014-06-11 15:28:27 UTC (rev 192)
@@ -34,7 +34,7 @@
#hibernate.connection.username=fx
#hibernate.connection.password=FX2013!
-hibernate.hbm2ddl.auto=update
+hibernate.hbm2ddl.auto=validate
#hibernate.show_sql=true
#hibernate.format_sql=true
#hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
@@ -42,4 +42,4 @@
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
-hibernate.c3p0.max_statements=50
\ No newline at end of file
+hibernate.c3p0.max_statements=50
1
0