Logging on and logging off
If your IBM® Cognos® Analytics with Watson server requires authentication, import the authentication methods and classes using the following URL:
http://webservername:portnumber/ibmcognos/bi/v1/disp/rds/auth/wsdl
Use the logon
method to log
on to the Cognos
Analytics
server using the Mashup Service authentication methods.
You can determine which credentials the server requires by submitting
an empty credentials
element.
The server response includes a credentialPrompt
element
that lists actualValue
elements
for which the server has values and missingValue
elements
whose values must be supplied.
You can then submit another logon request with a credentials
element
that contains values for the missingValue
elements.
If your logon attempt is successful, the server response includes
an accountInfo
element
that provides authentication details.
If your log on request contains incorrect data, or still has missing
values, the server response is another credentialPrompt
element.
- C# example
To see this code in context, view the following sample program:
installation_location/sdk/cms_samples/csharp/Authentication/genericAuthentication.cs
AuthService authService = new AuthService(); authService.Url = url; LogonRequestType authRequest = new LogonRequestType(); authRequest.credentials = new CredentialType(); authRequest.credentials.credentialElements = new CredentialElementType[3]; authRequest.credentials.credentialElements[0] = new CredentialElementType(); authRequest.credentials.credentialElements[0].name = "CAMNamespace"; authRequest.credentials.credentialElements[0].value = new ValueElementType(); authRequest.credentials.credentialElements[0].value.Item = nameSpace; authRequest.credentials.credentialElements[1] = new CredentialElementType(); authRequest.credentials.credentialElements[1].name = "CAMUsername"; authRequest.credentials.credentialElements[1].value = new ValueElementType(); authRequest.credentials.credentialElements[1].value.Item = userName; authRequest.credentials.credentialElements[2] = new CredentialElementType(); authRequest.credentials.credentialElements[2].name = "CAMPassword"; authRequest.credentials.credentialElements[2].value = new ValueElementType(); authRequest.credentials.credentialElements[2].value.Item = passWord; LogonResponseType authResp = authService.logon(authRequest);
- Java™ example
To see this code in context, view the following sample program:
installation_location/sdk/cms_samples/java/Authentication/genericAuthentication.java
String nameSpaceStr=strNameSpace; //namespace String userNameStr=strUserName; //username String userPasswordStr=strPassword; //password String reportIDStr=strReportID; //reportID AuthServiceLocator authlocator = new AuthServiceLocator(); AuthServicePort authService = authlocator.getAuthServicePort(new URL(serverURL)); CredentialType credentialType = new CredentialType(); CredentialElementType nameSpaceElement = new CredentialElementType(); ValueElementType nameSpaceValue = new ValueElementType(); nameSpaceValue.setActualValue(nameSpaceStr); nameSpaceElement.setName("CAMNamespace"); nameSpaceElement.setValue(nameSpaceValue); CredentialElementType userNameElement = new CredentialElementType(); ValueElementType userNameValue = new ValueElementType(); userNameValue.setActualValue(userNameStr); userNameElement.setName("CAMUsername"); userNameElement.setValue(userNameValue); CredentialElementType passWordElement = new CredentialElementType(); ValueElementType passWordValue = new ValueElementType(); passWordValue.setActualValue(userPasswordStr); passWordElement.setName("CAMPassword"); passWordElement.setValue(passWordValue); //Login IBM Cognos server using the CMS Authentication Service credentialType.setCredentialElements(new CredentialElementType[] {nameSpaceElement,userNameElement,passWordElement}); LogonRequestType logonRequest = new LogonRequestType(credentialType, null); LogonResponseType logonResponse = authService.logon(logonRequest); //Copy the SOAP header from the Authentication Service to CMS org.apache.axis.message.SOAPHeaderElement[] headers =((org.apache.axis.client.Stub) authService).getResponseHeaders();
When the application has completed, log off the user if your server requires authentication.
- C# example
LogoffRequestType logoffRequest = new LogoffRequestType(); logoffResponseType logoffResp = authService.logoff(logoffRequest);
- Java example
LogoffRequestType LogoffRequest = new LogoffRequestType(); LogoffResponseType logoff = authService.logoff(LogoffRequest);