

namespace ScrewTurn.Wiki
{
public static class WindowsLogin
{
public static string getWindowsUser()
{
//private string m_userName;
//private string m_email;
//private bool m_isAuthenticated;
string userName = HttpContext.Current.User.Identity.Name;
//Session["LoginKey"] = Tools.ComputeSecuredUsernameHash(userName);
//Session["Username"] = userName;
//Session["Admin"] = false;
//Log.LogEntry("Windows User " + (string)Session["Username"] + " logged in", EntryType.General, "SYSTEM");
return userName;
}
}
}
void Session_Start(object sender, EventArgs e) {
// Code that runs when a new session is started
ScrewTurn.Wiki.Users.OnlineUsers++;
string userName = ScrewTurn.Wiki.WindowsLogin.getWindowsUser();
string email = ScrewTurn.Wiki.WindowsLogin.getWindowsEmail(userName); //need to get from AD not coded yet
Session["LoginKey"] = ScrewTurn.Wiki.Tools.ComputeSecuredUsernameHash(userName);
Session["Username"] = userName;
Session["Email"] = email;
Session["Admin"] = false;
ScrewTurn.Wiki.Log.LogEntry("Windows User " + (string)Session["Username"] + " logged in", ScrewTurn.Wiki.EntryType.General, "SYSTEM");
}
//* [RandPage.aspx|Random Page]
//* [Login.aspx|Login/Logout]
//* [Language.aspx|Language Selection]
//* [Profile.aspx|Your Profile]
//* [Register.aspx|Create Account]

