Pārlūkot izejas kodu

尝试修复内网登录失败问题

wangjiang988 2 gadi atpakaļ
vecāks
revīzija
1a55baf383

+ 23 - 17
src/main/java/platform/config/shiro/RetryLimitCredentialsMatcher.java

@@ -6,6 +6,7 @@ import org.apache.shiro.authc.ExcessiveAttemptsException;
 import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
 import org.apache.shiro.cache.Cache;
 import org.apache.shiro.cache.CacheManager;
+import platform.modules.sys.shiro.UsernamePasswordToken;
 
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -43,25 +44,30 @@ public class RetryLimitCredentialsMatcher extends HashedCredentialsMatcher {
     @Override
     public boolean doCredentialsMatch(AuthenticationToken token,
                                       AuthenticationInfo info) {
-        String username = (String) token.getPrincipal();
-        Set<String> keys = passwordRetryCache.keys();
 
-        // retry count + 1
-        AtomicInteger retryCount = passwordRetryCache.get(username);
-        if (retryCount == null) {
-            retryCount = new AtomicInteger(0);
-            passwordRetryCache.put(username, retryCount);
-        }
-        if (retryCount.incrementAndGet() > errorPasswordTimes) {
-            // if retry count > 5 throw
-            throw new ExcessiveAttemptsException();
-        }
+        UsernamePasswordToken tk = (UsernamePasswordToken) token;
+        if (tk.getSSO()) {
+            return true;
+        } else {
+            String username = (String) token.getPrincipal();
+
+            // retry count + 1
+            AtomicInteger retryCount = passwordRetryCache.get(username);
+            if (retryCount == null) {
+                retryCount = new AtomicInteger(0);
+                passwordRetryCache.put(username, retryCount);
+            }
+            if (retryCount.incrementAndGet() > errorPasswordTimes) {
+                // if retry count > 5 throw
+                throw new ExcessiveAttemptsException();
+            }
 
-        boolean matches = super.doCredentialsMatch(token, info);
-        if (matches) {
-            // clear retry count
-            passwordRetryCache.remove(username);
+            boolean matches = super.doCredentialsMatch(token, info);
+            if (matches) {
+                // clear retry count
+                passwordRetryCache.remove(username);
+            }
+            return matches;
         }
-        return matches;
     }
 }