Tigraine

Daniel Hoelbling-Inzko talks about programming

Introducing ELMS-Connector v.1 Beta

When I joined the imagineClub in Klagenfurt and started building the new website I kept avoiding one major feature for a very long time: Implementing the remote-login for the MSDN-AA system by Microsoft.

The way imagineClub members get to MSDN-AA software is through a web-store called ELMS that handles licensing and downloading for us. ELMS supports two modes: integrated authentication or campus authentication. Integrated means that accounts have to be maintained inside ELMS while campus authentication means you manage accounts in your own system and ELMS will ask your services to authenticate users.

Now the first approach works for very small organizations where you can easily keep track of your members and (as admin) respond to their “oh god I lost my password” requests.
But with about 200 members like the imagineClub this alley leads into a world of pain and despair. So the only real solution is to implement the campus authentication that requires a authentication handshake between ELMS and imagineClub.

The documentation on the whole process is quite scarce, but with some reverse engineering of our old site and some FireBug network analysis I was able to eventually figure out how the whole system was supposed to work. It’s not that complicated after all, yet it’s not funny to have to re-invent it over and over again.

Since I knew that the Institute of Technology at Klagenfurt University has also acquired a MSDN-AA license for it’s staff I started working on the idea of a re-useable and easily pluggable library that could encapsulate all ELMS campus authentication logic to spare others the pain of implementing the thing from not so great documentation.

My main goals for this where:

  • Minimum configuration
  • Pluggable (being able to drop it into an existing ASP.NET app)
  • Variable authentication method (not everyone is using the same auth services we do)

Especially for pluggability I wanted the whole thing to live inside a DLL so I decided to implement a HttpHandler that will then handle the authentication.

The handler will look for a Login.htm file in your application’s root folder and display that file to users that need to log in. This means that you can easily modify the look&feel of your login page without having to mess with any ASP.NET code that can break. As long as you leave the name attribute of the username/password field intact all modification is fair game.

Once the user hits login the connector will then look into it’s configuration (I use Windsor for that) and invoke a supplied IAuthenticationService class. That means that you tell Windsor through the config what class servicing IAuthenticationService you want to call and it will get called with username/password.

This is the interface that users may need to implement:

public interface IAuthenticatonService
{     bool AuthenticateUser(string username, string password);
}

I intentionally said may because ELMS-Connector comes with a built-in LDAP auth service that you can use to simply hook up the login to your existing LDAP system without having to write any code at all (although that part is still in development).

Now, let’s get to the gory details.

How to set up:

1: Grab the release from the project’s download page

ElmsConnector download

2: Add reference to ElmsConnector.dll

ElmsConnector uses Castle Windsor internally but that dependency is merged into ElmsConnector.dll so you won’t run into any versioning issues.

3: Add httphandler to web.config

Add the following to your <httHandlers> section in the web.config:

<add verb="*" path="*.elms" type="ElmsConnector.ElmsHandler, ElmsConnector"/>

This makes all requests that end in .elms go to the ElmsConnector component that then does it’s magic.

4: Configure ELMS

Log into your ELMS dashboard and go to User Management –> Integrated Campus Authentication.

image

Set the Campus Authentication to Test Mode (while testing the connector).
The Campus Authentication URL should look like this: http://<yourserver>/Login.elms (or wherever the *.elms HttpHandler will be accessible).


Set Department to department (the suggested default value).

Campus CGI Server IP should be set to the IP your Server is using since ELMS will use the destination IP address to verify your identity.

Now don’t forget to copy the ELMS CGI Connector url since it will become of importance during the configuration of the connector.

4: Copy and modify sample elms.xml

Inside the release zip there should be a file called elms.xml, this file is the main configuration for the ElmsConnector. Copy it to the root of your web application and open it inside Visual Studio.

You now need to paste the ELMS CGI Connector url into the <cgiConnector> tag:

<component
  id="ElmsSessionRequestService">
  <parameters>
    <cgiConnector>https://msdn60.e-academy.com/<campus>/index.cfm?loc=login/cab_cgi</cgiConnector>
  </parameters>
</component>

And you’ll have to tell ElmsConnector where to find a type servicing IAuthenticationService. This is done by modifying the type attribute on the AuthenticationService component:

