Welcome Guest Search | Active Topics | Members | Log In | Register
How To: Integrate Gallery Server Pro with Active Directory Options
Roger Martin
Posted: Tuesday, May 20, 2008 4:57:17 PM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
You can configure Gallery Server Pro to use your existing accounts in Active Directory. Woo HOO! Crack open the Skittle-brau and pretzels!

Gallery Server Pro uses the ASP.NET Membership Provider model to manage users and roles. By default, it is configured to store this data in a SQLite database. However, you can take advantage of an entirely different data store through the use of alternate membership providers such as ActiveDirectoryMembershipProvider or even one you write yourself. In this article I'll describe how to modify a default installation of Gallery Server Pro to use Active Directory for user management.

Step 1: Configure basic AD integration
The first step in Active Directory configuration is to modify the web.config file in the root of the Gallery Server Pro application. Add a connection string to AD:

Code:
<connectionStrings>
    ...existing connection string(s) here...
    <add name="ADConnection" connectionString="LDAP://192.168.1.1/CN=users,DC=mydomain,DC=techinfosystems,DC=com"/>
</connectionStrings>


The value 192.168.1.1 is the IP address of the domain controller. You can also specify the Fully Qualified Domain Name (ex. mydomain.techinfosystems.com), the Relative Distinguished Name (ex. godzilla if that is the name of your DC); or for more redundancy you can specify just the domain name (ex. mydomain). Which ever you choose just be sure you can ping it.

The next step is to comment out the existing membership configuration by adding <!-- to the beginning and --> to the end, like this:

Code:
<!--<membership defaultProvider="SqlMembershipProvider">
  <providers>
    <clear/>
    <add applicationName="Gallery Server Pro" connectionStringName="GalleryServerDbConnection" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="2" requiresQuestionAndAnswer="false" passwordFormat="Clear" enablePasswordReset="true" enablePasswordRetrieval="true" requiresUniqueEmail="false" maxInvalidPasswordAttempts="50" passwordAttemptWindow="10" name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>
  </providers>
</membership>-->


Now add the new membership info for Active Directory:

Code:
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
  <providers>
    <clear/>
    <add name="AspNetActiveDirectoryMembershipProvider"
          type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
                connectionStringName="ADConnection"
                enableSearchMethods="true"/>
  </providers>
</membership>


The version number must match the one installed on your web server, so update it as needed. Some examples I saw on the internet used 2.0.3600.0 instead of 2.0.0.0. Make sure the connection string name matches the name you specified in the connection string definition. The enableSearchMethods attribute is required so that Gallery Server Pro can retrieve a list of all users on the user management page.

Now, at this point you should be able to log on to Gallery Server with your domain account, but you will receive the following message:

Quote:
Insufficient permission. You are not authorized to view any albums. Contact your administrator to request access.


This is because your user account is not a member of any roles in Gallery Server Pro. Recall that when you installed Gallery Server Pro, a role named System Administrator was created with administrative permission. Now you need to add one or more AD users to this role. But how do you do this when no one has authorization to perform this task?

If you are using IIS 7, the answer is easy. Open up IIS Manager, navigate to the Gallery Server Pro web app, and click .NET Users. A list of your AD users appears. Double click the one that you want to be the administrator, and add the user to the System Administrator role in the dialog box. The next time you log on to Gallery Server Pro you will have administrative access.

For IIS 6 and earlier users, the task is more difficult because those versions don't provide a means for accessing the users. However, all versions of Visual Studio 2005 and higher - including the free Express versions - provide the Web Site Administration Tool, which allows you to edit the roles for users. Using this tool is beyond the scope of this document, but online information can be found.

At this point you should be able to log on using your AD account. Use the syntax user@fully_qualified_domain_name, such as Roger@mydomain.techinfosystems.com. Later I'll show you how can get change it to just the username.


Step 2: Create, edit and delete AD accounts within Gallery Server Pro
Once you are logged on as an administrator, you can go to the Manage Users page and add the remaining AD accounts to appropriate roles. If the IIS user account does not have permission to make changes to AD, you may receive an error like this when you click Save changes:

Quote:
Cannot update user. General access denied errror