void Session_Start(object sender, EventArgs e) {
// Code that runs when a new session is started
ScrewTurn.Wiki.Users.OnlineUsers++;
ScrewTurn.Wiki.SessionFacade.Breadcrumbs = new ScrewTurn.Wiki.BreadcrumbsManager();
// new code from here down:
if (ConfigurationManager.AppSettings["LDAP"] == "true")
{
ScrewTurn.Wiki.LDAP_Login ldap = new ScrewTurn.Wiki.LDAP_Login();
ScrewTurn.Wiki.SessionFacade.LoginKey = ScrewTurn.Wiki.Tools.ComputeSecuredUsernameHash(ldap.Name);
ScrewTurn.Wiki.SessionFacade.Username = ldap.Name;
ScrewTurn.Wiki.SessionFacade.Admin = ldap.Admin;
ScrewTurn.Wiki.PluginFramework.UserInfo result =
new ScrewTurn.Wiki.LocalUserInfo(ldap.Name, ldap.Email, true, DateTime.Now, ldap.Admin, new ScrewTurn.Wiki.UsersStorageProvider(), "");
ScrewTurn.Wiki.Users.Instance = new ScrewTurn.Wiki.Users();
ScrewTurn.Wiki.Users u = ScrewTurn.Wiki.Users.Instance;
u.AllUsers.Add(result);
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.DirectoryServices;
namespace ScrewTurn.Wiki
{
/// <summary>
/// Summary description for LDAP_Login
/// </summary>
public class LDAP_Login
{
private string strEmail = "";
private string strName = "";
private bool blnAdmin = false;
public string Email
{
get
{
return strEmail;
}
set
{
strEmail = value;
}
}
public string Name
{
get
{
return strName;
}
set
{
strName = value;
}
}
public bool Admin
{
get
{
return blnAdmin;
}
set
{
blnAdmin = value;
}
}
public LDAP_Login()
{
try
{
// get user name (excluding domain)
string signon = HttpContext.Current.User.Identity.Name;
string[] signon_array = signon.Split('\\');
DirectorySearcher mySearcher = new DirectorySearcher("LDAP://...your ldap string here..");
mySearcher.Filter = "(&(objectClass=user)(objectCategory=person)(samAccountName=" + signon_array[1] + "))";
// add the mail property to the list of props to retrieve
// you can add any others you might be interested in, too!
mySearcher.PropertiesToLoad.Add("mail");
mySearcher.PropertiesToLoad.Add("name");
SearchResult mySearchResult = mySearcher.FindOne();
// get email address and full name
if (mySearchResult != null)
{
ResultPropertyCollection myResultPropColl = mySearchResult.Properties;
foreach (string myKey in myResultPropColl.PropertyNames)
{
foreach (Object myCollection in myResultPropColl[myKey])
{
switch (myKey)
{
case "mail":
Email = myCollection.ToString();
break;
case "name":
Name = myCollection.ToString();
break;
}
}
}
}
// determine if user is admin
string[] strAdminGroups = ConfigurationManager.AppSettings["Admin_Groups"].Split(',');
foreach (string group in strAdminGroups)
{
if (HttpContext.Current.User.IsInRole(group))
{
Admin = true;
}
}
}
catch (Exception ex)
{
Admin = false;
Email = "";
Name = "";
ScrewTurn.Wiki.Log.LogEntry("LDAP_Login Error: " + ex.Message, ScrewTurn.Wiki.EntryType.General, "SYSTEM");
}
}
}
}
<add key="LDAP" value="true"/>
<add key="Admin_Groups" value="admingroup1,admingroup2,etc"/>
void Session_Start(object sender, EventArgs e) {
// Code that runs when a new session is started
ScrewTurn.Wiki.Users.OnlineUsers++;
ScrewTurn.Wiki.SessionFacade.Breadcrumbs = new ScrewTurn.Wiki.BreadcrumbsManager();
// Get identity name from web server.
string identityName = System.Web.HttpContext.Current.User.Identity.Name;
if (identityName == null || identityName.Length < 1)
throw new System.ApplicationException("Could not get current Windows user name. Ensure Integrated Windows Authentication is enabled.");
string username;
// Strip domain prefix (e.g. "\\COMPANY.NET\DoeJ").
int domainDelimOffset = identityName.IndexOf("\\");
if (domainDelimOffset > 0)
username = identityName.Substring(domainDelimOffset + 1);
else
username = identityName;
if (username.Length < 1)
throw new System.ApplicationException("Username " + identityName + " is empty after domain stripped.");
// Locate user.
ScrewTurn.Wiki.PluginFramework.UserInfo user = ScrewTurn.Wiki.Users.Instance.Find(username);
if (user == null)
{
// User not found, add a new one.
if (!ScrewTurn.Wiki.Users.Instance.AddUser(username, string.Empty, string.Empty, true, false, null))
throw new System.ApplicationException("Could not add user \"" + username + "\".");
// Get freshly-added user.
user = ScrewTurn.Wiki.Users.Instance.Find(username);
if (user == null)
throw new System.ApplicationException("Could not find user \"" + username + "\".");
}
// Set up session.
ScrewTurn.Wiki.SessionFacade.LoginKey = ScrewTurn.Wiki.Tools.ComputeSecuredUsernameHash(user.Username);
ScrewTurn.Wiki.SessionFacade.Username = user.Username;
ScrewTurn.Wiki.SessionFacade.Admin = user.Admin;
// Log event.
ScrewTurn.Wiki.Log.LogEntry("User " + ScrewTurn.Wiki.SessionFacade.Username + " logged in through Windows Integrated Authentication", ScrewTurn.Wiki.EntryType.General, "SYSTEM");
}Richard wrote:// Get identity name from web server.
string identityName = System.Web.HttpContext.Current.User.Identity.Name;
kscott wrote:try turning off Anonymous users access in IIS under Directory Security.
(you'll have to use Basic or Integrated access)
You need anonymous users disabled and Windows Integrated Authentication enabled in IIS. If you are not using a domain, you may need to create accounts for each user on the web server.mmestemaker wrote:kscott wrote:try turning off Anonymous users access in IIS under Directory Security.
(you'll have to use Basic or Integrated access)
That works. Sorta. The browser is prompting me for login and password before letting get to the wiki. At that point, the code is picking up my ID and I could implement the rest of the code, but it's not really the pass-thru effect I was hoping for. Anyone know if this is the nature of using a workgroup network instead of a domain server? That's my current guess.
eric.stephani wrote:In another thread it looks like samward created a custom plugin.
http://www.screwturn.eu/forum/viewtopic.php?t=508
Samward, could you post your code so the community could evaluate it and maybe we could come up with a recommeded method?
I would like to avoid making any manual changes to avoid any problems when upgrading from version to version.
Return to Suggestions and Feature Requests
Users browsing this forum: Google [Bot] and 0 guests