View Javadoc

1   package com.atlassian.asap.api.exception;
2   
3   import com.atlassian.asap.core.validator.ValidatedKeyId;
4   
5   import javax.annotation.Nullable;
6   import java.net.URI;
7   import java.util.Optional;
8   
9   /**
10   * Thrown when an incoming HTTP request cannot be authenticated using ASAP.
11   */
12  public abstract class AuthenticationFailedException extends Exception {
13      /**
14       * The validated key ID that was used when the authentication failure happened. May be {@code null}
15       */
16      @Nullable
17      private final ValidatedKeyId keyId;
18  
19      /**
20       * The URI from which the key was fetched, if it was.
21       */
22      @Nullable
23      private final URI keyUri;
24  
25      /**
26       * The unverified issuer that used when the authentication failure happened. May be {@code null}
27       */
28      @Nullable
29      private final String unverifiedIssuer;
30  
31      protected AuthenticationFailedException(String message, String unverifiedIssuer) {
32          this(message, null, null, unverifiedIssuer);
33      }
34  
35      protected AuthenticationFailedException(String message, ValidatedKeyId keyId, URI keyUri, String unverifiedIssuer) {
36          super(message);
37          this.keyId = keyId;
38          this.keyUri = keyUri;
39          this.unverifiedIssuer = unverifiedIssuer;
40      }
41  
42      public Optional<ValidatedKeyId> getKeyId() {
43          return Optional.ofNullable(keyId);
44      }
45  
46      public Optional<URI> getKeyUri() {
47          return Optional.ofNullable(keyUri);
48      }
49  
50      public Optional<String> getUnverifiedIssuer() {
51          return Optional.ofNullable(unverifiedIssuer);
52      }
53  }