SIMS 7 - Making use of Windows users for 'Trusted Auto' Logins
SIMS 7 supports two types of users:
- SQL logins which are variants of the user name set in SIMS
- These are variants of the user name in SIMS
- Users are prefixed with the database name.
- Passwords are obfuscations of the passwords provided by the user.
- obfuscations are one way.
- Windows users
- <Domain>\<User Name>
- NB: Only the currently logged in user can be used.
Within the Connect.ini file typically in c:\Program Files (x86)\SIMS\SIMS .Net or redirected to <Drive>:\sims there will either be:
[SIMSConnection]
ServerName=SIMSServer\SIMS22
DatabaseName=SchoolDatabase
or
[SIMSConnection]
REDIRECT=C:\SIMS
But it may have an extra line
[SIMSConnection]
ServerName=SIMSServer\SIMS22
DatabaseName=SchoolDatabase
ConnectionType=TrustedAuto
ConnectionType could also contain 'Trusted' which is a 'halfway' house. Within the Connected SIMS environment, all systems are set to 'TrustedAuto'.
If a TI wants their application to behave like SIMS then that's quite simple to achieve. However some more sample code might be needed.
The main application behaves like normal
static void Main()
{
Application.EnableVisualStyles();
SIMSInterface.SIMSDllResolution.AddSIMSDllResolution();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
The main form needs then to add a few lines after the form is initialised.
public static bool LoggedIn = false;
public Form1()
{
InitializeComponent();
// Assume failure
DoSIMSLogon();
if (LoggedIn)
{
// Happy days we are in
}
else
{
// Show message for login failure
Application.Exit;
}
}
The login needs to do a bit of work to read connect.ini or redirects there of:
public static void DoSIMSLogon()
{
bool useAuto =
SIMSInterface.Connectini.ConnectionType.ToLower() == "trustedauto";
if (useAuto)
{
if(SIMSInterface.LoginHelper.SIMSlogin(SIMSInterface.Connectini.Server,
SIMSInterface.Connectini.Database
,"",""))
{
LoggedIn = true;
}
}
}
Where the connect.ini reading code looks like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace SIMSInterface
{
public class Connectini
{
//Constants
private const string CONNECT = "CONNECT.INI";
private const string SERVER = "ServerName";
private const string DATABASE = "DatabaseName";
private const string REDIRECT = "Redirect";
private const string SECTION = "SIMSConnection";
private const string CONNECTIONTYPE = "ConnectionType";
private static bool _initalised = false;
private static string _Server = "";
private static string _Database = "";
private static string _ConnectionType = "";
private static int _recursionDepth = 0;
private static string _redirect = "";
private static string _errorMessage = "";
/// <summary>
/// Read the values from the ini file and be prepared to recurse!
/// </summary>
private static void Initialise()
{
_initalised = true;
if (_redirect == "")
{
_recursionDepth++;
if (_recursionDepth > 10)
{
return; // Give up
}
_redirect = Path.Combine(SIMSFolderLocations.SIMSDotNetFolder(), CONNECT);
}
string temp = iniFile.Read(_redirect, "SIMSConnection", "REDIRECT");
if (!string.IsNullOrEmpty(temp)) // Potenti
{
_redirect = Path.Combine(temp, CONNECT);
Initialise();
}
else
{
_Server = iniFile.Read(_redirect, SECTION, SERVER);
_Database = iniFile.Read(_redirect, SECTION, DATABASE);
_ConnectionType = iniFile.Read(_redirect, SECTION, CONNECTIONTYPE);
}
}
/// <summary>
/// Returns the last error message
/// </summary>
public static string ErrorMessage { get { return _errorMessage; } }
/// <summary>
/// Returns the SIMS Server Name
/// </summary>
public static string Server
{
get
{
if (!_initalised)
{
Initialise();
}
return _Server;
}
}
/// <summary>
/// Returns the SIMS Database Name
/// </summary>
public static string Database
{
get
{
if (!_initalised)
{
Initialise();
}
return _Database;
}
}
/// <summary>
/// Returns the Connection Type
/// </summary>
public static string ConnectionType
{
get
{
if (!_initalised)
{
Initialise();
}
return _ConnectionType;
}
}
}
}