Friday, April 18, 2008

Intranet Applications with Role-based Security using Windows Authentication and SQL Server

First of all, I would like to thank ScottGu, again for a job well done on this tutorial on how to implement Windows authentication for an INTRANET website that works against a sql server database.

I recently added authentication scheme for an intranet website that I developed. There are some reports and tools that are supposed to be accessed only by some priviledged people within the organization. No login is required since this is an intranet application. But I needed a way to restrict access to some pages. The easiest way to maintain such a website is by adding a role-based security that is tied-in to Active Directory user account. Anyways, following this recipe that Scott Gu concocted, I got up and running quickly. Thank you Scott!

Btw, I translated the Visual Basic code to C# below...

private void PopulateRoleList(string userName)

    {

        if (!String.IsNullOrEmpty(userName))

        {

            RoleList.Items.Clear();

            foreach (string roleName in Roles.GetAllRoles())

            {

                ListItem roleListItem = new ListItem();

                roleListItem.Text = roleName;

                roleListItem.Selected = Roles.IsUserInRole(userName, roleName);

                RoleList.Items.Add(roleListItem);

            }

        }

    }

 

    private void UpdateRolesFromList()

    {

        foreach (ListItem roleListItem in RoleList.Items)

        {

            string roleName = roleListItem.Value;

            string userName = TxtUserName.Text;

            bool enableRole = roleListItem.Selected;

 

            if (enableRole == true && Roles.IsUserInRole(userName, roleName) == false)

            {

                Roles.AddUsersToRole(new string[] { userName }, roleName);

            }

            else if (enableRole == true && Roles.IsUserInRole(userName, roleName) == true)

            {

                Roles.RemoveUserFromRole(userName, roleName);

            }

        }

    }

 

    protected void LookupBtn_Click(object sender, EventArgs e)

    {

        PopulateRoleList(TxtUserName.Text);

        UpdateBtn.Visible = true;

        LabelRoleMembership.Visible = true;

    }

 

    protected void UpdateBtn_Click(object sender, EventArgs e)

    {

        UpdateRolesFromList();

        PopulateRoleList(TxtUserName.Text);

        PopulateRoleList(TxtUserName.Text);

    }

Friday, April 04, 2008

Features in Hardy Heron Release of Ubuntu

I can't wait for the latest version of Ubuntu named "Hardy Heron". If you are interested to see what's new in this new version look here. I have been using Ubuntu since "Hoary HedgeHog". I have used a number of Linux distros, but the first time I looked at Ubuntu, I liked it right away and stayed with it. It's the best Linux distro for me. In case you're wondering what the past and future versions of Ubuntu were called, here's a list I compiled...

Version Code Name Release Date
4.10 Warty Warthog 2004-10-20
5.04 Hoary Hedgehog 2005-04-08
5.10 Breezy Badger 2005-10-13
6.06 Dapper Drake 2006-06-01
6.10 Edgy Eft 2006-10-26
7.04 Fiesty Fawn 2007-04-19
7.10 Gutsy Gibbon 2007-10-18
8.04 Hardy Heron 2008-04-24
8.10 Intrepid Ibex 2008-10-30

Interesting to note from this list is that if you look in the version number, the first number is the year it was released, the second number after the dot is the month it was released. Based on the dates, I have been using Ubuntu for 3 years now!