You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by gruntbug <br...@gmail.com> on 2013/08/08 23:15:01 UTC
fake authentication in Shiro with test password
I just got ActiveDirectory in Shiro working (YAY!). In non-production
testing, we want to be able to test our app (login) as any user without
knowing the users password. In a previous (non-shiro) app I worked on, when
not in production, the password of "test" would let us in. I'm trying to
figure out how I can do something similar with Shiro.
Right now the code looks like this:
---------------------
Subject currentUser = SecurityUtils.getSubject();
if ( !currentUser.isAuthenticated() ) {
UsernamePasswordToken token = new UsernamePasswordToken(userWithDomain,
password);
token.setRememberMe(true);
try {
currentUser.login(token);
} catch (AuthenticationException e) {
e.printStackTrace();
throw e;
}
}
System.out.println("authenticated: "+currentUser.isAuthenticated());
---------------------
But I want is something like:
---------------------
Subject currentUser = SecurityUtils.getSubject();
if ( !currentUser.isAuthenticated()) {
if (!inProduction && !"test".equals(password)) { {
//"fake" authenticate user
currentUser.setIsAuthenticated(username)
} else {
UsernamePasswordToken token = new
UsernamePasswordToken(userWithDomain, password);
token.setRememberMe(true);
try {
currentUser.login(token);
} catch (AuthenticationException e) {
e.printStackTrace();
throw e;
}
}
}
System.out.println("authenticated: "+currentUser.isAuthenticated());
---------------------
Any ideas on how I can accomplish this? Should I create a fake Realm that
authenticates only if password is "test" and if not, it uses the actual AD
realm? if so, how can I set this up in my shiro.ini? Do I need to
essentially create my own realm (extend a base class) and implement it?
Thanks,
Brian
--
View this message in context: http://shiro-user.582556.n2.nabble.com/fake-authentication-in-Shiro-with-test-password-tp7579014.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: fake authentication in Shiro with test password
Posted by Stuart Broad <st...@moogsoft.com>.
If you really want to check the password is test you can do:
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
String username = upToken.getUsername();
String password = new String(upToken.getPassword());
On Fri, Aug 9, 2013 at 2:37 PM, Stuart Broad <st...@moogsoft.com> wrote:
> Hi,
>
> I created a realm that was a subclass of AuthorizingRealm (I think it
> would be just as easy to subclass AuthenticatingRealm). Then write the
> methods:
>
> AuthenticationInfo doGetAuthenticationInfo(AuthentiationToken)
>
> Then for any authentication token (since you will authenticate anyone in
> development) just return something like:
>
> return new SimpleAuthenticationInfo(username, password, getName());
>
> If you wanted to fail the authentication then you can just return null.
>
> Cheers,
>
> Stuart
>
>
> On Fri, Aug 9, 2013 at 2:22 PM, gruntbug <br...@gmail.com> wrote:
>
>> Replying to myself... in thinking about this a little more, I think what
>> makes more sense is to have a production realm configured in shiro.ini
>> that
>> does the AD authentication, then for testing and development, we have a
>> shiro-dev.ini that defines a realm that authenticates anyone that logs in
>> with the password of test (or, more generically, uses some other realm).
>> So,
>> my question is still similar - how do I setup a realm that will
>> authenticate
>> arbitrarily via code/algorithm I write? Is there one already in Shiro I
>> can
>> use or should I extend one of the built-in classes and override a
>> method(s)
>> to make it work like that?
>>
>> Looks like I should just extend AuthorizingRealm and create a
>> TestAuthorizingRealm from it?
>>
>>
>>
>> --
>> View this message in context:
>> http://shiro-user.582556.n2.nabble.com/fake-authentication-in-Shiro-with-test-password-tp7579014p7579019.html
>> Sent from the Shiro User mailing list archive at Nabble.com.
>>
>
>
Re: fake authentication in Shiro with test password
Posted by Stuart Broad <st...@moogsoft.com>.
Hi,
I created a realm that was a subclass of AuthorizingRealm (I think it would
be just as easy to subclass AuthenticatingRealm). Then write the methods:
AuthenticationInfo doGetAuthenticationInfo(AuthentiationToken)
Then for any authentication token (since you will authenticate anyone in
development) just return something like:
return new SimpleAuthenticationInfo(username, password, getName());
If you wanted to fail the authentication then you can just return null.
Cheers,
Stuart
On Fri, Aug 9, 2013 at 2:22 PM, gruntbug <br...@gmail.com> wrote:
> Replying to myself... in thinking about this a little more, I think what
> makes more sense is to have a production realm configured in shiro.ini that
> does the AD authentication, then for testing and development, we have a
> shiro-dev.ini that defines a realm that authenticates anyone that logs in
> with the password of test (or, more generically, uses some other realm).
> So,
> my question is still similar - how do I setup a realm that will
> authenticate
> arbitrarily via code/algorithm I write? Is there one already in Shiro I can
> use or should I extend one of the built-in classes and override a
> method(s)
> to make it work like that?
>
> Looks like I should just extend AuthorizingRealm and create a
> TestAuthorizingRealm from it?
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/fake-authentication-in-Shiro-with-test-password-tp7579014p7579019.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>
Re: fake authentication in Shiro with test password
Posted by gruntbug <br...@gmail.com>.
Replying to myself... in thinking about this a little more, I think what
makes more sense is to have a production realm configured in shiro.ini that
does the AD authentication, then for testing and development, we have a
shiro-dev.ini that defines a realm that authenticates anyone that logs in
with the password of test (or, more generically, uses some other realm). So,
my question is still similar - how do I setup a realm that will authenticate
arbitrarily via code/algorithm I write? Is there one already in Shiro I can
use or should I extend one of the built-in classes and override a method(s)
to make it work like that?
Looks like I should just extend AuthorizingRealm and create a
TestAuthorizingRealm from it?
--
View this message in context: http://shiro-user.582556.n2.nabble.com/fake-authentication-in-Shiro-with-test-password-tp7579014p7579019.html
Sent from the Shiro User mailing list archive at Nabble.com.