You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Charles Syperski <cs...@dupage88.net> on 2012/03/08 18:34:48 UTC

JdbcRealm authenticationQuery with mutliple user fields

I have a table that I am trying to authenticate against using a 
JdbcRealm that has multiple fields that the user can use for their 
username can anyone tell me if this is possible?

I basically want the user to be able to login using their username, 
alias or email address.

jdbcRealm.authenticationQuery = SELECT password FROM users WHERE 
(username = ? or userAlias = ? or emailAddress = ?) and accountStatus = '1'

Thanks in advance

Re: JdbcRealm authenticationQuery with mutliple user fields

Posted by Paulo Pires <pj...@ubiwhere.com>.
Les,

I had the same issue as Charles and I found it would be easier to extend
JdbcRealm for this use-case if at least JdbcRealm.getPasswordForUser() was
to be protected.

If this was the case, all one has to do is:
1) extends JdbcRealm
2) @Override getPasswordForUser()
2.1) Hack as follows:
ps.setString(1, username);
ps.setString(2, username);
...
ps.setString(n, username);

Probably the username parameter should be renamed for something like
(param1) or something, for better readibility in this case. But this way,
one could use the same parameter for all OR statements in WHERE clause.

Just my 2c,
PP



--
View this message in context: http://shiro-user.582556.n2.nabble.com/JdbcRealm-authenticationQuery-with-mutliple-user-fields-tp7355682p7578338.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: JdbcRealm authenticationQuery with mutliple user fields

Posted by Les Hazlewood <lh...@apache.org>.
Hi Charles,

The existing JdbcRealm is not too flexible for this type of
customization.  Your best bet is to probably look at the existing
source code [1], and override doGetAuthenticationInfo to work with
your particular query.

HTH,

Les

[1] http://svn.apache.org/repos/asf/shiro/trunk/core/src/main/java/org/apache/shiro/realm/jdbc/JdbcRealm.java

On Thu, Mar 8, 2012 at 9:34 AM, Charles Syperski <cs...@dupage88.net> wrote:
> I have a table that I am trying to authenticate against using a JdbcRealm
> that has multiple fields that the user can use for their username can anyone
> tell me if this is possible?
>
> I basically want the user to be able to login using their username, alias or
> email address.
>
> jdbcRealm.authenticationQuery = SELECT password FROM users WHERE (username =
> ? or userAlias = ? or emailAddress = ?) and accountStatus = '1'
>
> Thanks in advance