Click here to register.
      
PBWG Banner


     Discuss > Etcetera

SQL Lookup for group membership fails

User Jesse
Date 4/20/2006 3:36 am
Views 2095
Rating 3    Rate [
|
]
Previous · Next
User Message
Jesse

Using 6.8.8, and just trying to make some special groups which use the results of an sql query to determine whether the user belongs to that group.

I've got a simple mysql database that I'm using which basically has two fields - Login (which has the username of the user) and another field User which holds either 0 or 1 depending on whether they should have access or not.

The group is set up with a simple sql query that is:

SELECT 1 FROM users
where Login = "^@;"
      AND User = 1

Cache external groups is set to 1hr.

Now.. here's the wierd part.  If one of these users who should have access logs in and tries to access either a page that is restricted (to this group), or even if the page has a GroupText macro which tests whether they belong to the group, then it fails the first time they do so.  If they refresh the page or try again - it works and they have access - but it seems to forget again after an hour.

I'm baffled why it's failing the first time - but it's broken the way it's currently working and I have no idea how to fix it (or even if it's actually a bug and not something I'm doing)

Surely some of you are using this functionality to determine whether users belong to certain groups?

If anyone can help I'd really appreciate it.

Jesse 

--- (Edited on 4/20/2006 3:36 am [GMT-0500] by Jesse) ---



Back to Top
Rate [
|
]
 
 
colink

I'm not sure why your users have to reload the page, but I can tell you exactly why the 1 hour behavior happens.

The dbCacheTimeout isn't really a cache timeout.  What it does is add the current user (if they match the SQL query) to that group with an expiration time of the dbCacheTimeout.  In a way, you could say they're cached in the actual WebGUI group instead of the external database and the system checks for WebGUI group membership before it checks any of the external group methods (scratch filter, LDAP, etc.)

One hour later, that user's membership in the group expires, and then the original problem (needing to reload) happens again, which puts them back in the group, and the cycle repeats from there.

You can reduce the frequency of that happening by increasing the dbCacheTimeout.

In 7.0 this whole system will work much more predictably.

--- (Edited on 4/20/2006 10:55 am [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
Jesse

After much debugging I've found the bit of code that doesn't seem to work correctly when looking up groups in an external DB.

In Grouping.pm there's a function isInGroup() - this has a section which looks up an external database if specified - this is where it actually gets tested.

If the lookup is successful, and the result is 1 then it has a bit of code:

$session{isInGroup}{$uid}{$gid} = 1 unless ($session{config}{disableCache}); 

This assignment does not seem to work - as later when it does a call:

return 1 if ($session{isInGroup}{$uid}{$gid});

the value returned by $session{isInGroup}{$uid}{$gid} is blank.

This causes it to fail the first time - though it has added the user to the group already, so next time it works.. until the group assignment expires and it happens again.

I don't know why that assignment fails - I'm an amateur at perl (though I write code in C/C++ daily) - but I do know how to debug code and I littered the code with trace statements in order to figure this out.  I've fixed it by using my own variable which I set to 1 if the lookup is successful (and it defaults to 0 if not) and I've changed that return statement to use my variable)

I'll post this up on sourceforge as a bugfix - hopefully someone with better perl skills will understand why that assignment doesn't work - but in the meantime my hack fixes the issue we were experiencing here.

Cheers,

Jesse 

--- (Edited on 4/24/2006 1:52 am [GMT-0500] by Jesse) ---



Back to Top
Rate [
|
]
 
 
colink

And you don't have disableCache set in your WebGUI.conf file?
--- (Edited on 4/24/2006 11:30 am [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
Jesse

No - there's no mention of disableCache in my config file.

I also tried it early in my debugging by removing that unless clause - even changing it to:

$session{isInGroup}{$uid}{$gid} = 1;

didn't work.

I have no idea why - as I said, my perl knowledge is limited.

Instead, I just ignored it for this clause and added a line below it with:

$returnvalue = 1; 

and changed the return 1 if ... call to

return $returnvalue;

Oh.. and I declared my $returnvalue = 0; at the top of that section also.

This solved the problem for me.

--- (Edited on 4/26/2006 1:17 am [GMT-0500] by Jesse) ---



Back to Top
Rate [
|
]
 
 
     Discuss > Etcetera



Recent Discussions Color Key

Design:

Development:

Et Cetera:

Install/Upgrade:  

Smoketest:

Template Group:


Re: Navigation links by techwriter - Fri @ 03:23pm

Re: Best way to make files available to webgui comunity by bernd - Fri @ 02:50pm

Re: User event history by knowmad - Fri @ 02:02pm

Re: Best way to make files available to webgui comunity by lctn2 - Fri @ 01:55pm

Re: Strategic Roadmap by JT - Fri @ 01:55pm

Re: Navigation links by rogier - Fri @ 01:55pm

Re: 2009 Presidents Meeting by JT - Fri @ 01:10pm

Re: navigation new window by rogier - Fri @ 01:03pm

Re: navigation new window by rogier - Fri @ 12:53pm

Re: WUC 2009 by JT - Fri @ 12:50pm

Re: Best way to make files available to webgui comunity by preaction - Fri @ 12:35pm

Re: Pagination markup by rogier - Fri @ 12:35pm

Re: Best way to make files available to webgui comunity by kristi - Fri @ 12:29pm

Debian and Ubuntu Packaging Status by jmarsden - Fri @ 12:12pm