package com.l7tech.server.identity;

import com.l7tech.identity.AuthenticationException;
import com.l7tech.identity.PersistentGroup;
import com.l7tech.identity.PersistentUser;
import com.l7tech.identity.ValidationException;
import com.l7tech.identity.cert.CertEntryRow;
import com.l7tech.identity.cert.ClientCertManager;
import com.l7tech.objectmodel.EntityHeaderSet;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.IdentityHeader;
import com.l7tech.policy.assertion.credential.LoginCredentials;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import java.util.List;
import javax.security.auth.x500.X500Principal;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public abstract class PersistentIdentityProviderImpl<UT extends PersistentUser, GT extends PersistentGroup, UMT extends PersistentUserManager<UT>, GMT extends PersistentGroupManager<UT, GT>>
   implements ApplicationContextAware,
   InitializingBean,
   PersistentIdentityProvider<UT, GT, UMT, GMT> {
   protected ApplicationContext applicationContext;
   protected ClientCertManager clientCertManager;
   private static final String[] m;

   public EntityHeaderSet<IdentityHeader> search(EntityType[] param1, String param2) throws FindException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 1
      // 01: ifnull 11
      // 04: aload 1
      // 05: arraylength
      // 06: bipush 1
      // 07: if_icmpge 22
      // 0a: goto 11
      // 0d: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 10: athrow
      // 11: new java/lang/IllegalArgumentException
      // 14: dup
      // 15: getstatic com/l7tech/server/identity/PersistentIdentityProviderImpl.m [Ljava/lang/String;
      // 18: bipush 1
      // 19: aaload
      // 1a: invokespecial java/lang/IllegalArgumentException.<init> (Ljava/lang/String;)V
      // 1d: athrow
      // 1e: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 21: athrow
      // 22: bipush 0
      // 23: istore 3
      // 24: bipush 0
      // 25: istore 4
      // 27: aload 1
      // 28: astore 5
      // 2a: aload 5
      // 2c: arraylength
      // 2d: istore 6
      // 2f: bipush 0
      // 30: istore 7
      // 32: iload 7
      // 34: iload 6
      // 36: if_icmpge 5e
      // 39: aload 5
      // 3b: iload 7
      // 3d: aaload
      // 3e: astore 8
      // 40: aload 8
      // 42: getstatic com/l7tech/objectmodel/EntityType.USER Lcom/l7tech/objectmodel/EntityType;
      // 45: if_acmpne 4d
      // 48: bipush 1
      // 49: istore 3
      // 4a: goto 58
      // 4d: aload 8
      // 4f: getstatic com/l7tech/objectmodel/EntityType.GROUP Lcom/l7tech/objectmodel/EntityType;
      // 52: if_acmpne 58
      // 55: bipush 1
      // 56: istore 4
      // 58: iinc 7 1
      // 5b: goto 32
      // 5e: iload 3
      // 5f: ifne 7f
      // 62: iload 4
      // 64: ifne 7f
      // 67: goto 6e
      // 6a: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 6d: athrow
      // 6e: new java/lang/IllegalArgumentException
      // 71: dup
      // 72: getstatic com/l7tech/server/identity/PersistentIdentityProviderImpl.m [Ljava/lang/String;
      // 75: bipush 2
      // 76: aaload
      // 77: invokespecial java/lang/IllegalArgumentException.<init> (Ljava/lang/String;)V
      // 7a: athrow
      // 7b: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 7e: athrow
      // 7f: new com/l7tech/objectmodel/EntityHeaderSet
      // 82: dup
      // 83: new java/util/TreeSet
      // 86: dup
      // 87: invokespecial java/util/TreeSet.<init> ()V
      // 8a: invokespecial com/l7tech/objectmodel/EntityHeaderSet.<init> (Ljava/util/Set;)V
      // 8d: astore 5
      // 8f: iload 3
      // 90: ifeq ad
      // 93: aload 5
      // 95: aload 0
      // 96: invokevirtual com/l7tech/server/identity/PersistentIdentityProviderImpl.getUserManager ()Lcom/l7tech/identity/UserManager;
      // 99: checkcast com/l7tech/server/identity/PersistentUserManager
      // 9c: aload 2
      // 9d: invokeinterface com/l7tech/server/identity/PersistentUserManager.search (Ljava/lang/String;)Lcom/l7tech/objectmodel/EntityHeaderSet; 2
      // a2: invokevirtual com/l7tech/objectmodel/EntityHeaderSet.addAll (Ljava/util/Collection;)Z
      // a5: pop
      // a6: goto ad
      // a9: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // ac: athrow
      // ad: iload 4
      // af: ifeq cc
      // b2: aload 5
      // b4: aload 0
      // b5: invokevirtual com/l7tech/server/identity/PersistentIdentityProviderImpl.getGroupManager ()Lcom/l7tech/identity/GroupManager;
      // b8: checkcast com/l7tech/server/identity/PersistentGroupManager
      // bb: aload 2
      // bc: invokeinterface com/l7tech/server/identity/PersistentGroupManager.search (Ljava/lang/String;)Ljava/util/Collection; 2
      // c1: invokevirtual com/l7tech/objectmodel/EntityHeaderSet.addAll (Ljava/util/Collection;)Z
      // c4: pop
      // c5: goto cc
      // c8: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // cb: athrow
      // cc: aload 5
      // ce: areturn
      // try (0 -> 6): 7 com/l7tech/objectmodel/FindException
      // try (2 -> 16): 16 com/l7tech/objectmodel/FindException
      // try (49 -> 53): 54 com/l7tech/objectmodel/FindException
      // try (51 -> 63): 63 com/l7tech/objectmodel/FindException
      // try (72 -> 82): 83 com/l7tech/objectmodel/FindException
      // try (85 -> 95): 96 com/l7tech/objectmodel/FindException
   }

   public void validate(UT var1) throws ValidationException {
      String var10002 = var1.getLogin();
      String[] var2 = m;
      throw new ValidationException(var2[4] + var10002 + var2[0]);
   }

   public void setClientCertManager(ClientCertManager var1) {
      this.clientCertManager = var1;
   }

   public void afterPropertiesSet() throws Exception {
   }

   public void setApplicationContext(ApplicationContext var1) throws BeansException {
      this.applicationContext = var1;
   }

   @Override
   public X509Certificate findCertByIssuerAndSerial(X500Principal var1, BigInteger var2) throws FindException {
      return this.a(this.clientCertManager.findByIssuerAndSerial(var1, var2));
   }

   @Override
   public X509Certificate findCertBySki(String var1) throws FindException {
      return this.a(this.clientCertManager.findBySki(var1));
   }

   @Override
   public X509Certificate findCertByThumbprintSHA1(String var1) throws FindException {
      return this.a(this.clientCertManager.findByThumbprint(var1));
   }

   @Override
   public X509Certificate findCertBySubjectDn(X500Principal var1) throws FindException {
      return this.a(this.clientCertManager.findBySubjectDn(var1));
   }

   @Override
   public AuthenticationResult authenticate(LoginCredentials var1, boolean var2) throws AuthenticationException {
      return this.authenticate(var1);
   }

   private X509Certificate a(List<CertEntryRow> param1) throws FindException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aconst_null
      // 01: astore 2
      // 02: aload 0
      // 03: invokevirtual com/l7tech/server/identity/PersistentIdentityProviderImpl.getConfig ()Lcom/l7tech/identity/IdentityProviderConfig;
      // 06: invokevirtual com/l7tech/identity/IdentityProviderConfig.getGoid ()Lcom/l7tech/objectmodel/Goid;
      // 09: astore 3
      // 0a: aload 1
      // 0b: invokeinterface java/util/List.iterator ()Ljava/util/Iterator; 1
      // 10: astore 4
      // 12: aload 4
      // 14: invokeinterface java/util/Iterator.hasNext ()Z 1
      // 19: ifeq 59
      // 1c: aload 4
      // 1e: invokeinterface java/util/Iterator.next ()Ljava/lang/Object; 1
      // 23: checkcast com/l7tech/identity/cert/CertEntryRow
      // 26: astore 5
      // 28: aload 5
      // 2a: invokevirtual com/l7tech/identity/cert/CertEntryRow.getProvider ()Lcom/l7tech/objectmodel/Goid;
      // 2d: aload 3
      // 2e: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 31: ifeq 56
      // 34: aload 2
      // 35: ifnull 50
      // 38: goto 3f
      // 3b: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 3e: athrow
      // 3f: new com/l7tech/objectmodel/FindException
      // 42: dup
      // 43: getstatic com/l7tech/server/identity/PersistentIdentityProviderImpl.m [Ljava/lang/String;
      // 46: bipush 3
      // 47: aaload
      // 48: invokespecial com/l7tech/objectmodel/FindException.<init> (Ljava/lang/String;)V
      // 4b: athrow
      // 4c: invokestatic com/l7tech/server/identity/PersistentIdentityProviderImpl.a (Lcom/l7tech/objectmodel/FindException;)Lcom/l7tech/objectmodel/FindException;
      // 4f: athrow
      // 50: aload 5
      // 52: invokevirtual com/l7tech/identity/cert/CertEntryRow.getCertificate ()Ljava/security/cert/X509Certificate;
      // 55: astore 2
      // 56: goto 12
      // 59: aload 2
      // 5a: areturn
      // try (16 -> 23): 24 com/l7tech/objectmodel/FindException
      // try (21 -> 33): 33 com/l7tech/objectmodel/FindException
   }

   private static FindException a(FindException var0) {
      return var0;
   }

   static {
      String[] var5 = new String[5];
      int var3 = 0;
      String var2 = "\u0015\u0017\"\u000ex\u001c\u0000ABz\u0010x\u001aTWS#N\u001b_By\u00147\u0018AAD*\u0001cHLWVy\u00147\u0007NW\u0017~\u0019g\r&FNz\u0005dHMGD~@t\u0007NFVc\u000e7\u001dSWEy@v\u0006D\u0012Xx@p\u001aOGGy";
      int var4 = "\u0015\u0017\"\u000ex\u001c\u0000ABz\u0010x\u001aTWS#N\u001b_By\u00147\u0018AAD*\u0001cHLWVy\u00147\u0007NW\u0017~\u0019g\r&FNz\u0005dHMGD~@t\u0007NFVc\u000e7\u001dSWEy@v\u0006D\u0012Xx@p\u001aOGGy"
         .length();
      char var1 = 18;
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 2;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = a(var10000, b(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     m = var5;
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "\u000f#\u0004u\b36< \u0005r\u001c\u007f>i!\u0010o\u000f{2'+Qx\ta/ *\u0018x\rg>:\u001c\u001f-\u001dr\br/ #\u001f;\nr2%)\u0015;\n|)i9\u0002~\u001e3|";
                  var4 = "\u000f#\u0004u\b36< \u0005r\u001c\u007f>i!\u0010o\u000f{2'+Qx\ta/ *\u0018x\rg>:\u001c\u001f-\u001dr\br/ #\u001f;\nr2%)\u0015;\n|)i9\u0002~\u001e3|"
                     .length();
                  var1 = '$';
                  var7 = -1;
            }

            var10000 = 121;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

   private static char[] b(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 34);
      }

      return var10000;
   }

   private static String a(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 48;
            case 1 -> 53;
            case 2 -> 8;
            case 3 -> 98;
            case 4 -> 21;
            case 5 -> 106;
            default -> 34;
         });
      }

      return new String(var10001).intern();
   }
}
