Sunday, August 12, 2007

Configuring SSO

After analyzing JOSSO and CAS as candidates for SSO , the JOSSO implementation seems very promising.
What is SSO ?


1) Just works. Can easily embed my application to the SSO framework.
2) Out-of-the box seem less integration with custom made tomcat. Inbuilt SSL configurations.
3) To-Do steps
i) Download Josso tomcat
ii) Refer to
iii)\conf\jaas.conf (Spent a romantic night for this. Had to write it )
iv) For getting the login data from the DB refer to this

1) Pathetic Docs
2) In-active community.

I could not get CAS working on my system. I know it works, but somehow the jigsaw is not complete. The community is very active and vibrant.Updated wiki . Let me know if anyone gets it working.

Thursday, August 09, 2007

"C" the Bug - Part I

1. Find the bug.

All necessary Headers included like stdio.h, stdlib.h, string.h etc.

int main()
char *str = NULL;
int i = 1;
str = (char*)malloc(sizeof(char)*2);
if(!str) {
printf("Malloc Failed\n");
strcpy(str, "Hi");
printf("%c\n", str[i*i+i/i]);
str = (char *)realloc(str, sizeof(char)*20);
if(!str) {
printf("Realloc Failed\n");
strcpy(str, "Hello World\n");
i = 2;
printf("%c\n", str[i*i+i/i]);
return 0;

2. In a doubly linked list, the nodes are paired and these pairs have to be reversed.

For Ex: If the linked is as below,
Output should be:

Struct is as below:
typedef struct node {
int data;
struct node *next;
struct node *prev;

Handle all the conditions. This question was asked in Microsoft Interview.
Deadline is on 18th Aug 2007.
Send it to me at or post in the comment.

Challenging the Code
* You need to have trust in me.
* Specify in your mail or comments as "Challenge".
* Rs.50/person.
* Max. challenge amount = Rs.(No. of Persons challenging * 50). Conditions Apply.
* If your code breaks under any conditions, you will lose the amount.
* If your code works smooth, you will win the Total Challenged amount.
The challenge amount increases if anyone supports me. Specify in your mail or comments as "Support". For those supporting me will definitely get a share if someone loses the challenge.

If not interested in challenge or support, you can also mail or post comment as "Fun".

Friday, August 03, 2007

Curiously Recurring Template Pattern (CRTP)

The funny named phrase is used to describe the use of a derived class type as a template parameter for its own base class! In simplest form, this is what I'm talking about:

template < typename T >
class Base{ };

class Derived : public Base< Derived > { };

Let me give a very simple example of where this might be useful. Suppose you want to keep track of how many objects of a particular class are alive at any point in time:

Simple approach is:
1) Keep a private static "count" member in the class
2) Increment the count in every constructor
3) Decrement the count in the destructor
4) Provide a public interface to query the value of the count

This approach is fine. However you have to do this for every class that you want to count the objects of. CRTP can pitch in and provide an elegant solution that is highly reusable.

template < typename CountedType >
class ObjectCounter
    static int counter;

      ++( ObjectCounter< CountedType >::counter );

    ObjectCounter( const ObjectCounter< CountedType >& obj )
      ++( ObjectCounter< CountedType >::counter );

      --( ObjectCounter< CountedType >::counter );

    static int live()
      return ObjectCounter< CountedType >::counter;

template < typename CountedType >
int ObjectCounter< CountedType >::counter = 0;

Any class that wants to do object counting will inherit from the above class as follows:

class TestClass : public ObjectCounter< TestClass >{ };

TestClass::live() will give the number of objects alive at that point in time.