Class AuthUtils

java.lang.Object
ch.autumo.commons.utils.web.AuthUtils

public class AuthUtils extends Object
Auth Utils.
  • Method Details

    • getHost

      public static org.apache.http.HttpHost getHost(String protocol, String hostName, int port) throws CommonsException
      Return HTTP host. Port and protocoll cannot be 0/null.
      Parameters:
      protocol - protocol or null (default: http)
      hostName - hostname
      port - port or 0 (default determined on protocol)
      Returns:
      HTTP host
      Throws:
      CommonsException - if protocol isn't valid
    • getAuthHost

      public static org.apache.http.HttpHost getAuthHost(String protocol, String hostName, String authHostName, int port) throws CommonsException
      Return Auth HTTP host. Port and protocol cannot be 0/null.
      Parameters:
      protocol - protocol or null (default: http)
      hostName - hostname
      authHostName - authentication host name
      port - port or 0 (default determined on protocol)
      Returns:
      HTTP host
      Throws:
      CommonsException - if protocol isn't valid
    • createNoAuthContext

      public static AuthContext createNoAuthContext()
      Create a simple auth context that needs no authentication.
      Returns:
      auth context
    • createAPIKeyAuthContext

      public static AuthContext createAPIKeyAuthContext()
      Create a simple auth context fro API key authentication.
      Returns:
      auth context
    • createBasicAuthContext

      public static AuthContext createBasicAuthContext(org.apache.http.HttpHost authHost, String user, String password) throws CommonsException
      Create a basic auth context. This uses preemptive basic authentication: Authorization is sent in first call! See: https://www.baeldung.com/httpclient-basic-authentication
      Parameters:
      authHost - authentication host name
      user - user
      password - password
      Returns:
      auth context
      Throws:
      CommonsException - if user isn't valid
    • createDigestAuthContext

      public static AuthContext createDigestAuthContext(org.apache.http.HttpHost authHost, String authUrl, String user, String password) throws CommonsException
      Create a digest auth context.
      Parameters:
      authHost - authentication host
      authUrl - auth URL is the relative path after the host or auth host that is used for digest token setup; when null '/' is used!
      user - user
      password - password
      Returns:
      auth context
      Throws:
      CommonsException - if user or password isn't valid
    • createOAuthContext

      public static AuthContext createOAuthContext(org.apache.http.HttpHost authHost, String authUrl, String user, String password, String authMethod, String grantType, List<String[]> body) throws CommonsException
      Create an OAuth auth context. This works for any token (basic, bearer, etc.), but no OAuth 2.0 flows are supported.
      Parameters:
      authHost - authentication host
      authUrl - auth URL is the relative path after the host or auth host that is used for digest token setup; when null '/' is used!
      user - user
      password - password
      authMethod - auth method for determining sub-type
      grantType - grant type
      body - body name-value-pairs
      Returns:
      auth context
      Throws:
      CommonsException - if handshake fails
    • revokeToken

      public static void revokeToken(AuthContext authContext) throws CommonsException
      Revoke token if possible.
      Parameters:
      authContext - auth context
      Throws:
      CommonsException - if revocation fails