Class Tm1Login
java.lang.Object
io.skipcheck.tm1.testcontainers.Tm1Login
A user's login to a TM1 v12 instance, through one of the instance's applications
("service-to-service"): TM1 v12 has no passwords of its own, so the application's
client ID and secret vouch for the user's name.
A login belongs to an instance: its session serves every database there. Whether the user may do anything in a database depends on the user existing in it.
Get one from Tm1Database.login() or Tm1Database.login(String), then
either let it log in for you (authorize(HttpRequest.Builder) or cookie()), or hand
getClientId(), getClientSecret() and getUser() to a client
that logs in itself.
Two other kinds log a user in as themselves: an OAuth 2.0 login
(Tm1Database.oauth2Login(String)), with a token from the engine's Keycloak, and a
pass-through login (Tm1Database.passThroughLogin()), with the
Authorization header a TM1 11 server takes (getAuthorization()).
authorize(HttpRequest.Builder) and cookie() work for all three.
-
Method Summary
Modifier and TypeMethodDescriptionauthorize(HttpRequest.Builder request) Adds this login's session cookie to a request.authorizeWithToken(HttpRequest.Builder request) Adds this login's token to a request asAuthorization: Bearer, as a program with a token of its own would send it.cookie()The session cookie,TM1SessionId=..., for aCookieheader.TheAuthorizationheader of a pass-through login, as a client that logs in itself sends it on any request:Basicwith the user's name and password on the TM1 11 server, orCAMNamespacewhen that server is in Cognos (CAM) security.Where a session or a token is asked for, as seen from the host, e.g.The application's client ID; the Keycloak client's for an OAuth 2.0 login, and empty for a pass-through login, which goes through no application.The application's client secret; empty for an OAuth 2.0 or a pass-through login.The instance this login is for.The user's password: at the identity provider for an OAuth 2.0 login, and on the TM1 11 server (or in Cognos) for a pass-through login.Where a token is asked for: the identity provider's token endpoint for an OAuth 2.0 login, as seen from the host, and TM1's own otherwise.getUser()The user this logs in as.booleanisOAuth2()Whether this is a login through OAuth 2.0 (Tm1Database.oauth2Login(String)), rather than through the instance's application.booleanWhether this is a pass-through login (Tm1Database.passThroughLogin()): one TM1 v12 checks with a TM1 11 server.Logs the user in with anAuthorizationheader of your own, such as"Bearer " + token(), and returns the new session's cookie.token()A bearer token for the application, from TM1's token endpoint (the OAuth 2.0 client-credentials grant).toString()
-
Method Details
-
isPassThrough
public boolean isPassThrough()Whether this is a pass-through login (Tm1Database.passThroughLogin()): one TM1 v12 checks with a TM1 11 server.- Returns:
truefor a pass-through login
-
getAuthorization
TheAuthorizationheader of a pass-through login, as a client that logs in itself sends it on any request:Basicwith the user's name and password on the TM1 11 server, orCAMNamespacewhen that server is in Cognos (CAM) security.- Returns:
- the header's value
- Throws:
IllegalStateException- for a login that isn't pass-through
-
isOAuth2
public boolean isOAuth2()Whether this is a login through OAuth 2.0 (Tm1Database.oauth2Login(String)), rather than through the instance's application.- Returns:
truefor an OAuth 2.0 login
-
getPassword
The user's password: at the identity provider for an OAuth 2.0 login, and on the TM1 11 server (or in Cognos) for a pass-through login. Empty otherwise, as TM1 v12 keeps none, and for a pass-through login made from a header alone.- Returns:
- the password, or empty
-
getTokenUrl
Where a token is asked for: the identity provider's token endpoint for an OAuth 2.0 login, as seen from the host, and TM1's own otherwise.- Returns:
- the token endpoint
-
getInstance
-
getUser
The user this logs in as. For a pass-through login it's the name on the TM1 11 server, or in Cognos: with a server in CAM security the user's name in TM1 v12 is its CAMID. Empty for a pass-through login made from a header alone.- Returns:
- the user's name
-
getClientId
The application's client ID; the Keycloak client's for an OAuth 2.0 login, and empty for a pass-through login, which goes through no application.- Returns:
- the client ID
-
getClientSecret
The application's client secret; empty for an OAuth 2.0 or a pass-through login.- Returns:
- the client secret
-
getAuthUrl
Where a session or a token is asked for, as seen from the host, e.g.http://localhost:54321/tm1/auth/v1/.- Returns:
- the instance's authentication root, ending in
/
-
cookie
The session cookie,TM1SessionId=..., for aCookieheader. Logs in the first time, with the application's credentials as Basic authentication, and keeps the session.- Returns:
- the cookie, name and value
- Throws:
IllegalStateException- if TM1 refuses the login
-
token
A bearer token for the application, from TM1's token endpoint (the OAuth 2.0 client-credentials grant). It names no user: send it asAuthorization: Bearerwith the user's name to get a session, assession(String)does.- Returns:
- the access token, a JWT
- Throws:
IllegalStateException- if TM1 refuses the application's credentials
-
session
Logs the user in with anAuthorizationheader of your own, such as"Bearer " + token(), and returns the new session's cookie. Each call makes a session;cookie()keeps one.- Parameters:
authorization- theAuthorizationheader's value- Returns:
- the session cookie,
TM1SessionId=... - Throws:
IllegalStateException- if TM1 refuses the login
-
authorize
Adds this login's session cookie to a request.- Parameters:
request- the request being built- Returns:
- the same builder
-
authorizeWithToken
Adds this login's token to a request asAuthorization: Bearer, as a program with a token of its own would send it. For an OAuth 2.0 login, a new token from the provider each time; TM1 answers with a session cookie.- Parameters:
request- the request being built- Returns:
- the same builder
- Throws:
IllegalStateException- for a login through the application, whose token TM1 takes only at its session endpoint (session(String))
-
toString
-