<component
  id="AuthenticationService"
  service="ElmsConnector.IAuthenticatonService, ElmsConnector"
  type="ElmsConnector.Web.FakeAuthenticatonService, ElmsConnector.Web" />

(I suggest you look at the provided sample project ElmsConnector.Web to see how this works)

5: Add the Login.htm

Inside the zip there is also a file called Login.htm. That file is nothing more than an empty template of the future Login dialog ElmsConnector will expose to users. Copy it to your web application’s root and edit it to your heart’s extend. All modifications are fair game as long as you don’t change the form parameter names or remove the $error$ placeholder.

6: Done

Yes. that’s it. You can now test the whole thing by visiting your ELMS portal page and hit Login. If your Campus Authentication Url is set correctly you should see the ElmsConnector’s Login.htm and be able to log in.

License

ElmsConnector uses the ASL-2 license and is therefore open-source-software. ASL-2 is a very permissive license that allows use of the code even in commercial closed-source scenarios. Still I’d appreciate if you’d let me know that you like ElmsConnector.

Problems

There may still be some problems with this release, if you notice anything strange or broken please open a Ticket on GitHub or shoot me a email.

Extending

ElmsConnector is very extensible through the use of Castle.Windsor internally. If you know your way around Windsor XML configuration you should be able to change everything about the connector without the need to recompile. Still I suggest you check out the source to find out what goes on there.

Future

I’ll be dogfooding this component during this week while getting the iC-Website ready for launch. After that I want to implement the LDAP authentication service that will ship with ElmsConnector so if you have an existing LDAP infrastructure you don’t need to write any real code at all.

Need help?

If you have any more questions regarding ElmsConnector or how to set it up in your special case, please feel free to send me an email or contact me through IM (Contact info). I’ll be happy to help you use ElmsConnector!

Git cheatsheet floating on your desktop as Windows 7 gadget

While browsing a bit through the GitHub guides section I noticed a wonderful git cheat sheet that outlines the most used commands with some basic usage instructions created by Zack Rusin.

I have a love/hate relationship with cheat sheets because most of the time I print them and then they usually merge with all the trash that’s laying around my desk so I hardly ever get to use them (except for when I really need them and they are laying face down below my mouse pad).

So the obvious place for that sheet would be my secondary monitor so I can refer to it when needed. Only problem here is that I really don’t want to run a browser window all the time just to see a cheat sheet, and setting it as my wallpaper would mean no more beautiful images changing every 10 minutes (I love Win7 for this!).

Now, what is between your applications and your desktop? Right: Windows gadgets.

By following the guide from the Microsoft developer center I very quickly ended up with a quite nice gadget that now beautifully floats above my desktop with all the common used git commands I need to check while scratching my head (dementia I hate you).

image

Pair this with the awesome Aero Peek at the desktop from Windows 7 (if you hit Win+Space all Windows become glass and you see your gadgets + desktop), and you can quickly glance at the cheat sheet without having to run any application or change your wallpaper. And if I don’t feel like doing git I just close the gadget with one click.

As said above, the cheat sheet is done by Zack Rusin. Thanks for this gem! The code for the gadget and the download is on GitHub and is licensed under the ASL-2 (yeah I like that license a lot).

The GitHub repository is at: http://github.com/Tigraine/git-cheatsheet-gadget

And to just download the gadget hit the downloads section within GitHub (or directly)

Oh and please excuse if GitHub is down sometimes right now. They are in the process of moving their servers to a new hoster and hopefully they will be reliably back up by Monday.

Filed under programmierung, tools

Make me wait

1 hour ago I noticed that I need the Castle.Facilities.Logging assembly, so I fired up SVN to checkout the newest trunk and run a build.

image

It took 53(!!!) minutes to checkout. Something is seriously wrong with SVN at times, there is no other way to explain the differences in speed I was seeing during checkout: Some files came with 50 kb/s, some with 2 kb/s and others with 100. That said: I’m sitting ontop of a 12 mbit ADSL-2 connection that peaks at about 1.6 mb/sec.

