MyModularRealmAuthenticator.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.izouma.awesomeadmin.shiro;
  2. import org.apache.log4j.Logger;
  3. import org.apache.shiro.authc.AuthenticationInfo;
  4. import org.apache.shiro.authc.AuthenticationToken;
  5. import org.apache.shiro.authc.pam.AuthenticationStrategy;
  6. import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
  7. import org.apache.shiro.realm.Realm;
  8. import java.util.Collection;
  9. import java.util.Iterator;
  10. public class MyModularRealmAuthenticator extends ModularRealmAuthenticator {
  11. protected static Logger logger = Logger.getLogger(MyModularRealmAuthenticator.class);
  12. protected AuthenticationInfo doMultiRealmAuthentication(Collection<Realm> realms, AuthenticationToken token) {
  13. AuthenticationStrategy strategy = this.getAuthenticationStrategy();
  14. AuthenticationInfo aggregate = strategy.beforeAllAttempts(realms, token);
  15. Iterator var5 = realms.iterator();
  16. while (var5.hasNext()) {
  17. Realm realm = (Realm) var5.next();
  18. aggregate = strategy.beforeAttempt(realm, token, aggregate);
  19. if (realm.supports(token)) {
  20. logger.trace("Attempting to authenticate token [{}] using realm [{}]");
  21. AuthenticationInfo info = null;
  22. Throwable t = null;
  23. info = realm.getAuthenticationInfo(token);
  24. aggregate = strategy.afterAttempt(realm, token, info, aggregate, t);
  25. } else {
  26. logger.debug("Realm [{}] does not support token {}. Skipping realm.");
  27. }
  28. }
  29. aggregate = strategy.afterAllAttempts(token, aggregate);
  30. return aggregate;
  31. }
  32. }