LemonLDAPNG / Apache-Session-Browseable

Apache::Session::Browseable Perl module
http://search.cpan.org/dist/Apache-Session-Browseable/
Other
3 stars 5 forks source link

LemonLDAP session browser is empty with Browseable::Postgres when all fields are indexed #17

Closed maxbes closed 5 years ago

maxbes commented 5 years ago

When using searchOn or searchOnExpr with a fields parameter, there are two possibilities:

SQL query:

SELECT id,a_session from sessions where _session_kind=?

Result, slow but display correctly in the manager

 'a05d5aac84aefa31de73c64c17e7045b931617b587b40cf67cf30b52fa280a04' => {
     '_whatToTrace' => 'abarnes',
     '_httpSessionType' => undef,
     '_session_kind' => 'SSO',
     'ipAddr' => '10.128.239.1'
 },
SELECT id,_httpSessionType,ipAddr,_whatToTrace,_session_kind from sessions where _session_kind=?

Result, fast because there is no need to deserialized, but doesn't get displayed in the manager

'a05d5aac84aefa31de73c64c17e7045b931617b587b40cf67cf30b52fa280a04' => {
    '_httpsessiontype' => undef,
    '_session_kind' => 'SSO',
    'id' => 'a05d5aac84aefa31de73c64c17e7045b931617b587b40cf67cf30b52fa280a04',
    '_whattotrace' => 'abarnes',
    'ipaddr' => '10.128.239.1'
}

Since the fields are returned in lowercase, LLNG will not be able to do a groupBy on them, and the sessions won't display in the manager at all.

My suggestion is to implement the same fix as PgJson and PgHstore are already doing, by overloading searchOn and searchOnExpr in Browseable/Postgres.pm :

sub searchOn {
    my $class = shift;
    my ( $args, $selectField, $value, @fields ) = @_;
    my $res = $class->SUPER::searchOn(@_);
    foreach (@fields) {
        if ( $_ ne lc($_) ) {
            foreach my $s ( keys %$res ) {
                $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ };
            }
        }
    }
    return $res;
}

sub searchOnExpr {
    my $class = shift;
    my ( $args, $selectField, $value, @fields ) = @_;
    my $res = $class->SUPER::searchOnExpr(@_);
    foreach (@fields) {
        if ( $_ ne lc($_) ) {
            foreach my $s ( keys %$res ) {
                $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ };
            }
        }
    }
    return $res;
}

Another possible fix is this little trick:

SELECT ipAddr as "ipAddr" , .... from sessions where ....

which would require completely overloading the _query function, so maybe it's not worth it.

guimard commented 5 years ago

@maxbes: hello, OK, would you push a MR with this fix ?

guimard commented 5 years ago

Included in version 1.3.1