You will get this error because the IIS worker process does not have permission to modify AD data. To get around this, you have two choices:

1. Specify a domain account in web.config that has the necessary permission. Open web.config and add connectionUsername and connectionPassword attributes to the provider definition, like this:

Code:
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
  <providers>
    <add name="AspNetActiveDirectoryMembershipProvider"
      type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
        connectionStringName="ADConnection"
        enableSearchMethods="true"
        connectionUsername="RMartin"
        connectionPassword="mypassword"/>
  </providers>
</membership>


Note that putting an AD account name and password in a plain text file is a security risk. If you go this route, I HIGHLY recommend you encrypt the web.config file. Here are two links where you can learn more:

How To: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI
http://msdn.microsoft.com/en-us/library/ms998280.aspx

Video: How Do I: Encrypt My Web.Config File?
http://weblogs.asp.net/scottgu/archive/2006/01/09/434893.aspx

2. Specify an account for the IIS worker process that has the necessary AD permission. I prefer this over the first solution.

Once the permissions are sorted out, you have the potential to create, edit and delete users. Remember that adding a user creates a new account in Active Directory and deleting an account removes it! Obviously this can be abused in a way that affects your entire domain, so use caution. For this reason, you may actually prefer to revert to read-only permissions and handle role membership via IIS 7 Manager (or the Web Site Administration Tool for IIS 5-6).

Options
Log on with simple username instead of fully qualified name

Your users might prefer logging on with just the user name rather than the fully qualified name. That is, instead of typing Roger@mydomain.techinfosystems.com, you enter Roger. To enable this feature, add the attributeMapUsername to the membership configuration:

Code:
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
  <providers>
    <add name="AspNetActiveDirectoryMembershipProvider"
      type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
      connectionStringName="ADConnection"
      enableSearchMethods="true"
      attributeMapUsername="sAMAccountName"/>
  </providers>
</membership>


By setting attributeMapUsername to sAMAccountName, you can log on with just the username, such as 'Roger' in the previous example.

Additional provider options

The AspNetActiveDirectoryMembershipProvider provider includes several attributes I haven't mentioned. These attributes configure various logon and password options. Be sure to check them out if you want more control.


Additional Notes
Can't use Windows groups

If you are using AD, you probably use Windows groups to control permissions. You may have a Marketing group whose members have read/write access to the marketing shared folder but read only access to the Development and Engineering folders. Wouldn't it be nice if you could map albums in Gallery Server to your groups, so that the Marketing users would have control over the Marketing album, Developers have the Dev album, and so on?

On the surface, it seems we can just use the WindowsTokenRoleProvider instead of the SqlRoleProvider. However, if one tries this, the following error occurs during application startup:

Quote:
"The configured Role Provider (WindowsTokenRoleProvider) relies upon Windows authentication to determine the groups that the user is allowed to be a member of. ASP.NET Role Manager cannot be used to manage Windows users and groups. Please use the SQLRoleProvider if you would like to support custom user/role assignment."


This error is generated when Gallery Server Pro tries to get a list of all roles with the Roles.GetAllRoles() method, and the WindowsTokenRoleProvider does not support it. Unfortunately, Gallery Server cannot do its job unless it can get a list of the roles, so for the time being we cannot take advantage of the Windows groups. If anyone discovers a way around this, let us know.

Can't auto-logon users

Back in my classic ASP days I built an intranet app that automatically recognized the Windows account the user was logged on with. No separate logon inside the web app was required. For reasons I don't understand, I cannot accomplish the same thing with ASP.NET Membership. Sure, you can disable anonymous authentication, enable Windows authentication, and turn on impersonation in web.config. Doing this *does* allow Gallery Server Pro to automatically log on users, but it doesn't think the user is in any roles, and there doesn't seem to be any way to configure roles for the user. Let us know if you know a way around this.

Can't reset or change password on other accounts

I didn't spend much time investigating this, but it appears you can't use Gallery Server Pro to reset or change another user's password. I received error messages when I tried. You *can*, however, change your own password by clicking the My account link in the top right corner and then clicking Change password.



Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Wednesday, October 29, 2008 5:56:31 AM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
I installed Pro 2.1 on W2K3 with a local SQL 2K server.