I hate waiting, and waiting an hour for a trivial operation that should not take any longer than 10 seconds is really the end. I only hope most projects get away from svn as soon as possible, the benefit in speed is just massive.

Oh and btw: I know that there are SVN mirrors of the castle project on GitHub, I already did a fork of one of those to pull it down. Only that it was 6 commits behind the current svn trunk and I couldn’t build the solution at that revision so I decided to re-pull the most current svn (big mistake).

Filed under personal

Windows 7 RTM available through imagineClub MSDN-AA

image

The Academic Alliance program lags a little bit behind the normal MSDN program, but last week Windows 7 finally hit the virtual shelves of our MSDN-AA subscription.

If you are a student at Klagenfurt University and a imagineClub member you can log in and download Windows 7 for free today.


Filed under imagineclub, windows-vista

How to ruin my day

In case you are somewhere stuck in a plan on how to make my day miserable I’ve got a tip for you:

Write absolutely horrible code like this and leave the maintenance to me:

Method signature:

internal void TryRequestSession(string securityToken, ref Guid secID)

Call site:

public ActionMethod Open(string securityToken)
{
	Guid secID = Guid.Empty;
	try
	{
		secID = new Guid(securityToken);
	}
	catch
	{}
	Guid oldSecID = secID;
	provider.TryRequestSession(securityToken, ref secID);
	if (oldSecID == Guid.Empty)
	//....
}

There are many things wrong with this code, but I’ll spare you the details and say that new Guid(securityToken) will always throw a ArgumentException and that I have absolutely no tolerance for void methods that have ref parameters!


Whatever was going on in that chimps mind who wrote that, it couldn’t have anything to do with programming.

So, recap: If you expect other people to maintain your code (I’m currently rewriting this thing, it’s easier) make sure you do the following:

  1. Have Unit tests that specify the behavior
  2. Leave an actual spec that can be looked at
  3. NEVER use ref if you can use return
  4. Don’t swallow exceptions (and if you have to, leave a comment!)
  5. Make it run!

Yes that’s right. If you leave a piece of crap behind, at least make it compile! I had to search for 3 totally outdated libraries to even make this piece of junk compile on my machine. Again: The GAC is your enemy!

Thank you, you now may go on with your lives while I feel a lot better and my actually start enjoying my coffee :)

Filed under net, programmierung, projects

Using a Mac Keyboard on Windows

I decided to do something really stupid: Spend 50€ on a Apple Keyboard.

image

Why? I was in the market for a keyboard that mirrors my laptop’s key press experience. The Apple Keyboard seemed like the perfect choice at first, and so I bought it at my local Apple retailer.

One thing I didn’t consider at the store was that on the Apple Keyboard ALT and Command have traded places, and the default mapping on Windows is Command = Winkey.

So, I found some handy guides on the internet on how to use the nice little program AutoHotkey to remap keys on the keyboard. So I could flip positions on Winkey and Alt.

Doing so with AutoHotkey is very easy and there are numerous scripts out there to do all sorts of crazy things. Here is the script I came up with after some time:

LWin::LAlt
LAlt::LWin
RWin::RAlt
RAlt::AppsKey
+F8::Send {Media_Play_Pause}
+F7::Send {Media_Prev}
+F9::Send {Media_Next}
+F10::Send {Volume_Mute}
+F11::Send {Volume_Down 2}
+F12::Send {Volume_Up 2}
F13::Insert
F14::PrintScreen

Also I have found it important to run AutoHotKey as admin, otherwise all these key mappings are lost whenever you enter a UAC protected area.

Now that the Key mappings are all set up I have to say that I am really happy with the keyboard so far. The typing experience takes some time getting used to, but it’s really solid and well manufactured and I am not really all that sure if I’ll go back to my Natural Keyboard 4000 anytime soon. (I might if the Apple one proves to be discomforting after prolonged use, but that remains to be seen).

PS: Windows Live Writer on my main machine decided to break. As of now I can’t write blog posts on my computer any more and I have on explanation for that (besides some Exception text stating that Courier New has no regular cut). And I get really pissed off by that (and by the fact that WLW is saving my drafts in some obscure binary format I can’t read).

Filed under personal

imagineClub Website source has moved to GitHub

