package com.l7tech.server.identity;

import com.l7tech.identity.BadCredentialsException;
import com.l7tech.identity.User;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.assertion.credential.LoginCredentials;
import com.l7tech.security.token.SessionSecurityToken;

public class SessionAuthenticator {
   private final Goid a;
   private static final String[] b;

   public SessionAuthenticator(Goid var1) {
      this.a = var1;
   }

   public AuthenticationResult authenticateSessionCredentials(LoginCredentials param1, User param2) throws BadCredentialsException {
      // $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: invokevirtual com/l7tech/policy/assertion/credential/LoginCredentials.getSecurityToken ()Lcom/l7tech/security/token/SecurityToken;
      // 04: astore 3
      // 05: aload 3
      // 06: instanceof com/l7tech/security/token/SessionSecurityToken
      // 09: ifne 1d
      // 0c: new com/l7tech/identity/BadCredentialsException
      // 0f: dup
      // 10: getstatic com/l7tech/server/identity/SessionAuthenticator.b [Ljava/lang/String;
      // 13: bipush 1
      // 14: aaload
      // 15: invokespecial com/l7tech/identity/BadCredentialsException.<init> (Ljava/lang/String;)V
      // 18: athrow
      // 19: invokestatic com/l7tech/server/identity/SessionAuthenticator.a (Lcom/l7tech/identity/BadCredentialsException;)Lcom/l7tech/identity/BadCredentialsException;
      // 1c: athrow
      // 1d: aload 3
      // 1e: checkcast com/l7tech/security/token/SessionSecurityToken
      // 21: astore 4
      // 23: aload 4
      // 25: invokevirtual com/l7tech/security/token/SessionSecurityToken.getProviderId ()Lcom/l7tech/objectmodel/Goid;
      // 28: aload 0
      // 29: getfield com/l7tech/server/identity/SessionAuthenticator.a Lcom/l7tech/objectmodel/Goid;
      // 2c: invokevirtual com/l7tech/objectmodel/Goid.equals (Ljava/lang/Object;)Z
      // 2f: ifne 38
      // 32: aconst_null
      // 33: areturn
      // 34: invokestatic com/l7tech/server/identity/SessionAuthenticator.a (Lcom/l7tech/identity/BadCredentialsException;)Lcom/l7tech/identity/BadCredentialsException;
      // 37: athrow
      // 38: aload 2
      // 39: invokeinterface com/l7tech/identity/User.getId ()Ljava/lang/String; 1
      // 3e: ifnonnull 50
      // 41: aload 4
      // 43: invokevirtual com/l7tech/security/token/SessionSecurityToken.getUserId ()Ljava/lang/String;
      // 46: ifnonnull 78
      // 49: goto 50
      // 4c: invokestatic com/l7tech/server/identity/SessionAuthenticator.a (Lcom/l7tech/identity/BadCredentialsException;)Lcom/l7tech/identity/BadCredentialsException;
      // 4f: athrow
      // 50: aload 2
      // 51: invokeinterface com/l7tech/identity/User.getId ()Ljava/lang/String; 1
      // 56: ifnull 89
      // 59: goto 60
      // 5c: invokestatic com/l7tech/server/identity/SessionAuthenticator.a (Lcom/l7tech/identity/BadCredentialsException;)Lcom/l7tech/identity/BadCredentialsException;
      // 5f: athrow
      // 60: aload 2
      // 61: invokeinterface com/l7tech/identity/User.getId ()Ljava/lang/String; 1
      // 66: aload 4
      // 68: invokevirtual com/l7tech/security/token/SessionSecurityToken.getUserId ()Ljava/lang/String;
      // 6b: invokevirtual java/lang/String.equals (Ljava/lang/Object;)Z
      // 6e: ifne 89
      // 71: goto 78
      // 74: invokestatic com/l7tech/server/identity/SessionAuthenticator.a (Lcom/l7tech/identity/BadCredentialsException;)Lcom/l7tech/identity/BadCredentialsException;
      // 77: athrow
      // 78: new com/l7tech/identity/BadCredentialsException
      // 7b: dup
      // 7c: getstatic com/l7tech/server/identity/SessionAuthenticator.b [Ljava/lang/String;
      // 7f: bipush 0
      // 80: aaload
      // 81: invokespecial com/l7tech/identity/BadCredentialsException.<init> (Ljava/lang/String;)V
      // 84: athrow
      // 85: invokestatic com/l7tech/server/identity/SessionAuthenticator.a (Lcom/l7tech/identity/BadCredentialsException;)Lcom/l7tech/identity/BadCredentialsException;
      // 88: athrow
      // 89: new com/l7tech/server/identity/AuthenticationResult
      // 8c: dup
      // 8d: aload 2
      // 8e: aload 1
      // 8f: invokevirtual com/l7tech/policy/assertion/credential/LoginCredentials.getSecurityTokens ()[Lcom/l7tech/security/token/SecurityToken;
      // 92: invokespecial com/l7tech/server/identity/AuthenticationResult.<init> (Lcom/l7tech/identity/User;[Lcom/l7tech/security/token/SecurityToken;)V
      // 95: areturn
      // try (3 -> 13): 13 com/l7tech/identity/BadCredentialsException
      // try (18 -> 26): 26 com/l7tech/identity/BadCredentialsException
      // try (28 -> 34): 35 com/l7tech/identity/BadCredentialsException
      // try (31 -> 40): 41 com/l7tech/identity/BadCredentialsException
      // try (37 -> 49): 50 com/l7tech/identity/BadCredentialsException
      // try (43 -> 59): 59 com/l7tech/identity/BadCredentialsException
   }

   public String getUserId(LoginCredentials var1) {
      String var2 = null;
      if (var1.getSecurityToken() instanceof SessionSecurityToken var4 && var4.getProviderId().equals(this.a)) {
         var2 = var4.getUserId();
      }

      return var2;
   }

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

   static {
      String[] var5 = new String[2];
      int var3 = 0;
      String var2 = "T{\u0006jH\u0005.'j\u001arD\u0004`kq\u0012pOJ$h{\u00069O\u00054's\u0014mB\u0002`nz\u0010wU\u00034~0\u0010Rp\u0010aQ\u000f#s{\u00119U\u0005+bp";
      int var4 = "T{\u0006jH\u0005.'j\u001arD\u0004`kq\u0012pOJ$h{\u00069O\u00054's\u0014mB\u0002`nz\u0010wU\u00034~0\u0010Rp\u0010aQ\u000f#s{\u00119U\u0005+bp"
         .length();
      char var1 = ',';
      int var0 = -1;

      while (true) {
         String var10002 = a(26, a(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            b = var5;
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

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

      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 -> 29;
            case 1 -> 4;
            case 2 -> 111;
            case 3 -> 3;
            case 4 -> 59;
            case 5 -> 112;
            default -> 90;
         });
      }

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