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.SecurityHeaderAddressableSupport;
import com.l7tech.policy.assertion.xmlsec.XmlSecurityAssertionBase;
import com.l7tech.security.token.ParsedElement;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.security.xml.processor.ProcessorResult;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractMessageTargetableServerAssertion;
import com.l7tech.server.policy.assertion.ServerAssertion;
import com.l7tech.util.Config;
import com.l7tech.xml.InvalidXpathException;
import com.l7tech.xml.xpath.DomCompiledXpath;
import java.io.IOException;
import org.springframework.context.ApplicationContext;

public abstract class ServerRequireWssOperation<AT extends XmlSecurityAssertionBase>
   extends AbstractMessageTargetableServerAssertion<AT>
   implements ServerAssertion<AT> {
   private final Config d;
   private final SecurityTokenResolver e;
   private final DomCompiledXpath f;
   private final InvalidXpathException g;
   private static final String[] i;

   protected ServerRequireWssOperation(AT var1, ApplicationContext var2) {
      super((AT)var1);
      String[] var6 = i;
      this.d = (Config)var2.getBean(var6[1], Config.class);
      this.e = (SecurityTokenResolver)var2.getBean(var6[0], SecurityTokenResolver.class);

      DomCompiledXpath var3;
      InvalidXpathException var4;
      try {
         var3 = new DomCompiledXpath(var1.getXpathExpression());
         var4 = null;
      } catch (InvalidXpathException var7) {
         var3 = null;
         var4 = var7;
      }

      this.f = var3;
      this.g = var4;
   }

   protected DomCompiledXpath getCompiledXpath() throws PolicyAssertionException {
      try {
         if (this.g != null) {
            throw new PolicyAssertionException(this.assertion, this.g);
         }
      } catch (PolicyAssertionException var1) {
         throw a(var1);
      }

      try {
         if (this.f == null) {
            throw new PolicyAssertionException(this.assertion, i[4]);
         }
      } catch (PolicyAssertionException var2) {
         throw a(var2);
      }

      return this.f;
   }

   @Override
   public AssertionStatus checkRequest(PolicyEnforcementContext var1) throws IOException, PolicyAssertionException {
      try {
         if (!SecurityHeaderAddressableSupport.isLocalRecipient(this.assertion)) {
            this.logAndAudit(AssertionMessages.REQUESTWSS_NOT_FOR_US);
            return AssertionStatus.NONE;
         }
      } catch (IOException var2) {
         throw a(var2);
      }

      return super.checkRequest(var1);
   }

   @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 01f
      // 007: aload 0
      // 008: getstatic com/l7tech/gateway/common/audit/AssertionMessages.REQUIREWSS_NONSOAP Lcom/l7tech/gateway/common/audit/Messages$M;
      // 00b: bipush 1
      // 00c: anewarray 179
      // 00f: dup
      // 010: bipush 0
      // 011: aload 3
      // 012: aastore
      // 013: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V
      // 016: aload 0
      // 017: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.getBadMessageStatus ()Lcom/l7tech/policy/assertion/AssertionStatus;
      // 01a: areturn
      // 01b: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 01e: athrow
      // 01f: aload 0
      // 020: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.isRequest ()Z
      // 023: ifeq 04d
      // 026: aload 0
      // 027: getfield com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.d Lcom/l7tech/util/Config;
      // 02a: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.i [Ljava/lang/String;
      // 02d: bipush 2
      // 02e: aaload
      // 02f: bipush 1
      // 030: invokeinterface com/l7tech/util/Config.getBooleanProperty (Ljava/lang/String;Z)Z 3
      // 035: ifne 04d
      // 038: goto 03f
      // 03b: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 03e: athrow
      // 03f: aload 2
      // 040: invokevirtual com/l7tech/message/Message.getSecurityKnob ()Lcom/l7tech/message/SecurityKnob;
      // 043: invokeinterface com/l7tech/message/SecurityKnob.getProcessorResult ()Lcom/l7tech/security/xml/processor/ProcessorResult; 1
      // 048: astore 5
      // 04a: goto 05c
      // 04d: aload 2
      // 04e: aload 3
      // 04f: aload 0
      // 050: getfield com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.e Lcom/l7tech/security/xml/SecurityTokenResolver;
      // 053: aload 0
      // 054: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.getAudit ()Lcom/l7tech/gateway/common/audit/Audit;
      // 057: invokestatic com/l7tech/server/util/WSSecurityProcessorUtils.getWssResults (Lcom/l7tech/message/Message;Ljava/lang/String;Lcom/l7tech/security/xml/SecurityTokenResolver;Lcom/l7tech/gateway/common/audit/Audit;)Lcom/l7tech/security/xml/processor/ProcessorResult;
      // 05a: astore 5
      // 05c: goto 06b
      // 05f: astore 6
      // 061: new com/l7tech/util/CausedIOException
      // 064: dup
      // 065: aload 6
      // 067: invokespecial com/l7tech/util/CausedIOException.<init> (Ljava/lang/Throwable;)V
      // 06a: athrow
      // 06b: aload 2
      // 06c: invokevirtual com/l7tech/message/Message.getXmlKnob ()Lcom/l7tech/message/XmlKnob;
      // 06f: invokeinterface com/l7tech/message/XmlKnob.getDocumentReadOnly ()Lorg/w3c/dom/Document; 1
      // 074: astore 6
      // 076: goto 095
      // 079: astore 7
      // 07b: aload 0
      // 07c: getstatic com/l7tech/gateway/common/audit/AssertionMessages.EXCEPTION_SEVERE_WITH_MORE_INFO Lcom/l7tech/gateway/common/audit/Messages$M;
      // 07f: bipush 1
      // 080: anewarray 179
      // 083: dup
      // 084: bipush 0
      // 085: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.i [Ljava/lang/String;
      // 088: bipush 3
      // 089: aaload
      // 08a: aastore
      // 08b: aload 7
      // 08d: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;Ljava/lang/Throwable;)V
      // 090: aload 0
      // 091: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.getBadMessageStatus ()Lcom/l7tech/policy/assertion/AssertionStatus;
      // 094: areturn
      // 095: aload 0
      // 096: aload 5
      // 098: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.getElementsFoundByProcessor (Lcom/l7tech/security/xml/processor/ProcessorResult;)[Lcom/l7tech/security/token/ParsedElement;
      // 09b: astore 7
      // 09d: aload 0
      // 09e: aload 1
      // 09f: aload 2
      // 0a0: aload 5
      // 0a2: aload 7
      // 0a4: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.elementsFoundByProcessorAreValid (Lcom/l7tech/server/message/PolicyEnforcementContext;Lcom/l7tech/message/Message;Lcom/l7tech/security/xml/processor/ProcessorResult;[Lcom/l7tech/security/token/ParsedElement;)Z
      // 0a7: ifne 0b2
      // 0aa: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 0ad: areturn
      // 0ae: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0b1: athrow
      // 0b2: aload 0
      // 0b3: getfield com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.logger Ljava/util/logging/Logger;
      // 0b6: aload 6
      // 0b8: aload 0
      // 0b9: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.getCompiledXpath ()Lcom/l7tech/xml/xpath/DomCompiledXpath;
      // 0bc: new com/l7tech/server/util/xml/PolicyEnforcementContextXpathVariableFinder
      // 0bf: dup
      // 0c0: aload 1
      // 0c1: invokespecial com/l7tech/server/util/xml/PolicyEnforcementContextXpathVariableFinder.<init> (Lcom/l7tech/server/message/PolicyEnforcementContext;)V
      // 0c4: aload 0
      // 0c5: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.isAllowIfEmpty ()Z
      // 0c8: aload 7
      // 0ca: aload 0
      // 0cb: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.getPastTenseOperationName ()Ljava/lang/String;
      // 0ce: invokestatic com/l7tech/security/xml/processor/ProcessorResultUtil.searchInResult (Ljava/util/logging/Logger;Lorg/w3c/dom/Document;Lcom/l7tech/xml/xpath/DomCompiledXpath;Lcom/l7tech/xml/xpath/XpathVariableFinder;Z[Lcom/l7tech/security/token/ParsedElement;Ljava/lang/String;)Lcom/l7tech/security/xml/processor/ProcessorResultUtil$SearchResult;
      // 0d1: astore 8
      // 0d3: goto 0e6
      // 0d6: astore 9
      // 0d8: new com/l7tech/policy/assertion/PolicyAssertionException
      // 0db: dup
      // 0dc: aload 0
      // 0dd: getfield com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.assertion Lcom/l7tech/policy/assertion/Assertion;
      // 0e0: aload 9
      // 0e2: invokespecial com/l7tech/policy/assertion/PolicyAssertionException.<init> (Lcom/l7tech/policy/assertion/Assertion;Ljava/lang/Throwable;)V
      // 0e5: athrow
      // 0e6: aload 0
      // 0e7: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.isRequest ()Z
      // 0ea: ifeq 109
      // 0ed: aload 8
      // 0ef: invokevirtual com/l7tech/security/xml/processor/ProcessorResultUtil$SearchResult.isFoundButWasntOperatedOn ()Z
      // 0f2: ifeq 109
      // 0f5: goto 0fc
      // 0f8: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0fb: athrow
      // 0fc: aload 1
      // 0fd: invokeinterface com/l7tech/server/message/PolicyEnforcementContext.setRequestPolicyViolated ()V 1
      // 102: goto 109
      // 105: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 108: athrow
      // 109: aload 8
      // 10b: invokevirtual com/l7tech/security/xml/processor/ProcessorResultUtil$SearchResult.getResultCode ()I
      // 10e: lookupswitch 69 2 0 26 1 65
      // 128: aload 0
      // 129: aload 1
      // 12a: aload 2
      // 12b: aload 5
      // 12d: aload 8
      // 12f: invokevirtual com/l7tech/security/xml/processor/ProcessorResultUtil$SearchResult.getElements ()[Lcom/l7tech/security/token/ParsedElement;
      // 132: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.elementsFoundForAssertionAreValid (Lcom/l7tech/server/message/PolicyEnforcementContext;Lcom/l7tech/message/Message;Lcom/l7tech/security/xml/processor/ProcessorResult;[Lcom/l7tech/security/token/ParsedElement;)Z
      // 135: ifne 147
      // 138: goto 13f
      // 13b: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 13e: athrow
      // 13f: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 142: areturn
      // 143: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 146: athrow
      // 147: aload 0
      // 148: aload 1
      // 149: aload 2
      // 14a: aload 3
      // 14b: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerRequireWssOperation.onCheckRequestSuccess (Lcom/l7tech/server/message/PolicyEnforcementContext;Lcom/l7tech/message/Message;Ljava/lang/String;)Lcom/l7tech/policy/assertion/AssertionStatus;
      // 14e: areturn
      // 14f: getstatic com/l7tech/policy/assertion/AssertionStatus.FALSIFIED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 152: areturn
      // 153: getstatic com/l7tech/policy/assertion/AssertionStatus.SERVER_ERROR Lcom/l7tech/policy/assertion/AssertionStatus;
      // 156: areturn
      // try (0 -> 14): 45 org/xml/sax/SAXException
      // try (17 -> 28): 29 org/xml/sax/SAXException
      // try (0 -> 15): 15 com/l7tech/security/xml/processor/ProcessorException
      // try (17 -> 44): 45 org/xml/sax/SAXException
      // try (51 -> 55): 56 org/xml/sax/SAXException
      // try (76 -> 85): 85 org/xml/sax/SAXException
      // try (87 -> 103): 104 com/l7tech/security/xml/processor/ProcessorException
      // try (112 -> 118): 119 org/xml/sax/SAXException
      // try (115 -> 123): 124 org/xml/sax/SAXException
      // try (126 -> 137): 138 org/xml/sax/SAXException
      // try (129 -> 142): 142 org/xml/sax/SAXException
   }

   protected boolean elementsFoundByProcessorAreValid(PolicyEnforcementContext var1, Message var2, ProcessorResult var3, ParsedElement[] var4) {
      return true;
   }

   protected boolean elementsFoundForAssertionAreValid(PolicyEnforcementContext var1, Message var2, ProcessorResult var3, ParsedElement[] var4) {
      return true;
   }

   protected abstract String getPastTenseOperationName();

   protected abstract boolean isAllowIfEmpty();

   protected AssertionStatus onCheckRequestSuccess(PolicyEnforcementContext var1, Message var2, String var3) {
      return AssertionStatus.NONE;
   }

   protected abstract ParsedElement[] getElementsFoundByProcessor(ProcessorResult var1);

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

   static {
      String[] var5 = new String[5];
      int var3 = 0;
      String var2 = "@AB1auBJpN/vrdVWN(eyD\f@AS2vnu\\JG-t-DWRjcnYPAR7|n\u0018VJ@&\u007fyrVBD6ayRaAP1voBcVN'voEZJF";
      int var4 = "@AB1auBJpN/vrdVWN(eyD\f@AS2vnu\\JG-t-DWRjcnYPAR7|n\u0018VJ@&\u007fyrVBD6ayRaAP1voBcVN'voEZJF".length();
      char var1 = 21;
      int var7 = -1;

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

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

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

                  var2 = ".\u001b\u0011t\"6H\n\u001f\u000b:=#\u0011\u0001\u0015\u001e~m&\u0007\u000e\u000f\u0012\u007f#6F\u0010#\u0015_Y\"/\u0018\u0004\u0016\u001a~\u00152\t\u0019\u0012";
                  var4 = ".\u001b\u0011t\"6H\n\u001f\u000b:=#\u0011\u0001\u0015\u001e~m&\u0007\u000e\u000f\u0012\u007f#6F\u0010#\u0015_Y\"/\u0018\u0004\u0016\u001a~\u00152\t\u0019\u0012"
                     .length();
                  var1 = 28;
                  var7 = -1;
            }

            var10000 = 14;
            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] ^ 102);
      }

      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 -> 99;
            case 1 -> 116;
            case 2 -> 113;
            case 3 -> 20;
            case 4 -> 67;
            case 5 -> 76;
            default -> 102;
         });
      }

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