package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.xmlsec.ProcessRstrSoapResponse;
import com.l7tech.security.token.SecurityTokenType;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractMessageTargetableServerAssertion;
import com.l7tech.util.ArrayUtils;
import com.l7tech.util.SoapConstants;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.springframework.beans.factory.BeanFactory;
import org.w3c.dom.Element;

public class ServerProcessRstrSoapResponse extends AbstractMessageTargetableServerAssertion<ProcessRstrSoapResponse> {
   private final SecurityTokenResolver d;
   private static final String[] e;

   public ServerProcessRstrSoapResponse(ProcessRstrSoapResponse var1, BeanFactory var2) {
      super(var1);
      this.d = (SecurityTokenResolver)var2.getBean(e[0], SecurityTokenResolver.class);
   }

   @Override
   protected AssertionStatus doCheckRequest(PolicyEnforcementContext param1, Message param2, String param3, AuthenticationContext param4) throws IOException, PolicyAssertionException {
      // $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:
      // 000: aload 2
      // 001: invokevirtual com/l7tech/message/Message.isSoap ()Z
      // 004: ifne 01e
      // 007: aload 0
      // 008: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RSTR_PROCESSOR_NOT_SOAP Lcom/l7tech/gateway/common/audit/Messages$M;
      // 00b: bipush 1
      // 00c: anewarray 29
      // 00f: dup
      // 010: bipush 0
      // 011: aload 3
      // 012: aastore
      // 013: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 016: getstatic com/l7tech/policy/assertion/AssertionStatus.NOT_APPLICABLE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 019: areturn
      // 01a: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 01d: athrow
      // 01e: aload 2
      // 01f: invokevirtual com/l7tech/message/Message.getXmlKnob ()Lcom/l7tech/message/XmlKnob;
      // 022: invokeinterface com/l7tech/message/XmlKnob.getDocumentReadOnly ()Lorg/w3c/dom/Document; 1
      // 027: invokestatic com/l7tech/xml/soap/SoapUtil.getBodyElement (Lorg/w3c/dom/Document;)Lorg/w3c/dom/Element;
      // 02a: astore 5
      // 02c: goto 061
      // 02f: astore 6
      // 031: aload 0
      // 032: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RSTR_PROCESSOR_BAD_XML Lcom/l7tech/gateway/common/audit/Messages$M;
      // 035: bipush 2
      // 036: anewarray 29
      // 039: dup
      // 03a: bipush 0
      // 03b: aload 3
      // 03c: aastore
      // 03d: dup
      // 03e: bipush 1
      // 03f: aload 6
      // 041: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 044: aastore
      // 045: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 048: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 04b: areturn
      // 04c: astore 6
      // 04e: aload 0
      // 04f: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RSTR_PROCESSOR_NOT_SOAP Lcom/l7tech/gateway/common/audit/Messages$M;
      // 052: bipush 1
      // 053: anewarray 29
      // 056: dup
      // 057: bipush 0
      // 058: aload 3
      // 059: aastore
      // 05a: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 05d: getstatic com/l7tech/policy/assertion/AssertionStatus.NOT_APPLICABLE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 060: areturn
      // 061: aload 5
      // 063: invokestatic com/l7tech/util/DomUtils.findOnlyOneChildElement (Lorg/w3c/dom/Element;)Lorg/w3c/dom/Element;
      // 066: astore 7
      // 068: aload 7
      // 06a: aload 0
      // 06b: getfield com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.d Lcom/l7tech/security/xml/SecurityTokenResolver;
      // 06e: invokestatic com/l7tech/security/wstrust/RstrInfo.parse (Lorg/w3c/dom/Element;Lcom/l7tech/security/xml/SecurityTokenResolver;)Lcom/l7tech/security/wstrust/RstrInfo;
      // 071: astore 6
      // 073: goto 0ac
      // 076: astore 7
      // 078: aload 0
      // 079: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RSTR_PROCESSOR_INVALID Lcom/l7tech/gateway/common/audit/Messages$M;
      // 07c: bipush 1
      // 07d: anewarray 29
      // 080: dup
      // 081: bipush 0
      // 082: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.e [Ljava/lang/String;
      // 085: astore 8
      // 087: aload 8
      // 089: bipush 2
      // 08a: aaload
      // 08b: aastore
      // 08c: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 08f: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 092: areturn
      // 093: astore 7
      // 095: aload 0
      // 096: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RSTR_PROCESSOR_INVALID Lcom/l7tech/gateway/common/audit/Messages$M;
      // 099: bipush 1
      // 09a: anewarray 29
      // 09d: dup
      // 09e: bipush 0
      // 09f: aload 7
      // 0a1: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 0a4: aastore
      // 0a5: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 0a8: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0ab: areturn
      // 0ac: aload 6
      // 0ae: invokevirtual com/l7tech/security/wstrust/RstrInfo.getToken ()Lorg/w3c/dom/Element;
      // 0b1: ifnonnull 0cf
      // 0b4: aload 0
      // 0b5: getstatic com/l7tech/gateway/common/audit/AssertionMessages.RSTR_PROCESSOR_INVALID Lcom/l7tech/gateway/common/audit/Messages$M;
      // 0b8: bipush 1
      // 0b9: anewarray 29
      // 0bc: dup
      // 0bd: bipush 0
      // 0be: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.e [Ljava/lang/String;
      // 0c1: bipush 1
      // 0c2: aaload
      // 0c3: aastore
      // 0c4: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 0c7: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0ca: areturn
      // 0cb: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0ce: athrow
      // 0cf: aload 0
      // 0d0: aload 6
      // 0d2: invokevirtual com/l7tech/security/wstrust/RstrInfo.getToken ()Lorg/w3c/dom/Element;
      // 0d5: aload 0
      // 0d6: getfield com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0d9: checkcast com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse
      // 0dc: invokevirtual com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.getTokenType ()Lcom/l7tech/security/token/SecurityTokenType;
      // 0df: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Lorg/w3c/dom/Element;Lcom/l7tech/security/token/SecurityTokenType;)Z
      // 0e2: ifne 0ed
      // 0e5: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0e8: areturn
      // 0e9: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0ec: athrow
      // 0ed: aload 1
      // 0ee: aload 0
      // 0ef: getstatic com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.VARIABLE_TOKEN Ljava/lang/String;
      // 0f2: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/String;)Ljava/lang/String;
      // 0f5: aload 6
      // 0f7: invokevirtual com/l7tech/security/wstrust/RstrInfo.getToken ()Lorg/w3c/dom/Element;
      // 0fa: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 0ff: aload 1
      // 100: aload 0
      // 101: getstatic com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.VARIABLE_CREATE_TIME Ljava/lang/String;
      // 104: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/String;)Ljava/lang/String;
      // 107: aload 6
      // 109: invokevirtual com/l7tech/security/wstrust/RstrInfo.getCreatedText ()Ljava/lang/String;
      // 10c: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 111: aload 1
      // 112: aload 0
      // 113: getstatic com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.VARIABLE_EXPIRY_TIME Ljava/lang/String;
      // 116: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/String;)Ljava/lang/String;
      // 119: aload 6
      // 11b: invokevirtual com/l7tech/security/wstrust/RstrInfo.getExpiresText ()Ljava/lang/String;
      // 11e: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 123: aload 1
      // 124: aload 0
      // 125: getstatic com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.VARIABLE_SERVER_ENTROPY Ljava/lang/String;
      // 128: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/String;)Ljava/lang/String;
      // 12b: aload 6
      // 12d: invokevirtual com/l7tech/security/wstrust/RstrInfo.getEntropyBase64 ()Ljava/lang/String;
      // 130: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 135: aload 1
      // 136: aload 0
      // 137: getstatic com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.VARIABLE_KEY_SIZE Ljava/lang/String;
      // 13a: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/String;)Ljava/lang/String;
      // 13d: aload 6
      // 13f: invokevirtual com/l7tech/security/wstrust/RstrInfo.getKeySize ()I
      // 142: invokestatic java/lang/Integer.valueOf (I)Ljava/lang/Integer;
      // 145: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 14a: aload 1
      // 14b: aload 0
      // 14c: getstatic com/l7tech/policy/assertion/xmlsec/ProcessRstrSoapResponse.VARIABLE_FULL_KEY Ljava/lang/String;
      // 14f: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerProcessRstrSoapResponse.a (Ljava/lang/String;)Ljava/lang/String;
      // 152: aload 6
      // 154: invokevirtual com/l7tech/security/wstrust/RstrInfo.getSecretBase64 ()Ljava/lang/String;
      // 157: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setVariable (Ljava/lang/String;Ljava/lang/Object;)V 3
      // 15c: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // 15f: areturn
      // try (0 -> 13): 22 org/xml/sax/SAXException
      // try (16 -> 21): 22 org/xml/sax/SAXException
      // try (0 -> 13): 39 com/l7tech/util/InvalidDocumentFormatException
      // try (0 -> 14): 14 java/io/IOException
      // try (16 -> 21): 39 com/l7tech/util/InvalidDocumentFormatException
      // try (51 -> 59): 60 com/l7tech/util/TooManyChildElementsException
      // try (51 -> 59): 76 com/l7tech/util/InvalidDocumentFormatException
      // try (89 -> 105): 105 org/xml/sax/SAXException
      // try (107 -> 118): 118 org/xml/sax/SAXException
   }

