You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by "bytor99999@gmail.com" <by...@gmail.com> on 2014/02/14 03:12:09 UTC

Two login types. User/Password and Guest/fingerprint

So in our application (REST)  we have the standard users with logging in via username/password. However, we also have a login as guest. However, guest users are still full users in our system. When a user signs in as guest for the first time a request is sent with just a FingerPrint, this is a HASH sent from the client to the REST api. To determine that this is the first time this fingerprint/deviceID has been sent I do a db lookup WHERE db.fingerPrint = loginRequest.fingerPrint. 

If it doesn’t return a record then that means it is a new guest and we create a User instance and store it in the db. We generate a username GuestNNN and generate a password for them, which we never send to them. If it does return, then we take the userName from the db and the passed in signature and create a SignatureAuthenticationToken, which just extends UsernamePasswordAuthenticationToken and the constructor we pass in username and fingerprint String. This works when we encrypt the fingerPrint with PasswordService and store it encrypted.

However, this does not work then on subsequent logins by that guest, because in order to get the userName I have to query the db using the same WHERE clause
WHERE db.fingerPrint = loginRequest.fingerPrint

It fails because the incoming login request has the fingerPrint unencrypted and the where clause will never match what is in the db, because the db has it stored encrypted. 

If I try to just store the fingerprint in the db unencrypted, then the login will fail because we are using PasswordMatcher with DefaultHashService which will always take the fingerprint and encrypt it and compare it to what is in the db, which is now unencrypted. So I am sort of damned if I do, damned if I don’t.

The login as guest request will always just have the fingerPrint, the client will never know or send us the userName because it doesn’t know it.

We can’t use rememberMe as unauthenticated user as guest because we need to make them an actual user with data stored in the database that on subsequent logins keeps their information etc.

Any ideas?

Thanks

Mark


Re: Two login types. User/Password and Guest/fingerprint

Posted by Mark Spritzler <by...@gmail.com>.
For some reason I just had to change the order of the Realms in the realms
property in my xml configuration. Now everything works perfectly. Having
two different Realms where each accept different types of Tokens was the
perfect way to go.

Mark


On Sat, Feb 15, 2014 at 9:48 PM, bytor99999@gmail.com
<by...@gmail.com>wrote:

