package com.airlock.iam.publicselfservice.application.configuration.restrictions;

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.BooleanProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "Ensures that for users that don't exist, public self-service continues in Stealth Mode (simulating the next step), or that they are immediately rejected (if the \"Enable Feedback\" property is enabled).",
   displayName = "Nonexistent User Restriction"
)
public class NonexistentUserRestrictionConfig implements InternalPublicSelfServiceRestrictionConfig {
   static final String NONEXISTENT_USER_RESTRICTION_DISPLAY_NAME = "Nonexistent User Restriction";
   @BooleanProperty(
      description = "<p>If enabled, the User Identification Step always returns a specific error code in case this restriction is violated.</p><p>If no restrictions are configured to provide feedback, a flow can also be started for users violating one or more restrictions and the flow will advance to the user identity verification step in stealth mode. In this mode, the initial behavior of the step is the same as for unrestricted users (e.g. an mTAN OTP is required), but all responses are rejected as if they were incorrect. This behavior prevents restricted users from ever proceeding further in the flow and thus offers protection against user enumeration. Please refer to the documentation for more details.</p><p>Irrespective of this settings, once the identity verification step is passed, restriction are always checked before and after each method call and violations are always reported.</p><p><b>Security notice:</b> Enabling this feature might allow a client to determine whether certain users exist in the system.</p>",
      optional = true,
      displayName = "Enable Feedback",
      defaultValue = "false"
   )
   private boolean enableFeedback;
   static final String ENABLE_FEEDBACK_DISPLAY_NAME = "Enable Feedback";

   public boolean isEnableFeedback() {
      return this.enableFeedback;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static NonexistentUserRestrictionConfig.NonexistentUserRestrictionConfigBuilder builder() {
      return new NonexistentUserRestrictionConfig.NonexistentUserRestrictionConfigBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public NonexistentUserRestrictionConfig() {
   }

   @SuppressFBWarnings(justification = "generated code")
   public NonexistentUserRestrictionConfig(boolean enableFeedback) {
      this.enableFeedback = enableFeedback;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class NonexistentUserRestrictionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private boolean enableFeedback;

      @SuppressFBWarnings(justification = "generated code")
      NonexistentUserRestrictionConfigBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public NonexistentUserRestrictionConfig.NonexistentUserRestrictionConfigBuilder enableFeedback(boolean enableFeedback) {
         this.enableFeedback = enableFeedback;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public NonexistentUserRestrictionConfig build() {
         return new NonexistentUserRestrictionConfig(this.enableFeedback);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "NonexistentUserRestrictionConfig.NonexistentUserRestrictionConfigBuilder(enableFeedback=" + this.enableFeedback + ")";
      }
   }
}
