Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

637 lines
21 KiB

  1. using System;
  2. using System.IO;
  3. using System.Web;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Collections;
  7. using System.Web.Services;
  8. using System.Xml.Serialization;
  9. using System.Security.Principal;
  10. using System.Web.Security;
  11. using System.Web.Services.Protocols;
  12. using UDDI.API;
  13. using UDDI;
  14. using UDDI.Diagnostics;
  15. using UDDI.API.Authentication;
  16. using UDDI.API.Binding;
  17. using UDDI.API.Service;
  18. using UDDI.API.Business;
  19. using UDDI.API.ServiceType;
  20. namespace UDDI.API
  21. {
  22. /// ****************************************************************
  23. /// class PublishMessages
  24. /// ----------------------------------------------------------------
  25. /// <summary>
  26. /// This is the web service class that contains the UDDI
  27. /// publish methods.
  28. /// </summary>
  29. /// ****************************************************************
  30. ///
  31. [SoapDocumentService( ParameterStyle=SoapParameterStyle.Bare, RoutingStyle=SoapServiceRoutingStyle.RequestElement )]
  32. [WebService( Namespace=UDDI.API.Constants.Namespace )]
  33. public class PublishMessages
  34. {
  35. /// ****************************************************************
  36. /// public AddPublisherAssertions
  37. /// ----------------------------------------------------------------
  38. /// <summary>
  39. /// Web method for adding publisher assertions. Users are
  40. /// authenticated and the message is processed as part of a
  41. /// transaction.
  42. /// </summary>
  43. /// ----------------------------------------------------------------
  44. /// <param name="message">
  45. /// A properly formed instance of the add_publisherAssertions
  46. /// message.
  47. /// </param>
  48. /// ----------------------------------------------------------------
  49. /// <returns>
  50. /// Returns a disposition report indicating success or failure.
  51. /// </returns>
  52. /// ****************************************************************
  53. ///
  54. [WebMethod, SoapDocumentMethod( Action = "\"\"", RequestElementName = "add_publisherAssertions" )]
  55. [UDDIExtension( authenticate = true, transaction = true, https = true, messageType = "add_publisherAssertions" )]
  56. public DispositionReport AddPublisherAssertions( AddPublisherAssertions message )
  57. {
  58. Debug.Enter();
  59. //
  60. // Create a disposition report indicating success
  61. //
  62. DispositionReport report = new DispositionReport();
  63. try
  64. {
  65. //
  66. // Add the publisher assertions.
  67. //
  68. message.Save();
  69. }
  70. catch( Exception e )
  71. {
  72. DispositionReport.Throw( e );
  73. }
  74. Debug.Leave();
  75. return report;
  76. }
  77. /// ****************************************************************
  78. /// public DeleteBinding
  79. /// ----------------------------------------------------------------
  80. /// <summary>
  81. /// Web method for removing a set of bindingTemplates from the UDDI registry.
  82. /// Users are authenticated and the message is processed as part of a
  83. /// transaction.
  84. /// </summary>
  85. /// ----------------------------------------------------------------
  86. /// <param name="dbind">
  87. /// A properly formed instance of the delete_binding message.
  88. /// </param>
  89. /// ----------------------------------------------------------------
  90. /// <returns>
  91. /// Returns a dispositionReport indicating success or failure.
  92. /// </returns>
  93. /// ****************************************************************
  94. ///
  95. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="delete_binding")]
  96. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="delete_binding" )]
  97. public DispositionReport DeleteBinding( DeleteBinding dbind )
  98. {
  99. Debug.Enter();
  100. //
  101. // Create dispositionReport indicating success
  102. //
  103. DispositionReport dr = new DispositionReport();
  104. try
  105. {
  106. //
  107. // Delete the binding
  108. //
  109. dbind.Delete();
  110. }
  111. catch( Exception e )
  112. {
  113. DispositionReport.Throw( e );
  114. }
  115. return dr;
  116. }
  117. /// ****************************************************************
  118. /// public DeleteBusiness
  119. /// ----------------------------------------------------------------
  120. /// <summary>
  121. /// Web method for removing a set of businessEntities from the UDDI registry.
  122. /// Users are authenticated and the message is processed as part of a
  123. /// transaction.
  124. /// </summary>
  125. /// ----------------------------------------------------------------
  126. /// <param name="dbus">
  127. /// A properly formed instance of the delete_business message.
  128. /// </param>
  129. /// ----------------------------------------------------------------
  130. /// <returns>
  131. /// Returns a dispositionReport indicating success or failure.
  132. /// </returns>
  133. /// ****************************************************************
  134. ///
  135. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="delete_business")]
  136. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="delete_business" )]
  137. public DispositionReport DeleteBusiness( DeleteBusiness dbus )
  138. {
  139. Debug.Enter();
  140. DispositionReport dr = new DispositionReport();
  141. try
  142. {
  143. //
  144. // Delete the business
  145. //
  146. dbus.Delete();
  147. }
  148. catch( Exception e )
  149. {
  150. DispositionReport.Throw( e );
  151. }
  152. return dr;
  153. }
  154. /// ****************************************************************
  155. /// public class DeletePublisherAssertions
  156. /// ----------------------------------------------------------------
  157. /// <summary>
  158. /// </summary>
  159. /// ****************************************************************
  160. ///
  161. [WebMethod]
  162. [SoapDocumentMethod( Action = "\"\"", RequestElementName = "delete_publisherAssertions" )]
  163. [UDDIExtension( authenticate = true, transaction = true, https = true, messageType = "delete_publisherAssertions" )]
  164. public DispositionReport DeletePublisherAssertions( DeletePublisherAssertions message )
  165. {
  166. Debug.Enter();
  167. DispositionReport report = new DispositionReport();
  168. try
  169. {
  170. message.Delete();
  171. }
  172. catch( Exception e )
  173. {
  174. DispositionReport.Throw( e );
  175. }
  176. Debug.Leave();
  177. return report;
  178. }
  179. /// ****************************************************************
  180. /// public DeleteService
  181. /// ----------------------------------------------------------------
  182. /// <summary>
  183. /// Web method for removing a set of businessServices from the UDDI registry.
  184. /// Users are authenticated and the message is processed as part of a
  185. /// transaction.
  186. /// </summary>
  187. /// ----------------------------------------------------------------
  188. /// <param name="ds">
  189. /// A properly formed instance of the delete_service message.
  190. /// </param>
  191. /// ----------------------------------------------------------------
  192. /// <returns>
  193. /// Returns a dispositionReport indicating success or failure.
  194. /// </returns>
  195. /// ****************************************************************
  196. ///
  197. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="delete_service")]
  198. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="delete_service" )]
  199. public DispositionReport DeleteService( DeleteService ds )
  200. {
  201. Debug.Enter();
  202. DispositionReport dr = new DispositionReport();
  203. try
  204. {
  205. //
  206. // Delete the service
  207. //
  208. ds.Delete();
  209. }
  210. catch( Exception e )
  211. {
  212. DispositionReport.Throw( e );
  213. }
  214. return dr;
  215. }
  216. /// ****************************************************************
  217. /// public DeleteTModel
  218. /// ----------------------------------------------------------------
  219. /// <summary>
  220. /// Web method for removing a set of tModels from the UDDI registry.
  221. /// Users are authenticated and the message is processed as part of a
  222. /// transaction.
  223. /// </summary>
  224. /// ----------------------------------------------------------------
  225. /// <param name="dtm">
  226. /// A properly formed instance of the delete_tModel message.
  227. /// </param>
  228. /// ----------------------------------------------------------------
  229. /// <returns>
  230. /// Returns a dispositionReport indicating success or failure.
  231. /// </returns>
  232. /// ****************************************************************
  233. ///
  234. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="delete_tModel")]
  235. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="delete_tModel" )]
  236. public DispositionReport DeleteTModel( DeleteTModel dtm )
  237. {
  238. Debug.Enter();
  239. DispositionReport dr = new DispositionReport();
  240. try
  241. {
  242. //
  243. // Delete the tModel
  244. //
  245. dtm.Delete();
  246. }
  247. catch( Exception e )
  248. {
  249. DispositionReport.Throw( e );
  250. }
  251. return dr;
  252. }
  253. /// ****************************************************************
  254. /// public DiscardAuthToken
  255. /// ----------------------------------------------------------------
  256. /// <summary>
  257. /// This optional message is used to deactivate an authentication token
  258. /// that was obtained by a call to get_authToken.
  259. /// </summary>
  260. /// ----------------------------------------------------------------
  261. /// <param name="dat">
  262. /// A properly formed instance of the discard_authToken message.
  263. /// </param>
  264. /// ----------------------------------------------------------------
  265. /// <returns>
  266. /// Returns a dispositionReport indicating success or failure.
  267. /// </returns>
  268. /// ****************************************************************
  269. ///
  270. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="discard_authToken")]
  271. [UDDIExtension( https=true, messageType="discard_authToken" )]
  272. public DispositionReport DiscardAuthToken( DiscardAuthToken dat )
  273. {
  274. Debug.Enter();
  275. DispositionReport dr = new DispositionReport();
  276. try
  277. {
  278. if( ( Config.GetInt( "Security.AuthenticationMode" ) == (int) AuthenticationMode.Passport ) )
  279. {
  280. PassportAuthenticator authenticator = new PassportAuthenticator();
  281. authenticator.Authenticate( dat.AuthInfo, Config.GetInt( "Security.TimeOut" ) );
  282. //
  283. // Call to the database to update the user status to logged off.
  284. //
  285. SqlCommand cmd = new SqlCommand( "ADM_setPublisherStatus", ConnectionManager.GetConnection() );
  286. cmd.Transaction = ConnectionManager.GetTransaction();
  287. cmd.CommandType = CommandType.StoredProcedure;
  288. cmd.Parameters.Add( new SqlParameter( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID ) ).Direction = ParameterDirection.Input;
  289. cmd.Parameters.Add( new SqlParameter( "@publisherStatus", SqlDbType.NVarChar, UDDI.Constants.Lengths.PublisherStatus ) ).Direction = ParameterDirection.Input;
  290. SqlParameterAccessor paramacc = new SqlParameterAccessor( cmd.Parameters );
  291. paramacc.SetString( "@PUID", Context.User.ID );
  292. paramacc.SetString( "@publisherStatus", "loggedOut");
  293. cmd.ExecuteNonQuery();
  294. }
  295. }
  296. catch( Exception e )
  297. {
  298. DispositionReport.Throw( e );
  299. }
  300. return dr;
  301. }
  302. [WebMethod]
  303. [SoapDocumentMethod( Action = "\"\"", RequestElementName = "get_assertionStatusReport" )]
  304. [UDDIExtension( authenticate = true, https = true, messageType = "get_assertionStatusReport" )]
  305. public AssertionStatusReport GetAssertionStatusReport( GetAssertionStatusReport message )
  306. {
  307. Debug.Enter();
  308. AssertionStatusReport statusReport = new AssertionStatusReport();
  309. try
  310. {
  311. statusReport.Get( message.CompletionStatus );
  312. }
  313. catch( Exception e )
  314. {
  315. DispositionReport.Throw( e );
  316. }
  317. Debug.Leave();
  318. return statusReport;
  319. }
  320. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="get_authToken")]
  321. [UDDIExtension( https=true, messageType="get_authToken" )]
  322. public AuthToken GetAuthToken( GetAuthToken gat )
  323. {
  324. Debug.Enter();
  325. AuthToken at = new AuthToken();
  326. try
  327. {
  328. //
  329. // XX-SECURITY: Review the value here in the case where we use
  330. // XX-this with a web.config with Authentication set to None or Passport
  331. //
  332. //
  333. // NOW: We now Get a Generic Identity. If the AuthenticationMode is AuthenticationMode.Passport (8),
  334. // we make sure the Identity is a PassportIdentity, then we authenticate. If AuthenticationMode
  335. // is Not set to AuthenticationMode.Passport, then process it as a WindowsIdentity.
  336. //
  337. //
  338. IIdentity identity = HttpContext.Current.User.Identity;
  339. int mode = Config.GetInt( "Security.AuthenticationMode", (int) AuthenticationMode.Both );
  340. if( ( (int) AuthenticationMode.Passport ) == mode )
  341. {
  342. if( identity is PassportIdentity )
  343. {
  344. Debug.Write( SeverityType.Info, CategoryType.Soap, "Generating credentials for Passport based authentication Identity is " + gat.UserID );
  345. PassportAuthenticator pa = new PassportAuthenticator();
  346. //
  347. // Get a Passport ticket for this user.
  348. //
  349. if( !pa.GetAuthenticationInfo( gat.UserID, gat.Cred, out at.AuthInfo ) )
  350. {
  351. // throw new UDDIException( ErrorType.E_unknownUser, "User failed authentication." ) ;
  352. throw new UDDIException( ErrorType.E_unknownUser, "USER_FAILED_AUTHENTICATION" ) ;
  353. }
  354. //
  355. // We need to extract the PUID from the ticket and put it into our Context.UserInfo.ID; a
  356. // successfull call to Authenticate will do all of this.
  357. //
  358. if( !pa.Authenticate( at.AuthInfo, UDDI.Constants.Passport.TimeWindow ) )
  359. {
  360. throw new UDDIException( ErrorType.E_unknownUser, "UDDI_ERROR_USER_FAILED_AUTHENTICATION" ) ;
  361. }
  362. //
  363. // Make sure this Passport user has registered with our UDDI site as a publisher.
  364. //
  365. if( !Context.User.IsVerified )
  366. {
  367. // throw new UDDIException( ErrorType.E_unknownUser, "Not a valid publisher." ) ;
  368. throw new UDDIException( ErrorType.E_unknownUser, "UDDI_ERROR_NOT_A_VALID_PUBLISHER" ) ;
  369. }
  370. }
  371. else
  372. {
  373. #if never
  374. throw new UDDIException( ErrorType.E_fatalError,
  375. "CONFIGURATION ERROR: Passport Identity Expected. \r\n"+
  376. "You are currently running in Passport Authentication Mode. \r\n"+
  377. "Check your web.config for the <authentication mode=\"Passport\" /> entry and try again." ) ;
  378. #endif
  379. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_PASSPORT_CONFIGURATION_ERROR" );
  380. }
  381. }
  382. //
  383. // SECURITY: Check to make sure the password is blank too
  384. //
  385. else if( !((WindowsIdentity)identity).IsAnonymous &&
  386. ( ( mode & (int) AuthenticationMode.Windows ) != 0 ) &&
  387. Utility.StringEmpty( gat.UserID ) )
  388. {
  389. Debug.Write( SeverityType.Info, CategoryType.Soap, "Generating credentials for Windows based authentication Identity is " + identity.Name );
  390. WindowsAuthenticator wa = new WindowsAuthenticator();
  391. wa.GetAuthenticationInfo( gat.UserID, gat.Cred, out at.AuthInfo );
  392. }
  393. else if( ( mode & (int) AuthenticationMode.Uddi ) != 0 )
  394. {
  395. Debug.Write( SeverityType.Info, CategoryType.Soap, "Generating credentials for UDDI based authentication" );
  396. UDDIAuthenticator ua = new UDDIAuthenticator();
  397. ua.GetAuthenticationInfo( gat.UserID, gat.Cred, out at.AuthInfo );
  398. }
  399. else
  400. {
  401. // throw new UDDIException( UDDI.ErrorType.E_unsupported,
  402. //"The UDDI server is not configured to support the requested form of authentication." );
  403. throw new UDDIException( UDDI.ErrorType.E_unsupported, "UDDI_ERROR_AUTHENTICATION_CONFIGURATION_ERROR" );
  404. }
  405. Debug.Write( SeverityType.Info, CategoryType.Soap, "Windows Identity is " + WindowsIdentity.GetCurrent().Name );
  406. Debug.Write( SeverityType.Info, CategoryType.Soap, "Thread Identity is " + System.Threading.Thread.CurrentPrincipal.Identity.Name );
  407. Debug.Write( SeverityType.Info, CategoryType.Soap, "HttpContext Identity is " + identity.Name );
  408. //
  409. // Check to make sure the authenticated user has publisher credentials
  410. //
  411. #if never
  412. Debug.Verify( Context.User.IsPublisher,
  413. "The user account " + Context.User.ID + " does not have publisher credentials",
  414. UDDI.ErrorType.E_fatalError );
  415. #endif
  416. Debug.Verify( Context.User.IsPublisher,
  417. "UDDI_ERROR_NO_PUBLISHER_CREDENTIALS",
  418. UDDI.ErrorType.E_fatalError,
  419. Context.User.ID );
  420. Debug.Write(
  421. SeverityType.Info,
  422. CategoryType.Authorization,
  423. "Authenticated user (userid = " + gat.UserID + " )" );
  424. }
  425. catch( Exception e )
  426. {
  427. DispositionReport.Throw( e );
  428. }
  429. return at;
  430. }
  431. /// ****************************************************************
  432. /// public class GetPublisherAssertions
  433. /// ----------------------------------------------------------------
  434. /// <summary>
  435. /// </summary>
  436. /// ****************************************************************
  437. ///
  438. [WebMethod]
  439. [SoapDocumentMethod( Action = "\"\"", RequestElementName = "get_publisherAssertions" )]
  440. [UDDIExtension( authenticate = true, https = true, messageType = "get_publisherAssertions" )]
  441. public PublisherAssertionDetail GetPublisherAssertions( GetPublisherAssertions message )
  442. {
  443. Debug.Enter();
  444. PublisherAssertionDetail detail = new PublisherAssertionDetail();
  445. try
  446. {
  447. detail.Get();
  448. }
  449. catch( Exception e )
  450. {
  451. DispositionReport.Throw( e );
  452. }
  453. Debug.Leave();
  454. return detail;
  455. }
  456. /// ****************************************************************
  457. /// public class GetRegisteredInfo
  458. /// ----------------------------------------------------------------
  459. /// <summary>
  460. /// </summary>
  461. /// ****************************************************************
  462. ///
  463. [WebMethod, SoapDocumentMethod( Action="\"\"", RequestElementName="get_registeredInfo" )]
  464. [UDDIExtension( authenticate=true, https=true, messageType="get_registeredInfo")]
  465. public RegisteredInfo GetRegisteredInfo( GetRegisteredInfo gri )
  466. {
  467. Debug.Enter();
  468. RegisteredInfo ri = new RegisteredInfo();
  469. try
  470. {
  471. ri.Get();
  472. }
  473. catch( Exception e )
  474. {
  475. DispositionReport.Throw( e );
  476. }
  477. return ri;
  478. }
  479. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="save_binding")]
  480. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="save_binding")]
  481. public BindingDetail SaveBinding( SaveBinding sb )
  482. {
  483. Debug.Enter();
  484. BindingDetail bd = new BindingDetail();
  485. try
  486. {
  487. sb.Save();
  488. bd.BindingTemplates = sb.BindingTemplates;
  489. }
  490. catch( Exception e )
  491. {
  492. DispositionReport.Throw( e );
  493. }
  494. return bd;
  495. }
  496. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="save_business")]
  497. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="save_business" )]
  498. public BusinessDetail SaveBusiness( SaveBusiness sb )
  499. {
  500. Debug.Enter();
  501. BusinessDetail bd = new BusinessDetail();
  502. try
  503. {
  504. sb.Save();
  505. bd.BusinessEntities = sb.BusinessEntities;
  506. }
  507. catch( Exception e )
  508. {
  509. DispositionReport.Throw( e );
  510. }
  511. return bd;
  512. }
  513. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="save_service")]
  514. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="save_service" )]
  515. public ServiceDetail SaveService( SaveService ss )
  516. {
  517. Debug.Enter();
  518. ServiceDetail sd = new ServiceDetail();
  519. try
  520. {
  521. ss.Save();
  522. sd.BusinessServices = ss.BusinessServices;
  523. }
  524. catch( Exception e )
  525. {
  526. DispositionReport.Throw( e );
  527. }
  528. return sd;
  529. }
  530. [WebMethod, SoapDocumentMethod(Action="\"\"", RequestElementName="save_tModel")]
  531. [UDDIExtension( authenticate=true, transaction=true, https=true, messageType="save_tModel" )]
  532. public TModelDetail SaveTModel( UDDI.API.ServiceType.SaveTModel stm )
  533. {
  534. Debug.Enter();
  535. TModelDetail tmd = new TModelDetail();
  536. try
  537. {
  538. stm.Save();
  539. tmd.TModels = stm.TModels;
  540. }
  541. catch( Exception e )
  542. {
  543. DispositionReport.Throw( e );
  544. }
  545. return tmd;
  546. }
  547. [WebMethod()]
  548. [SoapDocumentMethod( Action = "\"\"", RequestElementName = "set_publisherAssertions" )]
  549. [UDDIExtension( authenticate = true, transaction = true, https = true, messageType = "set_publisherAssertions" )]
  550. public PublisherAssertionDetail SetPublisherAssertions( SetPublisherAssertions message )
  551. {
  552. Debug.Enter();
  553. PublisherAssertionDetail detail = new PublisherAssertionDetail();
  554. try
  555. {
  556. detail = message.Set();
  557. }
  558. catch( Exception e )
  559. {
  560. DispositionReport.Throw( e );
  561. }
  562. Debug.Leave();
  563. return detail;
  564. }
  565. }
  566. }