> I created two Realms and added them to the realms property of Default Web
> security manager
>
>     <bean id="securityManager"
> class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
>         <!-- Single realm app.  If you have multiple realms, use the
> 'realms' property instead. -->
>         <!--<property name="realm" ref="hdPokerRealm"/>-->
>         <property name="realms">
>             <list>
>                 <ref bean="hdRealm"/>
>                 <ref bean="hdFingerprintRealm"/>
>             </list>
>         </property>
>         <!--<property name="cacheManager" ref="cacheManager"/>-->
>         <property name="sessionManager" ref="sessionManager"/>
>     </bean>
>
> In hdRealm we have
>
>   @Override
>   public boolean supports(AuthenticationToken authenticationToken) {
>     return (authenticationToken instanceof UsernamePasswordToken)
>   }
>
> In hdFingerPrintrealm we have
>
>   @Override
>   public boolean supports(AuthenticationToken authenticationToken) {
>     return (authenticationToken instanceof FingerPrintAuthenticationToken)
>   }
>
> In which FingerPrintAuthenticationToken is a custom token we created
>
> But we get the following error.
>
> 2014-02-15 21:32:39,704 ERROR c.h.a.controller.LoginController  - Error
> testing credentials
> org.apache.shiro.authc.AuthenticationException: Authentication token of
> type [class org.apache.shiro.authc.UsernamePasswordToken] could not be
> authenticated by any configured realms.  Please ensure that at least one
> realm can authenticate these tokens.
> at
> org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy.afterAllAttempts(AtLeastOneSuccessfulStrategy.java:54)
> ~[shiro-core-1.2.1.jar:1.2.1]
> at
> org.apache.shiro.authc.pam.ModularRealmAuthenticator.doMultiRealmAuthentication(ModularRealmAuthenticator.java:235)
> ~[shiro-core-1.2.1.jar:1.2.1]
> at
> org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:269)
> ~[shiro-core-1.2.1.jar:1.2.1]
> at
> org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
> ~[shiro-core-1.2.1.jar:1.2.1]
>
>
> What could we be missing?
>
> Thanks
>
> Mark Spritzler
>
>
> On Feb 14, 2014, at 1:40 AM, Dominic Farr <do...@gmail.com> wrote:
>
> This line.
> ... generate a password for them, which we never send to them.
>
> This is the start of your design problem.
>
> You generate a password which the user never knows.
>
> When the user returns your system expects the user to know the unknown
> password.
>
> No amount of software will solve this problem.
>
> What is the password protecting? If the DeviceID is globally unique
> perhaps you don't need a password, the Device itself can act as a password.
>
>
> On 14 February 2014 02:12, bytor99999@gmail.com <by...@gmail.com>wrote:
>
>> So in our application (REST)  we have the standard users with logging in
>> via username/password. However, we also have a login as guest. However,
>> guest users are still full users in our system. When a user signs in as
>> guest for the first time a request is sent with just a FingerPrint, this is
>> a HASH sent from the client to the REST api. To determine that this is the
>> first time this fingerprint/deviceID has been sent I do a db lookup WHERE
>> db.fingerPrint = loginRequest.fingerPrint.
>>
>> If it doesn't return a record then that means it is a new guest and we
>> create a User instance and store it in the db. We generate a username
>> GuestNNN and generate a password for them, which we never send to them. If
>> it does return, then we take the userName from the db and the passed in
>> signature and create a SignatureAuthenticationToken, which just extends
>> UsernamePasswordAuthenticationToken and the constructor we pass in username
>> and fingerprint String. This works when we encrypt the fingerPrint with
>> PasswordService and store it encrypted.
>>
>> However, this does not work then on subsequent logins by that guest,
>> because in order to get the userName I have to query the db using the same
>> WHERE clause
>> WHERE db.fingerPrint = loginRequest.fingerPrint
>>
>> It fails because the incoming login request has the fingerPrint
>> unencrypted and the where clause will never match what is in the db,
>> because the db has it stored encrypted.
>>
>> If I try to just store the fingerprint in the db unencrypted, then the
>> login will fail because we are using PasswordMatcher with
>> DefaultHashService which will always take the fingerprint and encrypt it
>> and compare it to what is in the db, which is now unencrypted. So I am sort
>> of damned if I do, damned if I don't.
>>
>> The login as guest request will always just have the fingerPrint, the
>> client will never know or send us the userName because it doesn't know it.
>>
>> We can't use rememberMe as unauthenticated user as guest because we need
>> to make them an actual user with data stored in the database that on
>> subsequent logins keeps their information etc.
>>
>> Any ideas?
>>
>> Thanks
>>
>> Mark
>>
>>
>
>

Re: Two login types. User/Password and Guest/fingerprint

Posted by "bytor99999@gmail.com" <by...@gmail.com>.
I created two Realms and added them to the realms property of Default Web security manager

    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <!-- Single realm app.  If you have multiple realms, use the 'realms' property instead. -->
        <!--<property name="realm" ref="hdPokerRealm"/>-->
        <property name="realms">
            <list>
                <ref bean="hdRealm"/>
                <ref bean="hdFingerprintRealm"/>
            </list>
        </property>
        <!--<property name="cacheManager" ref="cacheManager"/>-->
        <property name="sessionManager" ref="sessionManager"/>
    </bean>

In hdRealm we have

  @Override
  public boolean supports(AuthenticationToken authenticationToken) {
    return (authenticationToken instanceof UsernamePasswordToken)
  }

In hdFingerPrintrealm we have

  @Override
  public boolean supports(AuthenticationToken authenticationToken) {
    return (authenticationToken instanceof FingerPrintAuthenticationToken)
  }

In which FingerPrintAuthenticationToken is a custom token we created

But we get the following error. 

2014-02-15 21:32:39,704 ERROR c.h.a.controller.LoginController  - Error testing credentials
org.apache.shiro.authc.AuthenticationException: Authentication token of type [class org.apache.shiro.authc.UsernamePasswordToken] could not be authenticated by any configured realms.  Please ensure that at least one realm can authenticate these tokens.
	at org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy.afterAllAttempts(AtLeastOneSuccessfulStrategy.java:54) ~[shiro-core-1.2.1.jar:1.2.1]
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doMultiRealmAuthentication(ModularRealmAuthenticator.java:235) ~[shiro-core-1.2.1.jar:1.2.1]
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:269) ~[shiro-core-1.2.1.jar:1.2.1]
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198) ~[shiro-core-1.2.1.jar:1.2.1]


