September 2004 - Posts

Windows Principal and the MAGIC_NUMBER
Wednesday, September 29, 2004 11:34 PM

A number of our apps use a mixed model of authentication. We have a Windows integrated authorisation site which extracts role information from intranet users, stores it in a cooke, and redirects to a forms aiuth site. Users not on the intranet can access via the forms auth site directly. Part of this process involves enabling impersonation on the windows auth site and extracting role information from the windows princpal. This is done using the code below :-

WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal princ = new WindowsPrincipal(ident);
princ.IsInRole("DummyRole"); // This call is required so that the subsystem goes and retrieves a list of roles.
FieldInfo field = type.GetField("m_roles", BindingFlags.Instance | BindingFlags.NonPublic);
String[] roles = (String[]) field.GetValue(princ);
return roles;

Notice how we get the string array of role from a private 'm_roles' member. All works fine....mostly... what I didn't know was that this string array is not used if the principal contains more than 23 roles. An internal hashtable i used instead.

The principal object has a 'MAGIC_NUMBER' internal variable that is set at 23. This is the limit after which the internal hashtable is used. So our code wa not working where an intranet user belonged to more than 23 groups.

To fix this, we used some more reflection so change the value of the MAGIC_NUMBER variable. See below :-

   Type type = princ.GetType();
   
   // Note: This code sets the 'MAGIC_NUMBER' field of the principal object.
   FieldInfo field2 = type.GetField("MAGIC_NUMBER", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
   field2.SetValue(princ,30);

The above code sets the MAGIC_NUMBER to 30, so we can now get 30 roles into the string array. This can obviously be changed to as much as you'd like.

So, moral of the story, if you are using reflection to extract roles from a windows principal, be aware oif the MAGIC_NUMBER limit when trying to get the roles from the 'm_roles' string array.

P.S. I assume this MAGIC_NUMBER limit is for performance reasons.

 

UML Modelling in VS.Net
Monday, September 27, 2004 12:05 AM

As part of the MSDN connection program offered by Microsoft here in Australia, I believe that all dedicated level developers received a copy of Borlands "Together" for Visual Studio.Net. An addin that lets you do UML modelling synchronised to source code. It comes complete with a patterns repository and other features. I wasn't too interested in synchronising source code but loved the idea of integrated UML modelling in VS.Net. I like UML and use it constantly to describe class designs and system designs for a lot of our detailed design documents we need to produce, as well as to simply describe a class design for developers in my team to work towards. (Note: If you dont use UML for your design work, I recommend you start, even if its just to describe class heirarchy and design for yourself)

While it certainly allows one to do all that is mentioned above, its not as nice as I would have hoped.The print features simply dont work properly, I ask it t print a class diagram, and 2 class models come out on one page, with the rest of the diagram on another page. Also, the code sync features seem to have some wierd effects in that occassionally, association lines would disappear and had to be redefined. Finally, sometimes I just dont want to enable the addin for every single project, particularly for large projects where it wasn't initially used. While there is an option to cater for this, it doesn't seem to always work as expected and I find myself disabling the option again and again.

I love the concept that this product tries to address and I it certainly has a good feature set, but still seem to be somewhat lacking in some areas of its execution.

I'd love to hear of other tools that people use for this that are integrated into VS.Net. Visio and Rational Rose are fairly well known but I'd like to know from others experience.

One final note, the MSDN connection program in Australia is a great initiative from Microsoft and the support shown to Australian developers is great. For more information, see Frank Arrigo's blog.

 

Technical Interviewss
Sunday, September 12, 2004 5:19 PM

I have been going for some job interviews lately, and what has been interesting is the technical interview aspect of each of them. I have been to what I consider 2 major interviews, each with the technical interview (they all consisted of at least 3 interviews) going for at least 2 hours, usually up towards 3 hours.

While both of them were for fairly prominent .Net related positions, tey they were both vastly different. One involved an initial multiple choice test, with a further one on one interview discussing some fairly detailed technical questions. The other involved almost next to no .Net related technical questions, but instead concentrated on process, architectural and design skills. The latter had me describing the software development lifecycle (SDLC), drawing plenty of UML diagrams such as use cases, sequence diagrams and class diagrams, as well as a quick code test I had to write up on a whiteboard. The individuals interviewing me were clearly of high quality but were definitely not .Net specialists (I had to explain some basics of ASP.NET operation such as code behind files).

As mentioned, the first interview had some fairly detailed technical questions, but were usually things that one could easily find using on line help, or a bit of searching on Google. It was more a memory thing, whereas the second interview definitely exercised skills that you cannot get from some help system, a reference manual or anything else except experience. It was damn hard, but I did pretty well and even if a) I dont get the job or b) dont want the job, it was a very valuable exercise in architectural and design knowledge.

Motto of the story: Know the expectations of your job interview. Knowing a method signature on a particular function of a .Net library may not help you at all, and in the end, nothing is a substitute for experience. This kind of implies I have a huge base of experience, which is really subjective and may or may not be true, but the point is that my general experience has served me better than my knowledge of method level functions in a class.

I'd be interested in others experiences in technical interviews though. What else have you come across?

More Posts

This Blog

Syndication