国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET2.0應用中定制安全憑證之實踐篇

2024-07-10 13:04:21
字體:
來源:轉載
供稿:網友
,歡迎訪問網頁設計愛好者web開發。    一、方案架構

  本方案架構很簡單——它用一個web服務來包裝asp.net 2.0提供者并且為遠程客戶暴露該憑證管理,你甚至還能在該架構中加上一些失去的功能。然后,在提供一個豐富的用戶接口和全面憑證管理經驗的同時,使用一個windows表單應用程序來消費該web服務。該web服務配置文件將包含特定于該憑證存儲的指令。然而,這的確意味著所有由該web服務管理的應用程序都將可以共享這些指令。

  盡管你能夠從頭到尾地構建該web服務,也就是說,首先用靜態方法roles和membership來包裝它們并定義該web服務,我卻更喜歡一種契約驅動的方法:首先設計執行各種操作的最好接口將是什么,并且直到需要時才考慮怎樣實現它們。這樣做可以確保由web服務暴露的接口支持所有要求的管理功能并且還將減少該客戶應用程序與任何實現細節(例如包裝提供者)之間的耦合。

  asp.net 2.0的一個更好的特點是它支持web服務接口,你可以定義并且讓該web服務暴露邏輯接口,就象類的表現一樣。為此,你需要用webservicebinding屬性修飾你的接口并且經由webmethod屬性來暴露單個的接口方法。然后,你將有一個派生于這個接口的類并實現該接口,而且編譯器將要求你支持該接口的所有方法。

  為了管理和交互于憑證存儲和web服務配置,我定義了5個接口-iapplicationmanager,imembershipmanager,ipasswordmanager,irolemanager和iusermanager。

  (一) iapplicationmanager

  該iapplicationmanager接口顯示于所附源碼中的列表2,允許管理員刪除一指定的應用程序-也就是說,從數據庫中刪除所有到它的參考并且刪除它的所有用戶和角色。iapplicationmanager允許從存儲中刪除所有的應用程序,并且它能返回在該存儲中的所有應用程序的一個列表。注意,這個接口作為一個內部的接口被定義-public或internal可見性修飾詞對web服務接口都是無意義的。該接口上的每個方法用webmethod屬性加以修飾并有一個該方法的簡短描述。此外,存取憑證存儲的所有方法都被設置為使用事務處理。這樣以來,兩種操作-如刪除一應用程序和創建一用戶將在彼此完全隔離的情況下執行,從而保證了如刪除所有用戶等復雜操作的原子性。.net 2.0中的web服務只能啟動一個新事務,而且它是由webmethod屬性的transactionoption屬性來控制的。最后一點是把webservicebinding屬性應用于接口上。這就指定該接口是一個客戶和服務都能綁定到的web服務接口。為了把該接口以一個wsdl契約方式暴露給外界,你需要使用一個shim類。這個shim類的設計是必要的,因為你不能把一個接口作為一web服務暴露,而且你也不能在其上應用webservice屬性。這個shim類還將經由webservice屬性為該接口命名空間定義。下面的代碼顯示了iapplicationmanagershim抽象類的定義。

[webservice(name="iapplicationmanager",
namespace="http://credentialsservices",
description="iapplicationmanager is used to manage
applications. this web service is only
the definition of the interface. you
cannot invoke method calls on it.")]
abstract class iapplicationmanagershim : iapplicationmanager{
 public abstract void deleteapplication(string application);
 public abstract string[] getapplications();
 public abstract void deleteallapplications();
}


  因為iapplicationmanagershim是一個類,所以你可以把它暴露為一個web服務。因為它是一抽象類且所有方法被定義為抽象方法,所以不需要(也不能)實現任何方法。為了使其看起來就象該接口,iapplicationmanagershim把webservice屬性的屬性名設置為iapplicationmanager(代替缺省的類名)。現在,你可以使用iapplicationmanager.asmx文件來暴露該接口。

<%@ webservice language="c#"
codebehind="~/app_code/iapplicationmanagershim.cs"
class="iapplicationmanagershim"%>


  現在,如果你瀏覽到iapplicationmanager.asmx頁面,你就會看到該接口定義。你可以使用wsdl.exe的serverinterface選項來把接口定義輸入到客戶端或任何其它想綁定到該接口定義上的服務。

  (二) imembershipmanager

  imembershipmanager接口(見所附源碼中的列表3)允許你管理用戶帳戶的所有方面-創建和刪除用戶帳戶,更新用戶帳戶,檢索用戶帳戶細節以及檢索在一應用程序中的所有用戶。

  (三) irolemanager

  irolemanager接口允許你管理邏輯角色的所有方面-創建和刪除角色,從角色中增加和刪除用戶以及檢索在一應用程序中的所有角色。

[webservicebinding("irolemanager")]
interface irolemanager{
[webmethod(...)]
void createrole(string application,string role);
[webmethod(...)]
bool deleterole(string application,string role,bool throwonpopulatedrole);
[webmethod(...)]
void addusertorole(string application,string username, string role);
[webmethod(...)]
void deleteallroles(string application,bool throwonpopulatedrole);
[webmethod(...)]
string[] getallroles(string application);
[webmethod(...)]
string[] getrolesforuser(string application,string username);
[webmethod(...)]
string[] getusersinrole(string application, string role);
[webmethod(...)]
void removeuserfromrole(string application,string username, string rolename);
//更多成員
}

  (四) ipasswordmanager

  這個ipasswordmanager接口主要提供與應用程序口令策略相關的只讀信息。

[webservicebinding("ipasswordmanager")]
interface ipasswordmanager{
[webmethod(...)]
bool enablepasswordreset(string application);
[webmethod(...)]
bool enablepasswordretrieval(string application);
[webmethod(...)]
string generatepassword(string application,int length,
int numberofnonalphanumericcharacters);
[webmethod(...)]
bool requiresquestionandanswer(string application);
[webmethod(...)]
string resetpassword(string application,string username);
[webmethod(...)]
string getpassword(string application,string username,string passwordanswer);
[webmethod(...)]
void changepassword(string application,string username,string newpassword);
//更多成員
}


  典型地,該策略存儲在應用程序的配置文件中。該策略包括是否啟動口令重置和檢索,口令強度和口令回答策略等。你也可以使用ipasswordmanager來生成一相應于該口令強度策略的新口令。另外,ipasswordmanager可用于重置、改變或檢索一指定用戶的口令。

  (五) iusermanager

  iusermanager接口允許校驗用戶憑證,檢索角色身份以及獲取指定用戶是其成員之一的所有角色。該接口用于測試和分析目的。

[webservicebinding("iusermanager")]
public interface iusermanager{
[webmethod(...)]
bool authenticate(string applicationname,string username, string password);
[webmethod(...)]
bool isinrole(string applicationname,string username, string role);
[webmethod(...)]
string[] getroles(string applicationname,string username);
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东阳市| 浮梁县| 东源县| 柳林县| 建始县| 台北市| 清河县| 韶关市| 兰西县| 耿马| 华宁县| 大渡口区| 徐闻县| 东乡| 喀喇沁旗| 习水县| 蓝山县| 治多县| 长寿区| 垦利县| 漯河市| 东辽县| 无极县| 阳山县| 库尔勒市| 桃江县| 平泉县| 什邡市| 贵定县| 东台市| 韶关市| 张家界市| 富宁县| 噶尔县| 嘉黎县| 广东省| 买车| 甘洛县| 佛山市| 城市| 镇平县|