You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by llagerlof <ll...@gmail.com> on 2016/09/23 15:02:48 UTC

Can I use both USER and EMAIL as login auth in the query shiro.ini's authenticationQuery parameter?

Hi. I am new to java (but not to programming in general, like php and
javascript).

Let me explain my issue:

I have a web application written in java. The LOGIN, HASHED PASSWORD and
EMAIL are in the database.

Everything is working until now because the user could only access using
LOGIN and PASSWORD. 

This is my authenticationQuery in my shiro.ini:



Now I need to allow the user to login with LOGIN or EMAIL. I tried change
the query to:



But this generate a runtime error on login, because, I think, only the first
"?" on query is set.


I don't know if this helps, but I have a JdbcRealm "CustomJdbcRealm":




Do you have some idea what I could do to achieve my objective? If you need,
I can provide more information about the system.

Thank you.



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Can-I-use-both-USER-and-EMAIL-as-login-auth-in-the-query-shiro-ini-s-authenticationQuery-parameter-tp7581286.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Can I use both USER and EMAIL as login auth in the query shiro.ini's authenticationQuery parameter?

Posted by Brian Demers <br...@gmail.com>.
Great!

If you get a chance, can you send us a pull request? Or post a gist?


On Tue, Sep 27, 2016 at 3:04 PM, llagerlof <ll...@gmail.com> wrote:

> Thank you very much.
>
> Your tips and direct link to the source of JdbcRealm.java pointed me in the
> right direction. I implemented in my CustomJdbcRealm.java:
>
> * doGetAuthenticationInfo
> * buildAuthenticationInfo
> * getPasswordForUser
>
>
> And one modification in shiro.ini. I commented the line:
>
> * jdbcRealm.authenticationQuery
>
> and set the DEFAULT_AUTHENTICATION_QUERY in CustomJdbcRealm.
>
> In the end, I put the ps.setString(2, username) in getPasswordForUser()
>
>
>
>
>
> --
> View this message in context: http://shiro-user.582556.n2.
> nabble.com/Can-I-use-both-USER-and-EMAIL-as-login-auth-
> in-the-query-shiro-ini-s-authenticationQuery-parameter-
> tp7581286p7581298.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: Can I use both USER and EMAIL as login auth in the query shiro.ini's authenticationQuery parameter?

Posted by llagerlof <ll...@gmail.com>.
Thank you very much. 

Your tips and direct link to the source of JdbcRealm.java pointed me in the
right direction. I implemented in my CustomJdbcRealm.java:

* doGetAuthenticationInfo
* buildAuthenticationInfo
* getPasswordForUser


And one modification in shiro.ini. I commented the line:

* jdbcRealm.authenticationQuery

and set the DEFAULT_AUTHENTICATION_QUERY in CustomJdbcRealm.

In the end, I put the ps.setString(2, username) in getPasswordForUser()





--
View this message in context: http://shiro-user.582556.n2.nabble.com/Can-I-use-both-USER-and-EMAIL-as-login-auth-in-the-query-shiro-ini-s-authenticationQuery-parameter-tp7581286p7581298.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Can I use both USER and EMAIL as login auth in the query shiro.ini's authenticationQuery parameter?

Posted by Brian Demers <br...@gmail.com>.
You may need to re implement the 'getPasswordForUser()' method and set an
additional parameter `ps.setString(2, username);`
https://github.com/apache/shiro/blob/1.3.x/core/src/main/java/org/apache/shiro/realm/jdbc/JdbcRealm.java#L281

This is probably something we could add back into the JdbcRealm, as this is
a pretty common technique (it would need to be disabled by default to stay
backwards compatible)  If you are interested, send us a pull request!


On Fri, Sep 23, 2016 at 11:02 AM, llagerlof <ll...@gmail.com> wrote:

> Hi. I am new to java (but not to programming in general, like php and
> javascript).
>
> Let me explain my issue:
>
> I have a web application written in java. The LOGIN, HASHED PASSWORD and
> EMAIL are in the database.
>
> Everything is working until now because the user could only access using
> LOGIN and PASSWORD.
>
> This is my authenticationQuery in my shiro.ini:
>
>
>
> Now I need to allow the user to login with LOGIN or EMAIL. I tried change
> the query to:
>
>
>
> But this generate a runtime error on login, because, I think, only the
> first
> "?" on query is set.
>
>
> I don't know if this helps, but I have a JdbcRealm "CustomJdbcRealm":
>
>
>
>
> Do you have some idea what I could do to achieve my objective? If you need,
> I can provide more information about the system.
>
> Thank you.
>
>
>
> --
> View this message in context: http://shiro-user.582556.n2.
> nabble.com/Can-I-use-both-USER-and-EMAIL-as-login-auth-
> in-the-query-shiro-ini-s-authenticationQuery-parameter-tp7581286.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>