我正在开发一个像这样运行的场景:用户单击SAP站点中的一个链接,将他/她带到SharePoint站点。要完成单点登录,http模块将获取SAP cookie,获取用户名并将用户登录到SharePoint。
在SP 2007上实现时,它曾经工作:只需调用SetAuthCookie(用户名)完成工作,用户访问SharePoint 2007网站,一切都按预期工作。
在SharePoint 2010声明的Web应用程序上,它停止工作。根据{{3}},这是非常期待的。所以我继续开始替换SetAuthCookie()代码,但我面临两个问题
这是我的自定义登录代码。有没有相当于SetAuthCookie()不需要密码? (没关系硬编码的url和pwd的......只是一个原型)
private SPIisSettings IisSettings
{
get
{
SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://virtualcasa1/sites/blank2"));//XXX
SPIisSettings settings = webApp.IisSettings[SPUrlZone.Default];
return settings;
}
}
private SecurityToken GetSecurityToken()
{
SecurityToken token = null;
SPIisSettings iisSettings = IisSettings;
Uri appliesTo = new Uri("http://virtualcasa1");//XXX
SPFormsAuthenticationProvider authProvider = iisSettings.FormsClaimsAuthenticationProvider;
token = SPSecurityContext.SecurityTokenForFormsAuthentication(appliesTo, authProvider.MembershipProvider, authProvider.RoleProvider, "userfba", "pa55word");//XXX
return token;
}
private void SignIn()
{
SecurityToken token = null;
if ((token = GetSecurityToken()) != null)
{
SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
HttpContext c = HttpContext.Current;
fam.SetPrincipalAndWriteSessionToken(token);
c.Response.Redirect("/sites/blank2");//XXX
}
}
void OnAuthenticateRequest(object sender, EventArgs e)
{
HttpContext c = HttpContext.Current;
if (c.Request.Url.ToString().ToLowerInvariant().Contains("/authenticate.aspx"))
{
SignIn();
}
非常感谢!