zoukankan      html  css  js  c++  java
  • Web Parts, Impersonate and Security Policy, Part 2

    Web Parts, Impersonate and Security Policy

    Part 2

     

    Written by: Rickie Lee (rickieleemail at yahoo.com)

    继续前面的postingWeb Parts, Impersonate and Security Policy, Part 1》,阐明如何解决SharePoint Web Parts开发过程中访问权限的问题。Part 1中以C#的示例代码演示了impersonate(角色扮演)的应用。

    这里简单贴出VB.Net代码,方便使用VB.NetCASE

    Protected Shared Function CreateIdentity(ByVal User As String, _

    ByVal Domain As String, ByVal Password As String) As WindowsIdentity

     

        Dim objToken As New IntPtr(0)

        Dim ID As WindowsIdentity

        Const LOGON32_PROVIDER_DEFAULT As Integer = 0

        Const LOGON32_LOGON_NETWORK As Integer = 3

     

        'Initialize token object

        objToken = IntPtr.Zero

     

        ' Attempt to log on

        Dim blnReturn As Boolean = LogonUser(User, Domain, Password, _

        LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, objToken)

     

        'Check for failure

        If blnReturn = False Then

            Dim intCode As Integer = Marshal.GetLastWin32Error()

            Throw New Exception("Logon failed: " & intCode.ToString)

        End If

     

        'Return new token

        ID = New WindowsIdentity(objToken)

        CloseHandle(objToken)

        Return ID

     

    End Function

     

    <DllImport("advapi32.dll", SetLastError:=True)> _

        Private Shared Function LogonUser(ByVal lpszUsername As String, _

    ByVal lpszDomain As String, _

    ByVal lpszPassword As String, ByVal dwLogonType As Integer, _

    ByVal dwLogonProvider As Integer, _

            ByRef phToken As IntPtr) As Boolean

    End Function

     

    <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _

        Private Shared Function CloseHandle(ByVal handle As IntPtr) As Boolean

    End Function

     

    ***

    未完,Part 3待续.

     

    Reference:

    1. Rickie Lee, Web Parts, Impersonate and Security Policy, Part 1, you can reach Rickie Lee at rickieleemail (at) yahoo.com.

     

  • 相关阅读:
    Elasticsearch7.8快照备份到阿里云存储(OSS)
    office启动时不要显示首页
    Tinker Flutter热修复
    wordpress获取最新文章列表
    Nginx下完美解决WordPress的伪静态
    freenom申请域名
    新版DigitalOcean注册及使用中文教程
    CentOs安装宝塔
    利用 Github Actions 自动更新 docfx 文档
    行为型设计模式总结
  • 原文地址:https://www.cnblogs.com/rickie/p/97895.html
Copyright © 2011-2022 走看看