   private boolean a(Element var1, SecurityTokenType var2) {
      boolean var3 = false;
      if ((var2 != SecurityTokenType.SAML_ASSERTION || SoapConstants.SAML_NAMESPACE.equals(var1.getNamespaceURI()))
         && (var2 != SecurityTokenType.SAML2_ASSERTION || SoapConstants.SAML_NAMESPACE2.equals(var1.getNamespaceURI()))
         && (var2 != SecurityTokenType.WSSC_CONTEXT || ArrayUtils.contains(SoapConstants.WSSC_NAMESPACE_ARRAY, var1.getNamespaceURI()))) {
         var3 = true;
      } else {
         this.logAndAudit(AssertionMessages.RSTR_PROCESSOR_UNEXPECTED_TOKEN, var2.getName(), this.a(var1));
      }

      return var3;
   }

   private String a(Element var1) {
      return new QName(var1.getNamespaceURI(), var1.getLocalName()).toString();
   }

   private String a(String var1) {
      String var2 = var1;
      if (this.assertion.getVariablePrefix() != null) {
         var2 = this.assertion.getVariablePrefix() + "." + var1;
      }

      return var2;
   }

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

   static {
      String[] var5 = new String[3];
      int var3 = 0;
      String var2 = "A*'\n\u007f%{K\u001b+\u0014h\"]W<+\u0013{)}\u0014\\ d\u000bb'j\\o-\u0011->jA?+\u0011~)\u0013\\ 0_l\"/`\u001c\u0010--!jA<%\u0018h";
      int var4 = "A*'\n\u007f%{K\u001b+\u0014h\"]W<+\u0013{)}\u0014\\ d\u000bb'j\\o-\u0011->jA?+\u0011~)\u0013\\ 0_l\"/`\u001c\u0010--!jA<%\u0018h".length();
      char var1 = 21;
      int var0 = -1;

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

         var1 = var2.charAt(var0);
      }
   }

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

      return var10000;
   }

   private static String c(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 -> 96;
            case 2 -> 107;
            case 3 -> 80;
            case 4 -> 34;
            case 5 -> 99;
            default -> 32;
         });
      }

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