I have been using Mercurial as my SCM of choice for quite some time now, and I’ve been loving it ever since. Working with a DVCS is a pleasure compared to the slow and painful experience I see when using Subversion. Not that Subversion is a bad product, but my workflow is just totally different from what SVN was built for.

Having used git now a bit while helping Erik on the Less.Net project, I discovered that it feels a tad better workflow wise. I especially like it’s much better branching support and it’s support for shelving changes. Both things already in hg, but not as easy to use or only available through addons.

Another thing that made the switch tempting was the fact that it seems almost the whole .NET community decided to head over to GitHub to continue development. There are NHibernate forks, there are Castle forks etc etc.. Even Ayende moved there!

So I decided to follow the herd, being familiar with the tools the community uses is very important to me, so today I finally moved the imagineClub website source to GitHub.

Why finally? Well, I’ve been trying to for now 2 days and simply failed. Today i finally decided that it’s OK for me to loose all my history and to start a fresh repo with the existing code. The migration from hg to git seems to be so uncommon that there is a significant lack of tools for that.

There is the hg2git from the GitHub crew, that didn’t work for me. And there is a hg2git script inside fast-export that I couldn’t run on Windows. Although Zerok managed to convert it on his Mac machine, all the linefeeds were wrong and therefore the history was rendered useless. So I decided to quit trying and simply wipe the history, start from scratch and be done with it.

So, now the new home of the imagineClub source is located here:
http://github.com/Tigraine/ic-website/tree/master

Feel free to watch / fork the repo.

The paging antipattern

Wherever you look on the internet, everywhere you’ll see pagination. This is especially important in web shop scenarios where you don’t want to overwhelm your user.

Usually you just take these things for granted and use them to navigate around, until you discover a gem of bad design like this one on the German bookstore Thalia:

image

This is a 1:1 screenshot, no scaling from the original. And as usual: the one < will take you to the previous page, the << will take you to the very first page.

Now, let’s consider these options that are only 3 pixels apart from each other: First page, previous (thus page 4), page 1.
Let’s just assume that unless you are really careful with you mouse you’re looking at a 2/3 chance of finding yourself on page number 1 instead of 4!

Instead of trying to home in on that tiny next button I found myself using the numbers to get to the next page, totally ridiculous.

Upon getting frustrated by this particular eBook store I decided to take a look at the other major players and their pagination solutions.

Amazon:

image

I just measured a distance of over 40 pixels between the 3 and the Next button. And even on a search where with less than 3 pages they keep a distance of at least 20 pixels between Next and 3. Also important that Next is always last and Previous is first. No First and Last button anywhere to be found.

Google:

image

Again, hitboxes for Previous and Next are enormous while completely lacking First and Last.

Ebay:

image

Bing:

image

 

Conclusion: Nobody uses these  Last and First any more. Get over it and leave them out! Why should anyone want to go to the last page of a listing that is probably already sorted by relevancy?

Instead use the space for huge Previous and Next buttons that are far away from any other navigational controls. At any rate, never ever use those <> Symbols alone as you means to navigate, always provide a big enough hitbox to avoid frustration.

Filed under internet

Using ActiveRecord&rsquo;s Field mapping to map custom enumeration classes

One thing that may be overlooked sometimes (I certainly did) is the ability of ActiveRecord to not only bind to properties but also to instance fields (yes, even private ones). This little feature came in very handy when I was looking for a way to persist a class based enumeration. I’ll tell you why in a minute.

First, I have Users that can be in one of 5 categories. None of which were important enough to warrant a foreign-key relationship modeling in the database, but I still wanted to encapsulate them in some sort of object to avoid doing string checking inside my code. The model looks like this:

image

I clearly didn’t want to have a Category table in my database, so I decided on creating the Category class while saving the Name property to the database.

Here is my implementation of the User.Category field:

[Field]
private string category;

public Category Category {     get { return Category.GetCategoryByName(category); }     set { category = value.Name; } }

As you can clearly see. My code is only dealing with Category objects (that can have implementations attached) while behind the scenes I only write the name of the category to the backing field. This way I get rid of magic strings inside my code while not having to burden my database with foreign key constraints.

Filed under net, castle, programmierung

