123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- /**
- Licensed Materials - Property of IBM
- IBM Cognos Products: DOCS
- (C) Copyright IBM Corp. 2005, 2008
- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
- IBM Corp.
- */
- /**
- * Credentials.java
- *
- * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
- * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
- *
- * Description: This file contains methods for creating credentials
- *
- */
- import org.apache.axis.client.Stub;
- import com.cognos.developer.schemas.bibus._3.AnyTypeProp;
- import com.cognos.developer.schemas.bibus._3.BaseClass;
- import com.cognos.developer.schemas.bibus._3.BiBusHeader;
- import com.cognos.developer.schemas.bibus._3.CAM;
- import com.cognos.developer.schemas.bibus._3.Credential;
- import com.cognos.developer.schemas.bibus._3.Locale;
- import com.cognos.developer.schemas.bibus._3.MultilingualToken;
- import com.cognos.developer.schemas.bibus._3.MultilingualTokenProp;
- import com.cognos.developer.schemas.bibus._3.PropEnum;
- import com.cognos.developer.schemas.bibus._3.QueryOptions;
- import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
- import com.cognos.developer.schemas.bibus._3.Sort;
- public class Credentials
- {
- public void setCredential(CRNConnect connection)
- {
- BiBusHeader bibus = null;
- try
- {
- Credential credential = new Credential();
- String search = "~/*";
- PropEnum[] props =
- { PropEnum.searchPath, PropEnum.name, PropEnum.defaultName };
- BaseClass[] objects =
- connection.getCMService().query(
- new SearchPathMultipleObject(search),
- props,
- new Sort[] {},
- new QueryOptions());
- if (objects != null)
- {
- for (int i = 0; i < objects.length; i++)
- {
- if (objects[i].getClass() == Credential.class)
- {
- credential.setSearchPath(objects[i].getSearchPath());
- credential.setName(objects[i].getName());
- credential.setDefaultName(objects[i].getDefaultName());
- bibus =
- BIBusHeaderHelper.getHeaderObject(((Stub)connection.getCMService()).getResponseHeader("", "biBusHeader"));
-
- if (bibus != null)
- {
- CAM newCam = bibus.getCAM();
- if (newCam != null)
- {
- newCam.setCAMCredentialPath(
- objects[i].getSearchPath().getValue());
- bibus.setCAM(newCam);
- }
- ((Stub)connection.getCMService()).setHeader("", "biBusHeader", bibus);
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public static boolean hasCredential(CRNConnect connection) throws java.rmi.RemoteException
- {
- String search = "~/*";
- PropEnum[] props =
- { PropEnum.searchPath, PropEnum.name, PropEnum.defaultName };
- BaseClass[] objects = null;
- objects =
- connection.getCMService().query(
- new SearchPathMultipleObject(search),
- props,
- new Sort[] {},
- new QueryOptions());
- if (objects != null)
- {
- for (int i = 0; i < objects.length; i++)
- {
- if (objects[i].getClass() == Credential.class)
- {
- return true;
- }
- }
- }
- return false;
- }
-
- public void addCredential(CRNConnect connection)
- {
- CSHandlers csHandler = new CSHandlers();
- Credential credential = new Credential();
-
- //Prepare the credentials for the new credential object
- AnyTypeProp credentials = new AnyTypeProp();
- credentials.setValue(Logon.getCredentialString());
-
- //Prepare the name property for the new credential object
- MultilingualToken[] names = new MultilingualToken[1];
- names[0] = new MultilingualToken();
- Locale[] locales = csHandler.getConfiguration(connection);
- names[0].setLocale(locales[0].getLocale());
- names[0].setValue("Credential");
- MultilingualTokenProp credNameTokenProp = new MultilingualTokenProp();
- credNameTokenProp.setValue(names);
-
- //Add the searchPath, name and defaultname to the new credential object
- credential.setName(credNameTokenProp);
- credential.setCredentials(credentials);
-
- try
- {
- csHandler.addObjectToCS(connection, credential, Logon.getLogonAccount(connection).getSearchPath().getValue());
- }
- catch (java.rmi.RemoteException remoteEx)
- {
- remoteEx.printStackTrace();
- }
-
- }
- }
|