Class AuthEnv

java.lang.Object
org.apache.jena.http.auth.AuthEnv

public class AuthEnv extends Object
An authentication environment. Multiple AuthEnv would exists for a multi-tenant environment. This is not currently supported but the use of an object, obtained with get(), allows for that in the future,
  • Field Details

    • LOG

      public static org.slf4j.Logger LOG
  • Method Details

    • get

      public static AuthEnv get()
      Get the AuthEnv appropriate to the caller.
    • registerUsernamePassword

      public void registerUsernamePassword(String uri, String username, String password)
      Register (username, password) information for a URI endpoint.
    • registerUsernamePassword

      public void registerUsernamePassword(URI uri, String username, String password)
      Register (username, password) information for a URI endpoint.
    • hasRegistation

      public boolean hasRegistation(URI uri)
      Check whether there is a registration.
    • unregisterUsernamePassword

      public void unregisterUsernamePassword(URI uri)
      Remove the registration for a URI endpoint.
    • getUsernamePassword

      public PasswordRecord getUsernamePassword(URI uri)
      Return the (username, password) for a URI.

      If there is no exact match for the URI, then the information mapped from the longest prefix entry is returned.

    • clearActiveAuthentication

      public void clearActiveAuthentication()
    • clearAuthEnv

      public void clearAuthEnv()
      Clear all registrations.
    • addAuth

      public HttpRequest.Builder addAuth(HttpRequest.Builder requestBuilder, String uri)
      Add authentication, if in the authModifiers registry. That is, add the right headers, and for digest, calculate the new digest string.
    • registerBasicAuthModifier

      public void registerBasicAuthModifier(String url, String user, String password)
      Register the user/password which is to be used with basic auth at the given URL
    • registerAuthModifier

      public void registerAuthModifier(String requestTarget, AuthRequestModifier authModifier)
      Register an AuthRequestModifier for a specific request target
    • unregisterAuthModifier

      public void unregisterAuthModifier(String requestTarget)
      Remove any AuthRequestModifier for a specific request target
    • setBearerTokenProvider

      public void setBearerTokenProvider(BiFunction<String,AuthChallenge,String> tokenSupplier)
      Set the creator of tokens for bearer authentication. The function must return null (reject a 401 challenge) or a valid token including encoding (e.g. Base64). It must not contain spaces. Requests will fail when the token becomes out-of-date and the application will need to set a new token.

      The string supplied will be used as-is with no further processing.

      Supply a null argument for the tokenSupplier to clear any previous token supplier.

    • setBearerToken

      public void setBearerToken(String requestTarget, String token)
      Set the tokens for bearer authentication at an specific endpoint. This is added to all requests sent to this same request target. Requests will fail when the token becomes out-of-date and the application will need to set a new token.

      The string supplied will be used as-is with no further processing. Supply a null argument to clear any previous token supplier.

    • getBearerToken

      public String getBearerToken(String uri, AuthChallenge aHeader)
      Return a bearer auth token to use when responding to a 401 challenge. The token must be in the form required for the "Authorization" header, including encoding (typically base64 URL encoding with no padding). The string supplied is used as-is with no further processing.

      Return null for "no token" in which case a 401 response is passed back to the application.

    • state

      public void state()