Credentials.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * Credentials.java
  10. *
  11. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. *
  14. * Description: This file contains methods for creating credentials
  15. *
  16. */
  17. import org.apache.axis.client.Stub;
  18. import com.cognos.developer.schemas.bibus._3.AnyTypeProp;
  19. import com.cognos.developer.schemas.bibus._3.BaseClass;
  20. import com.cognos.developer.schemas.bibus._3.BiBusHeader;
  21. import com.cognos.developer.schemas.bibus._3.CAM;
  22. import com.cognos.developer.schemas.bibus._3.Credential;
  23. import com.cognos.developer.schemas.bibus._3.Locale;
  24. import com.cognos.developer.schemas.bibus._3.MultilingualToken;
  25. import com.cognos.developer.schemas.bibus._3.MultilingualTokenProp;
  26. import com.cognos.developer.schemas.bibus._3.PropEnum;
  27. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  28. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  29. import com.cognos.developer.schemas.bibus._3.Sort;
  30. public class Credentials
  31. {
  32. public void setCredential(CRNConnect connection)
  33. {
  34. BiBusHeader bibus = null;
  35. try
  36. {
  37. Credential credential = new Credential();
  38. String search = "~/*";
  39. PropEnum[] props =
  40. { PropEnum.searchPath, PropEnum.name, PropEnum.defaultName };
  41. BaseClass[] objects =
  42. connection.getCMService().query(
  43. new SearchPathMultipleObject(search),
  44. props,
  45. new Sort[] {},
  46. new QueryOptions());
  47. if (objects != null)
  48. {
  49. for (int i = 0; i < objects.length; i++)
  50. {
  51. if (objects[i].getClass() == Credential.class)
  52. {
  53. credential.setSearchPath(objects[i].getSearchPath());
  54. credential.setName(objects[i].getName());
  55. credential.setDefaultName(objects[i].getDefaultName());
  56. bibus =
  57. BIBusHeaderHelper.getHeaderObject(((Stub)connection.getCMService()).getResponseHeader("", "biBusHeader"));
  58. if (bibus != null)
  59. {
  60. CAM newCam = bibus.getCAM();
  61. if (newCam != null)
  62. {
  63. newCam.setCAMCredentialPath(
  64. objects[i].getSearchPath().getValue());
  65. bibus.setCAM(newCam);
  66. }
  67. ((Stub)connection.getCMService()).setHeader("", "biBusHeader", bibus);
  68. }
  69. }
  70. }
  71. }
  72. }
  73. catch (Exception e)
  74. {
  75. e.printStackTrace();
  76. }
  77. }
  78. public static boolean hasCredential(CRNConnect connection) throws java.rmi.RemoteException
  79. {
  80. String search = "~/*";
  81. PropEnum[] props =
  82. { PropEnum.searchPath, PropEnum.name, PropEnum.defaultName };
  83. BaseClass[] objects = null;
  84. objects =
  85. connection.getCMService().query(
  86. new SearchPathMultipleObject(search),
  87. props,
  88. new Sort[] {},
  89. new QueryOptions());
  90. if (objects != null)
  91. {
  92. for (int i = 0; i < objects.length; i++)
  93. {
  94. if (objects[i].getClass() == Credential.class)
  95. {
  96. return true;
  97. }
  98. }
  99. }
  100. return false;
  101. }
  102. public void addCredential(CRNConnect connection)
  103. {
  104. CSHandlers csHandler = new CSHandlers();
  105. Credential credential = new Credential();
  106. //Prepare the credentials for the new credential object
  107. AnyTypeProp credentials = new AnyTypeProp();
  108. credentials.setValue(Logon.getCredentialString());
  109. //Prepare the name property for the new credential object
  110. MultilingualToken[] names = new MultilingualToken[1];
  111. names[0] = new MultilingualToken();
  112. Locale[] locales = csHandler.getConfiguration(connection);
  113. names[0].setLocale(locales[0].getLocale());
  114. names[0].setValue("Credential");
  115. MultilingualTokenProp credNameTokenProp = new MultilingualTokenProp();
  116. credNameTokenProp.setValue(names);
  117. //Add the searchPath, name and defaultname to the new credential object
  118. credential.setName(credNameTokenProp);
  119. credential.setCredentials(credentials);
  120. try
  121. {
  122. csHandler.addObjectToCS(connection, credential, Logon.getLogonAccount(connection).getSearchPath().getValue());
  123. }
  124. catch (java.rmi.RemoteException remoteEx)
  125. {
  126. remoteEx.printStackTrace();
  127. }
  128. }
  129. }