What could we be missing?

Thanks

Mark Spritzler


On Feb 14, 2014, at 1:40 AM, Dominic Farr <do...@gmail.com> wrote:

> This line.
> ... generate a password for them, which we never send to them.
> 
> This is the start of your design problem. 
> 
> You generate a password which the user never knows. 
> 
> When the user returns your system expects the user to know the unknown password.
> 
> No amount of software will solve this problem.
> 
> What is the password protecting? If the DeviceID is globally unique perhaps you don't need a password, the Device itself can act as a password. 
> 
> 
> On 14 February 2014 02:12, bytor99999@gmail.com <by...@gmail.com> wrote:
> So in our application (REST)  we have the standard users with logging in via username/password. However, we also have a login as guest. However, guest users are still full users in our system. When a user signs in as guest for the first time a request is sent with just a FingerPrint, this is a HASH sent from the client to the REST api. To determine that this is the first time this fingerprint/deviceID has been sent I do a db lookup WHERE db.fingerPrint = loginRequest.fingerPrint.
> 
> If it doesn’t return a record then that means it is a new guest and we create a User instance and store it in the db. We generate a username GuestNNN and generate a password for them, which we never send to them. If it does return, then we take the userName from the db and the passed in signature and create a SignatureAuthenticationToken, which just extends UsernamePasswordAuthenticationToken and the constructor we pass in username and fingerprint String. This works when we encrypt the fingerPrint with PasswordService and store it encrypted.
> 
> However, this does not work then on subsequent logins by that guest, because in order to get the userName I have to query the db using the same WHERE clause
> WHERE db.fingerPrint = loginRequest.fingerPrint
> 
> It fails because the incoming login request has the fingerPrint unencrypted and the where clause will never match what is in the db, because the db has it stored encrypted.
> 
> If I try to just store the fingerprint in the db unencrypted, then the login will fail because we are using PasswordMatcher with DefaultHashService which will always take the fingerprint and encrypt it and compare it to what is in the db, which is now unencrypted. So I am sort of damned if I do, damned if I don’t.
> 
> The login as guest request will always just have the fingerPrint, the client will never know or send us the userName because it doesn’t know it.
> 
> We can’t use rememberMe as unauthenticated user as guest because we need to make them an actual user with data stored in the database that on subsequent logins keeps their information etc.
> 
> Any ideas?
> 
> Thanks
> 
> Mark
> 
> 


Re: Two login types. User/Password and Guest/fingerprint

Posted by "bytor99999@gmail.com" <by...@gmail.com>.
Hey Dominic, thanks for your response. I really appreciate it.

"When the user returns your system expects the user to know the unknown password.”

I guess I didn’t explain it well, sorry. In the login as guest, the user never needs to enter the password or know it. There is no textfields for them to enter it anyway in that scenario on the Mobile App, just a button. So…

"If the DeviceID is globally unique perhaps you don't need a password, the Device itself can act as a password.”

Exactly, in login as guest the deviceID is unique will act as the password. I generate a password because the password field is Not nullable in the Database. ;)

Also, the deviceID acting as the password in this scenario is the catch-22. Since that will be the only piece of data coming into the request and we are using PasswordMatcher, because we also have to support a “real” user that registers and when real users login, they do enter their one created username/password. (This sentence only makes sense in my head, sorry)

It is the combination of real users and login as guest use cases with only being able to use one Matcher with one PasswordService with one HashService for our Realm. Hmmm as I say that, maybe that is my solution, make two different Realms, one for real users and one for login as guest, then for real users use the PasswordMatcher and for login as guest use SimpleCredentialsMatcher.

See you helped me out tremendously, Thanks

Mark

On Feb 14, 2014, at 1:40 AM, Dominic Farr <do...@gmail.com> wrote:

