JUser and authentication plugins

74 views
Skip to first unread message

Mitch Pirtle

unread,
Feb 5, 2010, 3:18:47 PM2/5/10
to joomla-...@googlegroups.com
Hi everyone,

When implementing Jetsetter I had to authenticate from a REST service,
and the user's data was returned in the response payload from that
call. I was fine with that until I needed to work with JUser, which
stubbornly refused to look anywhere but the jos_users table instead.

Is there an easy way to get around this, or are we all going to be
forced to stuff copies of user data in jos_users to make JUser happy?

Better yet, is there a plan moving forward to break that dependency so
JUser will respect authentication plugins? Or is there a better
approach?

-- Mitch

Louis Landry

unread,
Feb 5, 2010, 3:30:45 PM2/5/10
to joomla-...@googlegroups.com
You can use JUser::getTable() to replace the JTable class that JUser uses in its storage mechanism.  In a system plugin called "myuser" for example, you can add a JTable include path and have your custom JTable class installed there.  Then you call JUser::getTable() and pass the name of the new class that you want JUser to use.  


// Add the include path for the table object.

JTable::addIncludePath(JPATH_ROOT.'/plugins/system/myuser/table');


// Load the table.

JUser::getTable('MYUser');


This will allow JUser to use your custom class... which could get/set data from any data source I imagine.  That being said, there are several parts of Joomla that join on user_id so you may still need to maintain that data as well.  The need to have data in the users table doesn't really end with JUser.

If you wanna work on a way to separate that out I'd be happy to look at any work you put into it as I'm sure many others would as well.  Feel free to create a branch for it.

- Louis


--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To post to this group, send an email to joomla-...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.




--
Development Coordinator
Joomla! ... because open source matters.
http://www.joomla.org

Mitch Pirtle

unread,
Feb 8, 2010, 12:51:49 PM2/8/10
to joomla-...@googlegroups.com
Thanks for the response Louis. Here's another angle though...

I'm not storing the user in a database. I'm not storing the user at
all in fact - the user is living in a remote store with a RESTful
service. My authentication plugin passes the data, and the return
payload includes the user's information (assuming login was successful
of course).

So there's no table. JTable is my stumbling block it would seem, correct?

-- Mitch

Ian MacLennan

unread,
Feb 8, 2010, 1:10:06 PM2/8/10
to joomla-...@googlegroups.com
Couldn't you override those methods in your subclass so that they behave accordingly?

Ian


-- Mitch

Louis Landry

unread,
Feb 8, 2010, 1:27:20 PM2/8/10
to joomla-...@googlegroups.com
Ian is spot on.  You just have to think outside of the box.  Even with a RESTful service there is the notion of a load/store via GET / POST or PUT requests.  There is validation of data (check() method) .. and binding data to the object.  You could really just look at JTable in your instance as a data access object.  You override 4 methods -- that you would have to provide anyway -- and then you have yourself a JTable object that acts on a RESTful data source and can be used with JUser without any trouble.

/me dusts off hands :-)

- Louis

Mitch Pirtle

unread,
Feb 8, 2010, 2:21:50 PM2/8/10
to joomla-...@googlegroups.com
Pretty lucid explanation for a guy that probably hasn't gone to bed yet. :-)

-- Mitch

Louis Landry

unread,
Feb 8, 2010, 3:06:05 PM2/8/10
to joomla-...@googlegroups.com
Balmer curve ;-)

Sent from my iPhone

Omar Ramos

unread,
Feb 8, 2010, 3:08:01 PM2/8/10
to joomla-...@googlegroups.com
Louis has probably been up partying all night after the Saints won ;-).
Reply all
Reply to author
Forward
0 new messages