I&rsquo;m in love with Android

Last year I bought myself a iPhone 2G through friend from the US and was very fond of it, mainly because I didn’t have a Smartphone before. But as time goes by, the limitations of the iPhone platform became more and more obvious.

I made the decision not to buy a newer generation iPhone when I was at the office one evening and needed to carry a large db dump file with me home. Imagine my feelings when carrying a 16GB iPhone that has about 13GB of free space available and not being able to use it as a thumb drive due to it’s lack of a mass storage mode. Luckily I had my DSLR with me so I formatted my 8GB SD card and used that instead. But not being able to place files on a phone is just plain stupid.

Also I’m just tired of iTunes and it’s totally retarded syncing model.
I’m a totally connected person, all my data is in the cloud, be it code (BitBucket, GitHub), email (Gmail), calendar (Google calendar), Google reader or contacts (Gmail). So having to plug my phone into the computer at regular intervals to update information on it is just not the way I wanted it to be. (Especially considering what a headache it is getting data synced between Outlook and Google’s services).

So going to a Android phone was a pretty logical decision for me. I can take all of my current data with me, use the wireless syncing capabilities that come with using Google’s Gmail and Calendar services, and be up and running in less than 5 minutes.

Actually, it only took about 3 minutes for Google to load all of my contact list into the phone and present me with a fully working environment of Contacts, Email and Calendar. And that’s really impressive.

And lastly, I’m a developer! Being able to develop for my own device is very important to me, and not owning a Mac and hating the idea of programming in objective C (believe me I tried) severely limited my ability to do that on the iPhone platform.
Android on the other hand is using Java (not perfect, but still way better than C) and is not constrained to a particular platform with their SDK.

Although the platform choice was easy, the phone one was hard. As of speaking there are only 3 serious Android handsets in the market: HTC Magic, HTC Hero and Samsung Galaxy.
And to be honest: None of the three is perfect. The Magic has no headphone jack, the Hero is very bulky and due to sense UI not always as Snappy as I’d like it to be and the Galaxy didn’t bring any interesting features besides the AMOLED display. 
Since none of the current devices is really perfect, I figured buying the cheapest one and letting the platform mature for another year would be the best course of action. So I bought the HTC Magic.

So far, I’ve been using my Magic for about two weeks and love it. It’s fast, having multi-tasking paired with push notification for almost everything from Google makes this phone simply a joy to use. I get email notifications faster on my phone than I get them through the GMail notifier on my PC. I can use Google Talk to chat with friends who use Android instead of writing SMS or look up their position through Latitude.
Also the battery life on my Magic is way better than it was on my iPhone. While I was lucky to get my iPhone through one day without plugging it in, my Magic can easily live through 2 with push services and background tasks enabled.

The Android Market is also filled with lots and lots of apps, so there is no real disadvantage from the iPhone here. I even came to appreciate the ability to scan barcodes on the phone while shopping!

Now, from my limited testing so far I found the following apps really nice and handy:

  1. twidroid (Twitter .. )
  2. Places Dictionary (Gives you POI near you)
  3. My Tracks (Running track recorder)
  4. NewsRob (Very good Google Reader app)
  5. Astrid Task/Todo List
  6. Wikitude World Browser (cool augmented reality from Austria)
  7. Google Maps (make sure to get the newest version manually from the Market)
  8. Battery Widget (from mipping.com)
  9. Barcode Scanner (also scans QR codes)
  10. Quickpedia (Wikipedia app)
  11. Google Sky Map (oh this is so awesome!)

But what I love most about the phone is simply it’s syncing! I edit all my contacts online through GMail and without even thinking about it they all get updated on my phone too. No hassle with plugging it in or anything, totally zero friction. It just works!

My only gripe with the thing so far: You can have only one input language for the keyboard selected at a time. Since I frequently use the phone to look through twitter or emails, I sometimes need to switch from German to English. The iPhone had that handy little button to switch, while the Android would require me to go through the phone’s settings.

Verdict: I’d never go back to my iPhone. Although the platform is still young and there are some rough edges to be worked out, I feel like Android will be a serious player during the next years.

Filed under personal

My Photography business

Projects

dynamic css for .NET

Archives

more