Friday, August 19, 2016

SharePoint custom C# code - impersonate the app pool account

note to self - in SharePoint when you need to impersonate the application pool account, you can use WindowsIdentity.Impersonate(IntPtr.Zero) like this:

Friday, April 10, 2015

Node.js web app experiments

Needed a break from all the .NET and Coldfusion goo I've been dealing with at work. Started working on a mobile-first workout tracking app using only free tools/services. The app itself is turning out like this:
  • AngularJS for the client UI/UX. To be deployed to Azure webapp hosting or maybe at some point turned into a phone app using something like Cordova
  • ExpressJS for the Data Access Layer. The whole thing is just a collection of JSON web services so its super easy to consume from javascript. This just gets deployed to Azure as another stand alone website that the client app makes calls to.
  • PouchDB for the backend database. And also for the sweet client API which I'm using in the DAL project. Since PouchDB is 100% compatible with CouchDB I can just point the client to something like Couchbase when I'm ready to go "live" and get free DB hosting
So much great stuff in every layer, I love the whole AngularJS MVC framework for client apps. Loved learning how to use Promises with the PouchDB client, the tutorials on their site are fantastic. Still getting used to CouchDB though, it needs a better query language...map/reduce is killing me xD

Friday, December 26, 2014

Coldfusion 11 Java Keytool Import Cert Command

Doing an upgrade of coldfusion from CFMX 6.1 to CF11 and completely forgot how to import/trust external SSL certs (for consuming web services).

  1. hit the web service WSDL url, confirm it works over HTTPS, and download the base64 version of the cert from your browser
  2. copy the cert to the coldfusion server (the default path for java cacert keyfile is here: C:\ColdFusion11\jre\lib\security)
  3. open a command prompt (run as administrator) and execute the command
  4. Restart coldfusion

note that when you try to add an HTTPS web service with an untrusted SSL cert from the CF Admin you get a generic "Cant read WSDL" error. Not super helpful, but every time I get that message it ends up being either this SSL cert trust issue or that my web service requires windows authentication (CF 11 does not support kerberos or windows auth for consuming web services).

Thursday, October 23, 2014

SQL Server - Recursive CTE query to get manager hierarchy

I've used the CONNECT BY syntax to do hierarchy queries in oracle, but recursive queries seem to be the new standard (not so new I guess, but new for me!). Now that I'm using SQL server it seems to be the only way to go. So here's my reference for walking a single table parent/child hierarchy:

Friday, October 17, 2014

Copying AD Users into a SharePoint 2010 SPGroup

NOTE - if you are using Active Directory and you have user profiles being synced from AD to SharePoint, you should be able to apply security directly to an AD group and have it work recursively (with limitations - http://technet.microsoft.com/en-us/library/cc261972.aspx). With a custom claims provider in one of the applications I'm working on I can't get the provider to recursively read group membership, I'm told it's a limitation of the provider. With all that said, the notes here discuss a workaround for my claims provider issue.

I've run into a problem with SharePoint 2010 configured for Claims auth where the claims provider wont recursively read group membership. So if you have a claims group configured with a child group that contains users, like this:

  • my_master_group
    • User1
    • my_child_group
      • User2

And then try to assign my_master_group rights to a SharePoint site, only User1 picks up those rights. User2 is ignored. So only top level group members are ever granted rights. In my case, my source claims repository has complex nested group structure that is synced up with our orgs Active Directory. I have one master group that recursively holds all my group members and now I just want to get them into a SPGroup that I can then use for granting rights to my site. Here is my first stab at a rough solution for this, until the provider issue is resolved.

Create a scheduled task to copy AD members into a SPGroup

The plan is to first query AD, get a recursive list of my_master_group members and add them to the SharePoint group sp_my_master_group.

Get a list of AD Principal Objects

Insert Principals into a SharePoint Group

Friday, May 23, 2014

Exporting Data from SQL Server Managment Studio as INSERT statements

Another quirk of Microsoft SQL Server Management Studio 2008 - they made the option to export table data as SQL insert statements almost impossible to find. Here's how you do it:
  • Right click on the database and go to Tasks -> Generate Scripts
  • Select the tables that you want to generate the script for
  • Go to Set scripting options and click the Advanced button
  • In the General category, go to type of data to script
  • There are 3 options: Schema Only, Data Only, and Schema and Data. Select the appropriate option and click on OK
Found that gem here.

Thursday, March 13, 2014

Automated Browser Testing using Selenium

I just started using Selenium for automated browser testing. It's turning out to be really nice as a kind of SharePoint site warm up script too. This is what I've got running on my box right now for automated tests on a schedule:

Setting up a Selenium test script to run on a schedule on Windows 7
  1. Create a directory on your local system c:\selenium
  2. Install the seleniumn IDE FireFox plugin for recording/saving tests.
  3. Record a browser test with a starting point of https://www.google.com.
  4. save the test as c:\selenium\MyGoogleTest.html.
  5. Save the test suite as c:\selenium\MyGoogleTestSuite.html.
  6. Download selenium-server-standalone-2.40.0.jar so you can run test scripts from the command line
  7. copy the selenium-server-standalone-2.40.0.jar to c:\selenium\selenium-server-standalone-2.40.0.jar
  8. create a bat file to run your test script command c:\selenium\RunMyGoogleTest.bat
  9. Edit the bat file and paste in this command:
    java -jar selenium-server-standalone-2.40.0.jar -htmlSuite "*firefox" "https://www.google.com/" "c:\selenium\MyGoogleTestSuite.html" "c:\Selenium\results.html"
  10. Open a command prompt, change the current directory to c:\selenium and run RunMyGoogleTest.bat. Firefox should launch and show your tests being performed.
  11. Create a new windows scheduled task. In the action tab, add a new action.
    • Action: Start a program
    • Program/Script: C:\Selenium\RunMyGoogleTest.bat
    • Start in (optional): c:\Selenium
  12. You can setup the task to run as any user that's ever logged onto your computer. So if you dont want to see windows opening every time the task runs, change the user the task runs as something other than your user account.
  13. Run the scheduled task by hand to confirm it works. Again, it should launch firefox and run your tests.
Tests fail because they run too fast. How do I force a slow test run?

You can force selenium to run the test slower by hacking up the test suite html. After the open command you can add setSpeed command that will force every clickAndWait method to pause before running the next command, giving the browser time to load page content. For more info - http://www.jnhasty.com/2013/02/15/using-the-setspeed-setting-in-selenium-standalone-htmlsuite-mode/