Pro 2.1 works fine with SQL2K and when I tried to modify web.cofig following above steps to access the Active Directory, error show up as:

syntax error at line 141 at the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config, cannot find connectionstring "LocalSqlServer".

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>

Is that related to the use of SQL Server? SQL is now in mixed mode and I have defined sa passwords during the setup.
Roger Martin
Posted: Wednesday, October 29, 2008 8:35:35 AM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
It looks like you didn't comment out the SQL Membership provider. Review the steps above to see how to do this (it's near the beginning).


Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Wednesday, October 29, 2008 11:38:17 AM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
On the contrary, it seems the above error happened after I have commented out the <membership defaultProvider="SqlMembershipProvider"> section.

If the <membership defaultProvider="AspNetActiveDirectoryMembershipProvider"> section was added without commenting the defaultProvider="SqlMembershipProvider" section, the error shown was the repeating error of defaultProvider="AspNetActiveDirectoryMembershipProvider">

I tried to run the installer again using sa passwords and explicit IP addresses for SQL server, it runs well at default installation. However I cannot get through the web.config once editing the membership section for AD membership.

I'm now using the web_sqlserver_3.5.config as the installation template for web.config. The W2k3 server runs on .Net3.5 SP1.

Appreciate if any more clues can be provided.
Roger Martin
Posted: Wednesday, October 29, 2008 11:47:20 AM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
Why do you have a provider named AspNetSqlMembershipProvider? Seems to me you should only have one membership provider specified in web.config, and it should be named AspNetActiveDirectoryMembershipProvider.


Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Wednesday, October 29, 2008 12:35:12 PM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
Looks like AspNetSqlMembershipProvider comes default in machine.config. The machine.config shown was located in the .NET Framework2.0 folder (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config). There was no such membership providers in the web.config.
Roger Martin
Posted: Wednesday, October 29, 2008 12:43:37 PM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
Oh, I see. Add a <clear /> to the membership section so that it is not inherited from the parent config file. I edited the original topic to include it, so refer to it to see how it is done.


Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Wednesday, October 29, 2008 1:15:53 PM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
Thank you, <clear/> solves the error.

Now I am stucked at the AspNetActiveDirectoryMembershipProvider line. How can I determine the correct version number of the webserver? I tried 2.0.0.0 and 2.0.3600.0 and don't know if the version number is giving the error.
Roger Martin
Posted: Wednesday, October 29, 2008 1:43:13 PM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
I am sorry, but I don't know the answer to that. You'll have to google around.


Roger Martin
Creator and Lead Developer of Gallery Server Pro
sam
Posted: Wednesday, October 29, 2008 4:18:47 PM
Rank: Advanced Member

Joined: 8/6/2007
Posts: 103
Location: England
Hi

heres How

asp version
Paul
Posted: Wednesday, October 29, 2008 8:14:56 PM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
Thank you Sam, Actually I tried 2.0.50727.0 or 2.0.5072.7 but error remains the same as using 2.0.0.0 etc. It looks like this section only accepts version number in x.x.x.x format such that the numbers shown on the properties of ASP.net 2.050727 will not work directly as the version number.

This is exactly the the line in the membership defaultProvider section
<add name="AspNetActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" enableSearchMethods="true" connectionUsername="helpdesk@mydomain.com connectionPassword="password"/>

The webserver (not a member in the domain) has full network access rights to the domain controller and the username and password should be working over drive mapping test.

This is what is added section in <connectionStrings>

<add name="ADConnection" connectionString="LDAP://10.8.0.14/CN=users,DC=mydomain.com,DC=MYDOMAIN,DC=com"/>

The LDAP for the domain controller should be working well as I have other LDAP clients accessing the Windows 2K3 Domain user database over LDAP.

Error show was at the line in <add name="AspNetActiveDirectoryMembershipProvider"...

Any suggestion appreciated.

Paul
Posted: Wednesday, October 29, 2008 8:29:05 PM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
I noticed the version number was also shown on the bottom the debug page as 2.0.50727.3053 (although 3053 was not shown in the properies of the website).

I put in this version number and error remain the same. (I assume this version number is right)

