Mono Support MonoX Active Directory integration problem 

Viewed 11715 time(s), 5 post(s), 3/13/2015 7:44:06 AM - by pmalara
3/13/2015 7:55:41 AM
26 Reputation 3 Total posts

Hi all!
Using the MonoX latest version (MonoX v5.1.40.5107, DB v5.1.40.5027) I'm trying to set up the domain authorization. I followed this tutorial precisely - http://monox.mono-software.com/blog/post/Mono/92/MonoX-Active-Directory-integration/ but I encountered a problem: after entering login and password on login page (and clicking the Log In button) the following exception message appears:

[InvalidCastException: Specified cast is not valid.]
MonoSoftware.MonoX.ModuleGallery.LoginModule.#Gp(Object sender, EventArgs e) +379
System.Web.UI.WebControls.Login.AttemptLogin() +490
System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +78
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3586 

Here are the domain integration settings from my web.config:
...
<ActiveDirectoryConfiguration server="dc.domain.local" username="domainuser" password="password" />
...
<add name="ADConnectionString" connectionString="LDAP://dc.domain.local/OU=MONOX-INTEGRATION,DC=domain,DC=local" />
...
    <membership defaultProvider="ActiveDirectoryMembershipProvider" hashAlgorithmType="SHA1">
      <providers>
    <remove name="AspNetSqlMembershipProvider" />
        <add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="MonoX" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="MonoSoftware.MonoX.MonoXMembershipProvider, MonoX" />
        <remove name="ActiveDirectoryMembershipProvider" />
<add name="ActiveDirectoryMembershipProvider" type="MonoSoftware.MonoX.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" applicationName="MonoX"
         connectionUsername="domainuser@domain.local"
         connectionPassword="password" />
      </providers>
    </membership>
...
    <roleManager enabled="true" defaultProvider="ActiveDirectoryRoleProvider">
      <providers>
<remove name="AspNetSqlRoleProvider" />
        <add connectionStringName="LocalSqlServer" applicationName="MonoX" name="AspNetSqlRoleProvider" type="MonoSoftware.MonoX.MonoXRoleProvider, MonoX" />
        <remove name="ActiveDirectoryRoleProvider" />
        <add applicationName="MonoX" name="ActiveDirectoryRoleProvider" type="MonoSoftware.MonoX.ActiveDirectoryRoleProvider" connectionStringName="ADConnectionString"
          groupMode="Additive"
          groupsToUse=""
          groupsToIgnore=""
          usersToIgnore=""
          sqlConnectionStringName="LocalSqlServer"
          cacheTime="0"
          domainName="domain.local"
          userName="domainuser@domain.local"
          password="password"
        />
      </providers>
    </roleManager>


Few more informations:
1) Communication with the Active Directory works ok - there's no authorization errors in log.
2) It seems to that some things work ok - the aspnet_Roles table is filled with domain groups from selected container (OU=MONOX-INTEGRATION).
3) The user also is inserted into the aspnet_Users table.
4) If I switch the membership provider in web.config back to the AspNetSqlMembershipProvider and leave the roleManager with the ActiveDirectoryRoleProvider the MonoX gets the users from SQL DB and roles from domain. This works properly. So I think the problem is somewhere in the ActiveDirectoryMembershipProvider (or code using it).
5) In the OU=MONOX-INTEGRATION I have users and domain groups. Domain groups names match the MonoX roles (e.g. Administrators, Users, etc.)

I even tried to set the IIS pool user to NetworkService, as someone said here (http://monox.mono-software.com/Mono/Pages/Discussion/dtopic/2_ENR6f5okKSmKIbAUmLeg/Active-Directory-Authentication-Integration/) but with no success.

What can I do to make it working? Please help.

Best regards,
Piotr Malara

PS. One more thing: below are the log entries in MonoX log file after each log in try:

2015-03-13 08:28:04,155 [37] ERROR MonoX [::1] - Error
System.InvalidCastException: Specified cast is not valid.
   at MonoSoftware.MonoX.ModuleGallery.LoginModule.#Gp(Object sender, EventArgs e)
   at System.Web.UI.WebControls.Login.AttemptLogin()
   at System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e)
   at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
2015-03-13 08:28:04,157 [37] ERROR MonoX [BaseHttpApplication] - Application Error
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidCastException: Specified cast is not valid.
   at MonoSoftware.MonoX.ModuleGallery.LoginModule.#Gp(Object sender, EventArgs e)
   at System.Web.UI.WebControls.Login.AttemptLogin()
   at System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e)
   at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

1
3/13/2015 3:55:05 PM
1384 Reputation 152 Total posts

Hi pmalara,

I think I know what the issue is.
Unfortunately there's no quick fix.
You'll have to wait for the nightly build next week.

Regards,
Igor

2
3/14/2015 11:26:31 AM
26 Reputation 3 Total posts

Thank you for your answer.

So I'm waiting impatiently for the nightly build.

Best regards,
Piotr

3
3/19/2015 2:08:17 PM
1384 Reputation 152 Total posts

Please try the v5.1.40.5126 nightly
http://monox.mono-software.com/nightly-build/

Thanks

4
4/2/2015 12:34:53 PM
26 Reputation 3 Total posts

The login proces works properly now. Thanks for the fix.

5
This is a demo site for MonoX. Please visit Mono Software for more info.