You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Olivia <ol...@gmail.com> on 2012/07/25 11:18:37 UTC

Custom Realm

Hi, everybody!

I've posted this problem before but I am not sure it could be viewed by
others so i decided to do it one more time and be more specific.. This
problem is killing me. )

Well, I've wrote my own realm. Lets call it MyRealm, package com.company. I
extended it from JdbcRealm and added NO new methods. Btw, JdbcRealm works
perfectly. Of course I need more functionality but it even doesn't work in
this case.

So I added info about MyRealm to shiro.ini.

myRealm= com.company.MyRealm 
securityManager.realms = $myRealm

and started debugging..

In ModularRealmAuthenticator in shiro there is a method 


 protected AuthenticationInfo doAuthenticate(AuthenticationToken
authenticationToken) throws AuthenticationException {
        assertRealmsConfigured();
        Collection<Realm> realms = getRealms();
        if (realms.size() == 1) {
            return doSingleRealmAuthentication(realms.iterator().next(),
authenticationToken);
        } else {
            return doMultiRealmAuthentication(realms, authenticationToken);
        }
    }

Well, i have no issues with casting to Collection<Realm>. variable realm
contains one my realm. But the method doSingleRealmAuthentication gives me
the cast exception error.. Like myRealm cannot be cast to shiro's interface
Realm.

Can you give me any tips? Thanks in advance!!




--
View this message in context: http://shiro-user.582556.n2.nabble.com/Custom-Realm-tp7577630.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Custom Realm

Posted by Olivia <ol...@gmail.com>.
Well, as i've said the JdbcRealm works fine. And the same MyRealm doesn't.
The only difference is that MyRealm is in another package..



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Custom-Realm-tp7577630p7577634.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Custom Realm

Posted by wami99 <wa...@googlemail.com>.
I do not know your exact problem, but in case you have not given some more
parameter to JdbcRealm, here is an example:
[main] 
# realms to be used
#saltedJdbcRealm = com.jbosol.security.dao.MySimpleAccountRealm
saltedJdbcRealm = com.jbosol.security.dao.JndiAndSaltAwareJdbcRealm
#
# any object property is automatically configurable in Shiro.ini file
saltedJdbcRealm.jndiDataSourceName=java:comp/env/jdbc/Security
#
# the realm should handle also authorization
saltedJdbcRealm.permissionsLookupEnabled=true
#
# If not filled, subclasses of JdbcRealm assume "select password from users
where username = ?"
# first result column is password, second result column is salt 
saltedJdbcRealm.authenticationQuery = select u.passwd , s.salt from user u,
salt s where user = ?

# password hashing specification, put something big for hashIterations
sha256Matcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
sha256Matcher.hashAlgorithmName=SHA-256
sha256Matcher.hashIterations=1024
#Bas64 encoded : hex -> Character
sha256Matcher.storedCredentialsHexEncoded=false;
saltedJdbcRealm.credentialsMatcher = $sha256Matcher

Can you explain in more details, if this couldn't help you.

Walter






--
View this message in context: http://shiro-user.582556.n2.nabble.com/Custom-Realm-tp7577630p7577633.html
Sent from the Shiro User mailing list archive at Nabble.com.