If I removed the "connectionUsername=..." section, the debug page will show unable to establish secure sever connection.

Roger Martin
Posted: Thursday, October 30, 2008 9:53:26 AM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
I opened Win Explorer on my Win Server 2008 machine (.NET 3.5 SP1) and navigated to C:\Windows\assembly\ to take a look at System.Web.dll. There it is reported to have version 2.0.0.0. I would expect - but am not sure - that you want to make sure web.config matches this number. You will also see the PublicKeyToken in this directory, so make sure that matches as well.

Perhaps you have another issue altogether. If you provide the error message we'll try to give you a hand.


Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Thursday, October 30, 2008 10:42:25 AM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
Thank you very much Roger. The System.Web.dll showed the same token and version 2.0.0.0.

If the password username and password were right, the only error message shown was server returned a reference, error at source D:\Websites\PhotoGallery\web. line 94 <add name="AspNetActiveDirectoryMembershipProvider...

An interesting thing is that when I enter a wrong user password, it will return error saying "unable to establish secure server connection"

Looks like the authentication did happened the Active Directory Level.
Roger Martin
Posted: Thursday, October 30, 2008 10:51:03 AM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
Please provide the full text of the error message, including the call stack (stack trace) if shown. I can't google for help based on what you provided.

I agree that it looks like AD is authenticating, so you are making progress...


Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Thursday, October 30, 2008 11:02:41 AM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
Hope this will provide some clues

When password is right:

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: A referral was returned from the server.


Source Error:


Line 92: <providers>
Line 93: <clear/>
Line 94: <add name="AspNetActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" enableSearchMethods="true" connectionUsername="helpdesk@mydomain.com" connectionPassword="********"/>
Line 95: </providers>
Line 96: </membership>


Source File: D:\Websites\PhotoGallery\web.config Line: 94



Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
Paul
Posted: Thursday, October 30, 2008 11:06:47 AM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
This is the error when I the password was wrong
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unable to establish secure connection with the server

Source Error:


Line 92: <providers>
Line 93: <clear/>
Line 94: <add name="AspNetActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" enableSearchMethods="true" connectionUsername="helpdesk@mydomain.com" connectionPassword="**wrong**"/>
Line 95: </providers>
Line 96: </membership>


Source File: D:\Websites\PhotoGallery\web.config Line: 94



Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
Roger Martin
Posted: Thursday, October 30, 2008 11:25:52 AM
Rank: Administration

Joined: 8/3/2007
Posts: 1,695
Location: Fort Atkinson, WI
There are a lot of Google hits on that error. This one says the AD connection string may be incorrect. You didn't provide your connection string, so I can't tell if it is right. Even if you did provide it, I still might not be able to tell if it is correct, since I don't know your network. You might try putting together a little .vbs script to test your connection string, or do some other test to verify the string. That will narrow down the cause between GSP and your connection string.

You also might review the Google hits on that error. I only looked at the first few...


Roger Martin
Creator and Lead Developer of Gallery Server Pro
Paul
Posted: Thursday, October 30, 2008 12:45:56 PM
Rank: Member

Joined: 10/29/2008
Posts: 12
Location: Shanghai
Great thanks!! You are absolutely right about the connection string being incorrect. The Windows domain name I was using was seperated by two dots.

Domain name: mydomain.com.cn
DC server name: myserver
Domain controller IP: 10.8.0.14

So instead of this
LDAP://10.8.0.14/CN=Users,DC=mydomain.com.cn,DC=myserver,DC=COM"/

become the working string like this

LDAP://10.8.0.14/CN=Users,DC=mydomain,DC=COM,DC=CN"/

By the way the GSP server is not a member server in the domain.

Now I'll proceed with assigning user roles. Appreciate you help again!
mbayhylle
Posted: Wednesday, December 03, 2008 5:19:33 PM
Rank: Newbie

Joined: 12/3/2008
Posts: 1
Location: Kansas City
Thanks for all that you've done with this product. Has anyone had any luck integrating this into an AD structure with a parent + subdomain structure? Or is there a way to authenticate through the top-most domain down through the child?
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.2 (NET v2.0) - 9/27/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.