Hi Peter, > I am trying to add a custom authentication method in additional to the > Google accounts. > After searching around the web I found Shiro and I want to try it out.
Very cool! I hope you find the answers you're looking for on this list. > I just checked out the source with SVN and built with Maven and able to run > the Quickstart program. > However I am not sure where should I go next, seems like there are couple > paths I can take but there's little documentation about them. > > Here are my questions: > > 1. With a servlet environment, I should use the filter approach right? Yep, this is the way to go. > 2. Seems like I need to build my custom Realm to store credentials to > Google's datastore "bigtable". How do I define, config a custom Realm to be > used? What are the methods that I should customize? Yep, you would need a custom Realm to do this. Once you've created it, you can specify it in the ShiroFilter's 'config' init-param: [main] googleRealm = com.company.shiro.GoogleRealm gogoleRealm.property1 = someValue googleRealm.property2 = anotherValue etc... Shiro picks up any realms defined in this section and automatically enables them in the Shiro SecurityManager that will be used to 'talk' to the Realms at runtime. You store data in Google however you like - only the Realm implementation needs to know how to look up data using Google's APIs. If you subclass the AuthorizingRealm, you can override the 'doGetAuthenticationInfo' method to do this and return that data in the form of an AuthenticationInfo instance. > 3. Also, seems like I need to build my custom "CachingRealm" to use Google's > memcache. How do I define, config a caching realm to be used? You will need to implement the org.apache.shiro.cache.CacheManager interface to talk to Google's cache mechanism. Then you need to tell the SecurityManager about this CacheManager instance so it can be used at runtime: [main] cacheManager = com.company.pkg.shiro.GoogleCacheManager #set any other properties here as necessary. #cacheManager.property1 = value #cacheManager.property2 = $reference #etc. #Now set it on the security manager by using # an object reference ($ marker): securityManager.cacheManager = $cacheManager # define your realms here, they will be picked # up automatically and given to the SecurityManager # no need to set them on the securityManager directly: myRealm = com.company.pkg.shiro.BigtableRealm Almost all of the Shiro Realms are cache-enabled by default - you just need to configure the CacheManager on the SecurityManager as shown above. If you subclass the AuthenticatingRealm or AuthorizingRealm class depending on your needs, the SecurityManager will automatically provide the Realm instance with the CacheManager that was configured. I hope that helps! Cheers, Les