> This line.
> ... generate a password for them, which we never send to them.
> 
> This is the start of your design problem. 
> 
> You generate a password which the user never knows. 
> 
> When the user returns your system expects the user to know the unknown password.
> 
> No amount of software will solve this problem.
> 
> What is the password protecting? If the DeviceID is globally unique perhaps you don't need a password, the Device itself can act as a password. 
> 
> 
> On 14 February 2014 02:12, bytor99999@gmail.com <by...@gmail.com> wrote:
> So in our application (REST)  we have the standard users with logging in via username/password. However, we also have a login as guest. However, guest users are still full users in our system. When a user signs in as guest for the first time a request is sent with just a FingerPrint, this is a HASH sent from the client to the REST api. To determine that this is the first time this fingerprint/deviceID has been sent I do a db lookup WHERE db.fingerPrint = loginRequest.fingerPrint.
> 
> If it doesn’t return a record then that means it is a new guest and we create a User instance and store it in the db. We generate a username GuestNNN and generate a password for them, which we never send to them. If it does return, then we take the userName from the db and the passed in signature and create a SignatureAuthenticationToken, which just extends UsernamePasswordAuthenticationToken and the constructor we pass in username and fingerprint String. This works when we encrypt the fingerPrint with PasswordService and store it encrypted.
> 
> However, this does not work then on subsequent logins by that guest, because in order to get the userName I have to query the db using the same WHERE clause
> WHERE db.fingerPrint = loginRequest.fingerPrint
> 
> It fails because the incoming login request has the fingerPrint unencrypted and the where clause will never match what is in the db, because the db has it stored encrypted.
> 
> If I try to just store the fingerprint in the db unencrypted, then the login will fail because we are using PasswordMatcher with DefaultHashService which will always take the fingerprint and encrypt it and compare it to what is in the db, which is now unencrypted. So I am sort of damned if I do, damned if I don’t.
> 
> The login as guest request will always just have the fingerPrint, the client will never know or send us the userName because it doesn’t know it.
> 
> We can’t use rememberMe as unauthenticated user as guest because we need to make them an actual user with data stored in the database that on subsequent logins keeps their information etc.
> 
> Any ideas?
> 
> Thanks
> 
> Mark
> 
> 


Re: Two login types. User/Password and Guest/fingerprint

Posted by Dominic Farr <do...@gmail.com>.
This line.
... generate a password for them, which we never send to them.

This is the start of your design problem.

You generate a password which the user never knows.

When the user returns your system expects the user to know the unknown
password.

No amount of software will solve this problem.

What is the password protecting? If the DeviceID is globally unique perhaps
you don't need a password, the Device itself can act as a password.


On 14 February 2014 02:12, bytor99999@gmail.com <by...@gmail.com>wrote:

> So in our application (REST)  we have the standard users with logging in
> via username/password. However, we also have a login as guest. However,
> guest users are still full users in our system. When a user signs in as
> guest for the first time a request is sent with just a FingerPrint, this is
> a HASH sent from the client to the REST api. To determine that this is the
> first time this fingerprint/deviceID has been sent I do a db lookup WHERE
> db.fingerPrint = loginRequest.fingerPrint.
>
> If it doesn’t return a record then that means it is a new guest and we
> create a User instance and store it in the db. We generate a username
> GuestNNN and generate a password for them, which we never send to them. If
> it does return, then we take the userName from the db and the passed in
> signature and create a SignatureAuthenticationToken, which just extends
> UsernamePasswordAuthenticationToken and the constructor we pass in username
> and fingerprint String. This works when we encrypt the fingerPrint with
> PasswordService and store it encrypted.
>
> However, this does not work then on subsequent logins by that guest,
> because in order to get the userName I have to query the db using the same
> WHERE clause
> WHERE db.fingerPrint = loginRequest.fingerPrint
>
> It fails because the incoming login request has the fingerPrint
> unencrypted and the where clause will never match what is in the db,
> because the db has it stored encrypted.
>
> If I try to just store the fingerprint in the db unencrypted, then the
> login will fail because we are using PasswordMatcher with
> DefaultHashService which will always take the fingerprint and encrypt it
> and compare it to what is in the db, which is now unencrypted. So I am sort
> of damned if I do, damned if I don’t.
>
> The login as guest request will always just have the fingerPrint, the
> client will never know or send us the userName because it doesn’t know it.
>
> We can’t use rememberMe as unauthenticated user as guest because we need
> to make them an actual user with data stored in the database that on
> subsequent logins keeps their information etc.
>
> Any ideas?
>
> Thanks
>
> Mark
>
>