烦烦烦SharePoint2013 以其他用户登录和修改AD域用户密码
sharepoint默认是没有修改AD密码 和切换 用户的功能,这里我用future的方式来实现。
部署wsp前:

部署后

点击以其他用户身份登录

点击修改用户密码:

这里的扩展才菜单我们用CustomAction来实现,我们需要添加空项目来部署它

以其他用户身份登录得xml如下:

修改用户密码的xml如下:

这里我们需要新建一个应用程序页面,首先需要添加路径映射:

添加应用程序页面的代码如下:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %><%@ Import Namespace=
"Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI"
Assembly="System.Web.Extensions,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="ChangePassword.aspx.cs"
Inherits="SharePointProjectDemo.Layouts.ChangePassword.ChangePassword"
DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content ID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content><asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<asp:Literal ID="ltMsg" EnableViewState="false" runat="server"></asp:Literal><div>
<h3>
<span>修改密码</span>
</h3>
<table width="400px">
<tr>
<td>
域 </td>
<td>
: </td>
<td>
<asp:TextBox ID="txtdomain" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>
旧密码 </td>
<td>
: </td>
<td>
<asp:TextBox ID="txtOld" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
新密码 </td>
<td>
: </td>
<td>
<asp:TextBox ID="txtPass1" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
确认新密码 </td>
<td>
: </td>
<td>
<asp:TextBox ID="txtPass2" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="" align="center">
<br />
<asp:Button ID="btnChangePwd" runat="server" Text="修改密码"
OnClick="btnChangePwd_Click" />
</td>
</tr>
</table>
<br />
<br /></div></asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
修改密码
</asp:Content>
<asp:Content
ID="PageTitleInTitleArea"
ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
修改密码</asp:Content>
using System;using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;
using System.Security.Principal;using System.DirectoryServices.AccountManagement;
namespace SharePointProjectDemo.Layouts.ChangePassword
{ public class Impersonator
{ // Fields private WindowsImpersonationContext ctx = null; // Methods
public void BeginImpersonation()
{ try
{ if (!WindowsIdentity.GetCurrent().IsSystem)
{ this.ctx = WindowsIdentity.Impersonate(WindowsIdentity.GetCurrent().Token);
this.IsImpersonated = true;
}
} catch
{ this.IsImpersonated = false;
}
} public void StopImpersonation()
{ if (this.ctx != null)
{ this.ctx.Undo();
}
} // Properties
public bool IsImpersonated
{ set; get;
}
} public partial class ChangePassword : LayoutsPageBase
{ protected void btnChangePwd_Click(object sender, EventArgs e)
{ string str = this.txtPass1.Text.Trim();
string str2 = this.txtPass2.Text.Trim();
string str3 = this.txtOld.Text.Trim();
string str4 = this.txtdomain.Text.Trim();
if (string.IsNullOrWhiteSpace(str4))
{ this.ltMsg.Text = "域不能为空!";
} else if (string.IsNullOrWhiteSpace(str3))
{ this.ltMsg.Text = "旧密码不能为空!";
} else if (string.IsNullOrWhiteSpace(str))
{ this.ltMsg.Text = "新密码不能为空!";
} else if (str == str2)
{ this.ChangeUserPassword(this.txtPass2.Text.Trim(), str3, str4);
} else
{ this.ltMsg.Text = "两次新密码不一致,请检查!";
}
} private void ChangeUserPassword(string NewPwd, string OldPwd, string domain)
{ try
{
Impersonator impersonator = new Impersonator();
impersonator.BeginImpersonation();
using (PrincipalContext context = this.GetPContext(OldPwd, domain))
{
using (UserPrincipal principal = UserPrincipal.FindByIdentity
(context, IdentityType.SamAccountName, GetLoginName()))
{
principal.ChangePassword(OldPwd, NewPwd);
}
} if (impersonator.IsImpersonated)
{
impersonator.StopImpersonation(); this.ltMsg.Text = "已成功修改密码!";
} else
{ this.ltMsg.Text = "无法修改您的密码,请联系您的系统管理员!";
}
} catch (Exception exception)
{ this.ltMsg.Text = exception.Message;
}
} private string GetDomainContainter(string domain)
{ string str = string.Empty;
string[] strArray = domain.Split(new char[] { '.' },
StringSplitOptions.RemoveEmptyEntries);
foreach (string str2 in strArray)
{
str = str + "DC=" + str2 + ",";
} if (str.Length > )
{
str = str.Substring(, str.Length - );
} return str;
} private string GetLoginName()
{ string username= SPContext.Current.Web.CurrentUser.LoginName.Replace("i:0#.w|", "");
if(username.EndsWith(@"system"))
{
username = username.Replace("system", "sherry");
} return username;
} private string GetLoginNameDomain()
{ string[] strArray = GetLoginName().Split(new char[] { '\' },
StringSplitOptions.RemoveEmptyEntries);
if (strArray.Length == )
{ return strArray[];
} return null;
} private PrincipalContext GetPContext(string OldPwd, string domain)
{ return new PrincipalContext(ContextType.Domain, domain, this.GetDomainContainter(domain),
ContextOptions.Negotiate, this.GetLoginName(), OldPwd);
} protected void Page_Load(object sender, EventArgs e)
{ this.ltMsg.Text = GetLoginName().Replace("i:0#.w|", "");
} }
}
烦烦烦SharePoint2013 以其他用户登录和修改AD域用户密码的更多相关文章
- SharePoint2013 以其他用户登录和修改AD域用户密码 功能
sharepoint默认是没有修改AD密码 和切换 用户的功能,这里我用future的方式来实现. 部署wsp前: 部署后: 点击以其他用户身份登录 点击修改用户密码: 这里的扩展才菜单我们用Cust ...
- java修改AD域用户密码使用SSL连接方式
正常情况下,JAVA修改AD域用户属性,只能修改一些普通属性, 如果要修改AD域用户密码和userAccountControl属性就得使用SSL连接的方式修改, SSL连接的方式需要操作以下步骤: 1 ...
- python-ldap修改AD域用户密码(CA+SSL)
代码连接:https://github.com/raykuan/ldap-notes 使用python的ldap模块连接AD服务器,有两种方式: 非加密:con = ldap.initialize(' ...
- AD 域服务简介(三)- Java 对 AD 域用户的增删改查操作
博客地址:http://www.moonxy.com 关于AD 域服务器搭建及其使用,请参阅:AD 域服务简介(一) - 基于 LDAP 的 AD 域服务器搭建及其使用 Java 获取 AD 域用户, ...
- SharePoint 2010中重置windows 活动目录(AD)域用户密码的WebPart(免费下载)
由于SharePoint 2013推出不久,并非所有的企业都会升级到SharePoint 2013的,毕竟升级不是打打补丁这么简单,更多的企业还是使用Sharepoint 2010版本的,因此本人自行 ...
- SharePoint 2013中修改windows 活动目录(AD)域用户密码的WebPart(免费下载)
前段时间工作很忙,好久没更新博客了,趁国庆休假期间,整理了两个之前积累很实用的企业集成组件,并在真正的大型项目中经受住了考验:.Net版SAP RFC适配器组件和SharePoint 2013修改AD ...
- gitlab用户登录与AD域用户集成
---恢复内容开始--- 编辑gitlab.rb文件 sudo vi /etc/gitlab/gitlab.rb 下图是我编辑的内容示例(仅供参考): 编辑以下内容: gitlab_rails['ld ...
- JAVA 通过LDAP获取AD域用户及组织信息
因为工作需求近期做过一个从客户AD域获取数据实现单点登录的功能,在此整理分享. 前提:用户可能有很多系统的情况下,为了方便账号的统一管理使用AD域验证登录,所以不需要我们的系统登录,就需要获取用户的A ...
- Java利用jcifs集成AD域用户认证
近期一段时间发现AD这东西老火了,尤其是涉及到安全这一方面的,所以AD域用户认证成了如今网络安全方面的产品必备!这里就简单的分享一下,Java通过jcifs集成AD域用户实现认证,以实现网络安全! 我 ...
随机推荐
- ASP.NET加JS方式
一.如果是asp.net中的控件有OnClientClick事件,可以在控件中直接加 OnClientClick--客户端点击事件 二.如果asp.net中的控件没有OnClientClick事件,可 ...
- meta之renderer
今天不小心看了下慕课网首页的源码,看到有一行 1 <meta name="renderer" content="webkit|ie-comp|ie-stand&qu ...
- 【转】HTTP长连接与短连接
1. HTTP协议与TCP/IP协议的关系 HTTP的长连接和短连接本质上是TCP长连接和短连接.HTTP属于应用层协议,在传输层使用TCP协议,在网络层使用IP协议.IP协议主要解决网络路由和寻址问 ...
- BZOJ3098 Hash Killer II
Description 这天天气不错,hzhwcmhf神犇给VFleaKing出了一道题: 给你一个长度为N的字符串S,求有多少个不同的长度为L的子串. 子串的定义是S[l].S[l + 1].... ...
- PHP中soap的使用例子
PHP 使用soap有两种方式. 一.用wsdl文件 服务器端. <?phpclass service{ public function HelloWorld() { return " ...
- Linux常用命令 查看进程信息时 copy的-----温故而知新
1.查进程 ps命令查找与进程相关的PID号: ps a 显示现行终端机下的所有程序,包括其他用户的程序. ps -A 显示所有程序. ps c 列出程序时,显示每个程序真正的 ...
- ASP.NET MVC学习笔记-----ActionInvoker
还是这张图: 当ControllerFactory生成Controller实例后,这时就需要使用ActionInvoker来选择调用一个合适的Action执行.ASP.NET MVC提供的基类Cont ...
- require.async换这个方法的transport问题
这个方法是用于在模块中异步加载其他模块的,类似于在页面上的seajs.use. 比如需要在特定条件下才去加载a模块,不必每次都加载,类似于下面这样的代码 if({{some_condition}}){ ...
- Web SQL数据库
Web SQL数据库:它是一个独立的规范,引入了一组使用SQL操作客户端数据库的API. openDatabase方法:这个方法使用现有的数据库或者新建的数据库创建一个数据库对象.如果数据库存在,op ...
- javaScript模块化规范ADM与CMD
模块化:模块化是指在解决某一个复杂问题时,依照一种分类的思维把问题进行系统性的分解处理,可以想象一个巨大的系统代码,被整合优化分割成逻辑性很强的模块时,对于软件是一种何等意义的存在. 模块化系统所必须 ...