跳到主要內容

Rainbow Portal 2.0 NTLM 網域整合Hack

Rainbow Portal雖然有小進展,其實搬到以後還是有如龜速。

的2.0下載是假的2.0,其實是用.net 1.1的dll兜起來,做夢也沒想過有這種做法 Orz
要選RainbowPortal2.0.Beta1,也就是標示為Rainbow Portal 2.1.0.1882 Beta 1的版本。

在此要感謝不愧為MCAD.Net的同事Joseph,指出在WebSites\App_Code\Global.asax.cs下手。打開Global.asax.cs會發現原來的LDAP整合code全都remark起來,所以從這裏開始惡搞(Hack)。
一定要聲明,這是惡搞,並不是正確的作法。正確作法應該要實作MemberShipProvider,例如ADMemberShipProvider之類。

在Application_AuthenticateRequest方法裏找到適當的位置,加入:
if (context.User is WindowsPrincipal)
{
Rainbow.Framework.Users.Data.UsersDB accountSystem = new Rainbow.Framework.Users.Data.UsersDB();
string userid = Request.ServerVariables["Logon_User"]; //檢查User是否存在 Rainbow.Framework.Providers.RainbowMembershipProvider.RainbowUser rainbowUser = accountSystem.GetSingleUser(userid);
if (rainbowUser == null)
{
//不存在則加入並登入,底下這個Employee class是我自己寫的,請依照自己的情況寫
Rainbow.Framework.Helpers.Employee employee = new Rainbow.Framework.Helpers.Employee(userid);
// 檢查是否為合法的員工
if (employee.isValid())
{
string password="隨便";
//Rainbow會用email作為username,因此改用自己Hack的AddUser,後面會提到
Guid newUserId = accountSystem.AddUser(userid, employee.getUserName(), email, password); }
}
//幫User登入
PortalSecurity.SignOn(userid, strangePassword, true);
}


Projects\Rainbow.Framework.Core\Security\Security.cs的IsInRole(string role)會出問題,改成 public static bool IsInRole(string role) {
bool useNTLM = HttpContext.Current.User.Identity.AuthenticationType == "NTLM";
if (useNTLM) {
if (role.Trim() == "Admins") {
PortalSettings portalSettings = (PortalSettings)HttpContext.Current.Items[strPortalSettings];
StringBuilder winRoles = new StringBuilder();
winRoles.Append(portalSettings.CustomSettings["WindowsAdmins"]);
winRoles.Append(";");
winRoles.Append(Config.ADAdministratorGroup);
return IsInRoles(winRoles.ToString());
}
if (role == HttpContext.Current.User.Identity.Name) {
return true;
}
return false;
} else {
bool bl = false;
try {
bl = HttpContext.Current.User.IsInRole(role);
}
catch (Exception ) { }
return bl;
}
}

再來是adduser的部份,在Projects\Rainbow.Framework.Core\DAL\UsersDb.cs加上這個method
public Guid AddUser(string userid, string fullName, string email, string password)
{
Guid newUserId = AddUser(userid, string.Empty, string.Empty, string.Empty,
string.Empty, string.Empty, 0, string.Empty, string.Empty, password, email, false);

RainbowUser user = MembershipProvider.GetUser(newUserId, false) as RainbowUser;
user.Name = fullName;
MembershipProvider.UpdateUser(user);
return newUserId;
}

這樣就有個具有.Net 2.0版的NTLM整合Rainbow,可以作為企業內網用。

留言

這個網誌中的熱門文章

DBeaver 介面語言

DBeaver是我個人頗常用的一套跨平台Database管理工具,最近升級後發現Windows版本居然變成簡體中文,而且無法切換為英文。

自然人憑證讀卡機驅動程式

鳥毅用的是第一代的自然人憑證讀卡機,EZ100PU(後來有同事買EZmini可以讀SIM卡似乎更好),每年報稅時用一次。 本來只是要申請些政府業務,一時之間找不到光碟,沒想到在 驅動程式下載 居然看到Linux和Mac的驅動程式,剩下的就是政府單位的網頁和程式應該改版了吧!!!

Personal Bookmark

Java SE 6 + Firefox 2 UI 問題 As I do . Google拋棄了了SOAP API,浮想聯翩 https://www.gandi.net/ VS 2005 SP1中文版推出 Windows Vista中文版下載 ASP.NET 2.0網頁執行管線與快取原理 Cache 2.0快取架構與快取資料自動移除架構圖 flickr sync 分享與試用 SUN Looking Glass 3D圖形介面發布1.0 雅虎勵精圖治推動改革 Wait and see 國內某SOC疑遭駭客入侵 大砲開講 Very Important! 微軟公佈Vista安全程式介面草案 一窺Google開原碼庫房乾坤 qing is writing a dig girl net... wait and see