CognosContainer
import io.skipcheck.tm1.testcontainers.CognosContainer; IBM Cognos Analytics in Docker, for tests, built on the cognos-server image:
the security (CAM) a TM1 server in CAM mode takes its users from.
Give it test users, and the container builds an LDAP directory with them and a Cognos
namespace (LDAP) for it. Then run a Tm1ServerContainer against
it with Tm1ServerContainer.withCamSecurity, and log in to TM1 as each test
user:
try (var cognos = new CognosContainer(cognosSource).withUser("admin", "adminpw", "Admins")
.withUser("viewer", "viewerpw", "Readers");
var server = new Tm1ServerContainer(tm1Source).withCamSecurity(cognos, "admin")) {
server.start(); // starts Cognos first
// Each test user logs in with their own identity, through the LDAP namespace
Tm1Client viewer = Tm1Client.builder()
.baseUrl(server.getRestUrl())
.authenticator(Tm1Authenticator.camNamespace("viewer", "viewerpw", CognosContainer.NAMESPACE))
.build();
try {
// TM1 knows the user by their CAMID
return viewer.users().activeUser(ODataQuery.none().select(User.NAME)).map(User::name).block(WAIT);
}
finally {
viewer.close().block(WAIT);
}
}
Cognos is heavy: it takes about two minutes to start and uses about 8 GB of memory, so
Docker needs at least 12 GB. Every user is a Cognos administrator (a new content store
puts Everyone there); TM1's own security comes from the groups. The image contains no
IBM software, so every container needs a CognosSource.
Members
DEFAULT_IMAGE static | The cognos-server image, without a tag. |
SERVER_IMAGE static | Overrides the cognos-server image (not used with PrivateImage), e.g. |
DISPATCHER_PORT static | The Cognos dispatcher's port inside the container. |
NETWORK_ALIAS static | The container's host name and network alias, which Cognos's dispatcher URIs name. |
NAMESPACE static | The ID of the LDAP namespace the test users are in. |
CognosContainer constructor | A container on the default cognos-server image (or COGNOS_SERVER_IMAGE), getting Cognos from source. |
CognosContainer constructor | A container on image, which must be cognos-server or built on it. |
withUser | Adds a test user. |
withKeycloak | Adds an OIDC namespace (CognosContainer.Namespace.OIDC) through keycloak. |
getKeycloak | The Keycloak set with withKeycloak. |
getUsers | The test users, in the order they were added. |
getUser | A test user by name. |
getGroups | Every group of the test users, in order of first appearance. |
getSource | Where Cognos comes from. |
getUrl | Cognos as seen from the host, e.g. |
getNetworkUrl | The dispatcher's address on the container's Docker network, http://cognos:9300. |
camAuthorization | The Authorization header for a test user's CAM logon to TM1 (or Cognos). |
camAuthorization | The Authorization header for a test user's CAM logon through a namespace. |
passport | Logs a user on to Cognos with an ID token they already hold (the OIDC namespace's CAMOIDCIdToken), and returns their CAM passport. |
camAuthorization static | The Authorization header for a CAM logon. |
DEFAULT_IMAGE
staticDockerImageName DEFAULT_IMAGEThe cognos-server image, without a tag.
SERVER_IMAGE
staticString SERVER_IMAGE Overrides the cognos-server image (not used with
PrivateImage), e.g. cognos-server:local for a local
build. Read as a system property, then an environment variable.
DISPATCHER_PORT
staticint DISPATCHER_PORTThe Cognos dispatcher's port inside the container.
NETWORK_ALIAS
staticString NETWORK_ALIAS The container's host name and network alias, which Cognos's dispatcher URIs name.
Other containers on its network reach it at http://cognos:9300.
NAMESPACE
staticString NAMESPACEThe ID of the LDAP namespace the test users are in: the CAMNamespace.
CognosContainer
constructorCognosContainer(CognosSource source) A container on the default cognos-server image (or
COGNOS_SERVER_IMAGE), getting Cognos from source.
Parameters
source- where Cognos comes from
CognosContainer
constructorCognosContainer(DockerImageName image, CognosSource source) A container on image, which must be cognos-server or built on it.
Parameters
image- the image to run
source- where Cognos comes from
withUser
CognosContainer withUser(String name, String password, String... groups)Adds a test user. With at least one user, logons are required (anonymous access is off).
Parameters
name- the user name: letters, digits,
.,_and- password- the password; no
:or whitespace groups- the Cognos groups the user is in, created as needed; same rules as names
Returns
- this container
Throws
IllegalArgumentException- if a name or the password isn't allowed, or the user was already added
withKeycloak
CognosContainer withKeycloak(KeycloakContainer keycloak) Adds an OIDC namespace (CognosContainer.Namespace.OIDC) through keycloak: when
Cognos starts, it builds a realm there from the test users. The two containers
share a Docker network, and Keycloak starts first.
Parameters
keycloak- the Keycloak to use
Returns
- this container
getKeycloak
KeycloakContainer getKeycloak() The Keycloak set with withKeycloak.
Returns
- the Keycloak, or
nullif there's no OIDC namespace
getUsers
List<CognosContainer.User> getUsers()The test users, in the order they were added.
Returns
- the users
getUser
CognosContainer.User getUser(String name)A test user by name.
Parameters
name- the user name
Returns
- the user
Throws
IllegalArgumentException- if there's no such user
getGroups
Set<String> getGroups()Every group of the test users, in order of first appearance.
Returns
- the group names
getSource
CognosSource getSource()Where Cognos comes from.
Returns
- the source
getUrl
String getUrl() Cognos as seen from the host, e.g. http://localhost:54321/bi/.
Returns
- the URL, ending in
/
getNetworkUrl
String getNetworkUrl() The dispatcher's address on the container's Docker network,
http://cognos:9300: what a TM1 server there is pointed at.
Returns
- the in-network address
camAuthorization
String camAuthorization(String user) The Authorization header for a test user's CAM logon to TM1 (or Cognos):
CAMNamespace and the Base64 of user:password:namespace.
Parameters
user- a test user's name
Returns
- the header value
Throws
IllegalArgumentException- if there's no such user
camAuthorization
String camAuthorization(String user, CognosContainer.Namespace namespace) The Authorization header for a test user's CAM logon through a namespace.
Through CognosContainer.Namespace.OIDC, Cognos checks the password with Keycloak.
Parameters
user- a test user's name
namespace- the namespace to log on through
Returns
- the header value
Throws
IllegalArgumentException- if there's no such user
passport
String passport(String idToken) Logs a user on to Cognos with an ID token they already hold (the OIDC namespace's
CAMOIDCIdToken), and returns their CAM passport. TM1 in CAM security takes
it as Authorization: CAMPassport <passport>.
Parameters
idToken- an ID token from the OIDC provider, e.g.
KeycloakContainer.idToken
Returns
- the passport
Throws
IllegalStateException- if Cognos refuses the token
camAuthorization
staticstatic String camAuthorization(String user, String password, String namespace) The Authorization header for a CAM logon.
Parameters
user- the user name
password- the password
namespace- the Cognos namespace ID
Returns
CAMNamespaceand the Base64 ofuser:password:namespace
Also in the Javadoc.