Hi there,
I finally managed to find some time to finalize the razor script to get the LDAP authentication working with Seal Report :
It works as a two step authentication:
1. The windows credentials authentication to the LDAP server (works with username, or username@domain, not case sensitive);
2. Get the group to which the user belongs from an excel sheet (couldn't find if a user could be member of many groups).
The excel sheet is called sealreport_groups.xls, and is stored in c:\SealReport folder. It contains two columns (on the first line) : Username and Group.
Possible Improvements:
- Handle many groups for one user;
- Add LDAPS connection;
- Store the groups in the Active Directory instead of the Excel sheet;
- ...
Enjoy !
Thomas
@using Seal.Model;
@using System.Net;
@using System.Data
@using System.Data.OleDb
@using Seal.Helpers
@using System.DirectoryServices;
@{
SecurityUser user = Model;
user.Name = user.WebUserName; //Display name for the log file
bool blConnected = false;
// first validate the access of the user in the LDAP
try
{
// Get the connection
DirectoryEntry Ldap = new DirectoryEntry("LDAP://yourserver", user.WebUserName, user.WebPassword);
object nativeObject = Ldap.NativeObject;
blConnected = true;
}
catch(DirectoryServicesCOMException Ex)
{
//Console.WriteLine(Ex.Message);
user.Error = Ex.Message;
}
if (blConnected == true) {
// If the connection is successfull, get the user group in the excel sheet
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\SealReport\\sealreport_groups.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand(string.Format("select Group from [Sheet1$] where Username={0}", Helper.QuoteSingle(user.WebUserName)), connection);
object group = command.ExecuteScalar();
if (group != null && group != DBNull.Value)
{
user.AddSecurityGroup((string)group);
}
else
{
user.Error = "No reporting group assigned to this user";
}
}
else {
user.Error = "Please check your user / password";
}
}
Edited by user Wednesday, January 9, 2019 5:13:28 PM(UTC)
| Reason: Not specified