Impersonation Using Recursive Web Services - Part I
Indonesian:
Didalam SharePoint ada beberapa method/property yang “terlarang” untuk digunakan oleh user. Salah satunya adalah, property “Roles” dari SPUser yang berguna untuk melihat role-role yang dimiliki oleh user yang bersangkutan. Otorisasi minimal yang diperlukan untuk mengetahui role-role user adalah “Manage Group”, padahal adakalanya si user hanya perlu tahu role-role yang dimilikinya sendiri. Ada beberapa cara yang dapat digunakan untuk mengatasi keterbatasan ini, salah satunya adalah dengan teknik impersonation (berpura-pura sebagai user lain dan biasanya adalah administrator site).
Pada teknik impersonation, sebuah code disisipkan untuk membuat domain aplikasi baru dengan hak akses yang lebih tinggi seperti Administrator. Namun sayanya, teknik ini akan gagal bekerja jika digunakan didalam web services. Lebih lanjut mengenai bagaimana melakukan impersonation, dapat dicari di internet. Disini, saya akan menjelaskan bagaimana melakukan impersonation dengan memanfaatkan web service itu sendiri “Impersonation using recursive web services”.
English:
There are some methods/properties which requires special authority in Sharepoint development. One of the most importance property is “Roles” of SPUser. Imagine, when a user needs his/her Roles, he/she won’t be able to access that property because of the restriction. The minimal authority to enumerate user roles is “Manage Group” - unfortunatelly giving “Manage Group” to user will also gives him/her an Administrative rights. There are some techniques overcome this limitation, one of the proposed solution is impersonation.
Impersonation is a techniques to create another application domain using elevated privilege such as Administration. Unfortunatelly, this techniques will behaves incorrectly if you create Web Services. I will not talk much about how to impersonate, there are articles in internet. Here, I’ll show you something that you might not realized “impersonation using recursive web services”.
Indonesian (see in English)
Konsep Dasar
Sesuai dengan namanya, teknik ini memanfaatkan eksekusi web service oleh web service itu sendiri dengan menaikkan hak akses / credential pemanggil. Jadi alih-alih menyisipkan code untuk impersonation, method di web service yang sama akan dipanggil sebanyak dua kali. Untuk lebih jelasnya saya akan langsung memberikan contoh kasusnya.
Kasus:
Sebuah fungsi harus mengecek role-role apa yang dimiliki oleh seorang user. Alih-alih menggunakan properti Roles dari SPUser, aplikasi ini memanggil method “GetRoleCollectionFromUser” dari web service yang disediakan oleh Sharepoint, yaitu UserGroup.asmx (*/_vti_bin/UserGroup.asmx).
Kasus diatas diambil untuk mempersingkat pembuatan solusi dan untuk memberikan gambaran langsung bagaimana teknik recursive web service ini bekerja.
Dalam kasus ini, anggap saja bahwa kita web service UserGroup ini adalah web service buatan kita sendiri yang sudah diintegrasikan kedalam SharePoint. Web service UserGroup tersebut memiliki kelemahan keterbatasan hak akses (hanya bisa dieksekusi oleh Administrator). Tugas kita adalah memperbaikinya dengan teknik recursive web service.
Langkah-Langkah
Karena prosesnya cukup panjang, maka berikut ini langkah-langkah yang akan dilakukan
Mempersiapkan Project baru bertipe Web Service
Menambahkan kode untuk memanggil web service itu sendiri (recursive, kita ambil contoh UserGroup)
Mengintegrasikan web service kedalam Sharepoint
1. Mempersiapkan Project baru bertipe Web Service
Pertama-tama harus diingat bahwa project web service yang akan dibuat, pada akhirnya akan diintegrasikan kedalam Sharepoint. Web service yang diintegrasikan kedalam Sharepoint mengimplementasikan teknik virtualisasi. Teknik virtualisasi adalah teknik yang memungkinkan sebuah web service bekerja secara independen di beberapa situs berdasarkan alamatnya. Misal, dalam kasus ini kita mengamati web service UserGroup.asmx yang terletak di */_vti_bin/UserGroup.asmx. Tanda * didepan mewakili sebuah alamat dasar suatu situs. Jika kita memiliki dua buah situs masing-masing beralamat di http://situs1 dan http://situs2, maka web service tersebut dapat diakses di http://situs1/__vti_bin/UserGroups.asmx_ dan http://situs2/__vti_bin/UserGroups.asmx_.
Kita akan meletakkan web service ini di dalam folder yang sama dengan web service standar dari Sharepoint, yaitu di
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI
Web service tersebut akan diberi nama ProxyWS. Untuk memperlancar proses pembuatan project web service (alasan teknis untuk hal ini mungkin akan saya bahas di tulisan yang lain) dengan menggunakan Visual Studio maka, kita harus membuat virtual directory baru di IIS dengan nama ProxyWS dan diletakkan di
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI\ProxyWS
**jangan lupa untuk merubah “Execute permissions” menjadi script only.
Setelah virtual directory selesai dibuat, maka selanjutnya kita harus membuat perkecualian agar virtual directory yang baru dibuat tadi tidak diproses oleh Sharepoint. Virtual directory yang dikecualikan dari proses Sharepoint disebut sebagai “Excluded Path”. Untuk membuat “Excluded Path”, kita harus masuk kedalam web site administrasi Sharepoint, kemudian memilih web site yang ditempati oleh virtual directory yang baru saja dibuat.
Akhirnya kita dapat membuka Visual Studio untuk membuat project web service. Project web service tersebut diletakkan di URL virtual directory yang telah dipersiapkan diatas.
Tambahkan referensi “Windows Sharepoint Services” agar web service tersebut dapat mengakses objek-objek yang ada didalam Sharepoint. Sampai disini kita sudah memiliki project web service yang siap untuk diberi logic.
(bersambung ke bagian 2)
--o0o–
English (baca dalam Bahasa Indonesia)
Basic Principle
The name inspired by my technique to increase user rights by self-calling service method recursively using other credentials with higher authority. Hense, instead of putting impersonation code - this techniques execute the same service with Administrator credentials. I’ll take a real sample to elaborate what it is.
Case:
We need a function to check user roles. Instead of using Roles property of SPUSer, this application executes “GetRoleCollectionFromUser” from standard web service by Sharepoint. The web service is UserGroup.asmx and located in */_vti_bin/UserGroup.asmx.
I specially choose that case to make it easier to follow and to give you basic undertanding about how does it work.
Imagine that in this case, UserGroup web service is our custom web service that is integrated into Sharepoint. The service is executing “restricted” property in Sharepoint object model, the Roles of SPUser. Therefore the service has unexpected behaviour - executable by only Administrator. Our job is to fix the service using recursive web service technique.
Brief Steps
We are going for a long process, and here are brief steps for the solution
Prepare new web services project
Adding code to recursively calling web method (our example using UserGroup services)
Integrating web service into Sharepoint
1. Prepare new web services project
At first we must consider that the web service will be integrated into Sharepoint. Sharepoint implement virtualization in all of its web services. The virtualization is a technique to enable the web service work independently between sites according to the URL. For example, now we are going to utilize UserGroup.asmx web service in */_vti_bin/UserGroup.asmx. The asterisk (*) represents website root. Let say there is site and subsite each in http://situs1 and http://situs2. Using virtualization, then the web service for each site is in http://situs1/__vti_bin/UserGroups.asmx_ and http://situs2/__vti_bin/UserGroups.asmx_ consecutively.
We will put the new service in the same folder with standard Sharepoint’s web services, in
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI
The new web service will be called ProxyWS. To help web service project creation using Visual Studio then we must create new virtual directory in IIS using service name (I’ll show you technical background this in the upcoming posting), in this case is ProxyWS. So we will create a new virtual directory in
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI\ProxyWS
** don’t forget to change “Execute permissions=none” to “Execute permission= scipt only”.
After we’ve done with virtual directory, the next step is to change the configuration to prevent the virtual directory from Sharepoint’s processing. The virtual directory which has been prevented from Sharepoint’s processing is known as “Excluded Path “. Specifying “Excluded Path” is as easy as changing configuration in administration site of Sharepoint. Choose relevant web site and specify the new virtual directory as “Excluded Path”.
And now, we can open Visual Studio to create web services project. And you can guess that the URL for the web service is the new created virtual directory from the above step.
Add “Windows Sharepoint Services” reference to the project so it can access Sharepoint’s object. At this point, the web service project is ready for additional logic.
(to be continued to part 2)