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.

863 lines
29 KiB

  1. using System;
  2. using System.Data;
  3. using System.IO;
  4. using System.Security.Principal;
  5. using System.Text;
  6. using System.Web;
  7. using System.Xml.Serialization;
  8. using System.Runtime.InteropServices;
  9. using UDDI.Diagnostics;
  10. namespace UDDI
  11. {
  12. public enum AuthenticationMode : int
  13. {
  14. None = 0,
  15. Uddi = 1,
  16. Windows = 2,
  17. AuthenticatedRead = 4,
  18. Passport = 8,
  19. Both = Uddi | Windows,
  20. WindowsWithAuthenticatedRead = Windows | AuthenticatedRead
  21. }
  22. /// ********************************************************************
  23. /// public enum ContextType
  24. /// --------------------------------------------------------------------
  25. /// <summary>
  26. /// </summary>
  27. /// ********************************************************************
  28. ///
  29. public enum ContextType
  30. {
  31. Other = 0,
  32. SOAP = 1,
  33. UserInterface = 2,
  34. Replication = 3
  35. }
  36. //
  37. // Used in replication to determine where the exception came from
  38. //
  39. public enum ExceptionSource
  40. {
  41. Other = 0,
  42. BrokenServiceProjection = 1,
  43. PublisherAssertion = 2
  44. }
  45. /// ********************************************************************
  46. /// public enum RoleType
  47. /// --------------------------------------------------------------------
  48. /// <summary>
  49. /// </summary>
  50. /// ********************************************************************
  51. ///
  52. public enum RoleType
  53. {
  54. Anonymous = 0,
  55. User = 1,
  56. Publisher = 2,
  57. Coordinator = 3,
  58. Administrator = 4
  59. }
  60. /// ********************************************************************
  61. /// public class Context
  62. /// --------------------------------------------------------------------
  63. /// <summary>
  64. /// </summary>
  65. /// ********************************************************************
  66. ///
  67. public class Context
  68. {
  69. [ThreadStatic]
  70. private static Context context = null;
  71. private ContextType contextType;
  72. private ExceptionSource exceptionSource;
  73. internal UserInfo userInfo;
  74. private Guid contextID;
  75. private int threadID;
  76. private int apiVersionMajor;
  77. private bool logChangeRecords = false;
  78. private DateTime timeStamp;
  79. private string remoteOperator = null;
  80. /// ****************************************************************
  81. /// private Context [constructor]
  82. /// ----------------------------------------------------------------
  83. /// <summary>
  84. /// </summary>
  85. /// ****************************************************************
  86. ///
  87. private Context()
  88. {
  89. //
  90. // SECURITY: These member variables are not initialized during construction
  91. //
  92. // apiVersionMajor
  93. // contextType
  94. //
  95. //
  96. // Verify that the operating system is supported.
  97. //
  98. Win32.OsVersionInfoEx osVersion = new Win32.OsVersionInfoEx();
  99. if( !Win32.GetVersionEx( osVersion ) )
  100. {
  101. #if never
  102. throw new UDDIException(
  103. ErrorType.E_fatalError,
  104. "Could not retrieve operating system version." );
  105. #endif
  106. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_COULD_NOT_RETRIEVE_OPERATING_SYSTEM_VERSION" );
  107. }
  108. if( ( Win32.ProductType.WindowsServer != osVersion.ProductType
  109. && Win32.ProductType.DomainController != osVersion.ProductType )
  110. || osVersion.MajorVersion < 5
  111. || ( 5 == osVersion.MajorVersion && osVersion.MinorVersion < 1 ) )
  112. {
  113. #if never
  114. throw new UDDIException(
  115. ErrorType.E_fatalError,
  116. "Microsoft UDDI Services is not supported on this platform." );
  117. #endif
  118. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_UNSUPPORTED_PLATFORM" );
  119. }
  120. #if never
  121. contextID = Guid.NewGuid();
  122. threadID = System.Threading.Thread.CurrentThread.GetHashCode();
  123. timeStamp = DateTime.UtcNow;
  124. userInfo = new UserInfo();
  125. #endif
  126. }
  127. /// ****************************************************************
  128. /// public Initialize
  129. /// ----------------------------------------------------------------
  130. /// <summary>
  131. /// Initialize per-request data for the context. This method
  132. /// MUST be called once per request. Multiple calls will
  133. /// re-initialize the contents of the current context.
  134. ///
  135. /// </summary>
  136. /// ****************************************************************
  137. public void Initialize()
  138. {
  139. //
  140. // Reset our state. apiVersionMajor is not reset since it will be set in our VersionSupportExtension
  141. //
  142. contextType = ContextType.Other;
  143. exceptionSource = ExceptionSource.Other;
  144. userInfo = new UserInfo();
  145. contextID = Guid.NewGuid();
  146. threadID = System.Threading.Thread.CurrentThread.GetHashCode();
  147. //
  148. // 738148 - To reduce disk usage, make it configurable as to whether we log change records or not.
  149. //
  150. logChangeRecords = Config.GetInt( "LogChangeRecords", 0 ) == 0 ? false : true;
  151. timeStamp = DateTime.UtcNow;
  152. remoteOperator = null;
  153. //
  154. // In our log, we should never ever see multiple calls to this method
  155. // in the same application_request_started/application_request_ended blocks (see global.asax)
  156. // In the event log, correct behaviour is:
  157. // application_request started:
  158. // "Context.Initialize" message
  159. // ... (any number of messages)
  160. // application_request ended
  161. //
  162. Debug.Write( SeverityType.Info,
  163. CategoryType.Soap,
  164. "Context.Initialize" );
  165. }
  166. /// ****************************************************************
  167. /// public Current [static]
  168. /// ----------------------------------------------------------------
  169. /// <summary>
  170. /// Returns the current Context instance. This is either
  171. /// the Context instance that is associated with the
  172. /// current HttpContext, or the instance that is associated with
  173. /// the thread.
  174. /// </summary>
  175. /// ****************************************************************
  176. ///
  177. public static Context Current
  178. {
  179. get
  180. {
  181. HttpContext httpContext = HttpContext.Current;
  182. if( null == httpContext )
  183. {
  184. //
  185. // There is no HttpContext, so we must be running within
  186. // the context of an application. In such cases, we
  187. // create a message context for each thread.
  188. //
  189. if( null == context )
  190. {
  191. context = new Context();
  192. //
  193. // Since we are running in an application, we want to initialize each
  194. // instance that we create.
  195. //
  196. context.Initialize();
  197. }
  198. }
  199. else
  200. {
  201. //
  202. // Check to see if the we have seen this HttpContext
  203. // before. If not, we create a new message context and
  204. // mark the HttpContext.
  205. //
  206. if( null == httpContext.Items[ "UddiContext" ] || !( httpContext.Items[ "UddiContext" ] is Context ) )
  207. httpContext.Items.Add( "UddiContext", new Context() );
  208. context = (Context)httpContext.Items[ "UddiContext" ];
  209. }
  210. return context;
  211. }
  212. }
  213. /// ****************************************************************
  214. /// public LogChangeRecords [static]
  215. /// ----------------------------------------------------------------
  216. /// <summary>
  217. /// Specifies whether change records should be generated when
  218. /// updating registry data.
  219. /// </summary>
  220. /// ****************************************************************
  221. ///
  222. public static bool LogChangeRecords
  223. {
  224. get { return Current.logChangeRecords; }
  225. set
  226. {
  227. Debug.Verify( User.IsAdministrator, "UDDI_ERROR_FATALERROR_CONTEXT_SETLOGCHANGESNOTADMIN" );
  228. Current.logChangeRecords = value;
  229. }
  230. }
  231. /// ****************************************************************
  232. /// public TimeStamp [static]
  233. /// ----------------------------------------------------------------
  234. /// <summary>
  235. /// Gets or sets the context timestamp.
  236. /// </summary>
  237. /// ****************************************************************
  238. ///
  239. //
  240. // TODO: Why not use a field for this instead of a property
  241. //
  242. public static DateTime TimeStamp
  243. {
  244. get { return Current.timeStamp; }
  245. set { Current.timeStamp = value; }
  246. }
  247. /// ****************************************************************
  248. /// public RemoteOperator [static]
  249. /// ----------------------------------------------------------------
  250. /// <summary>
  251. /// Gets or sets the context remote operator.
  252. /// </summary>
  253. /// ****************************************************************
  254. ///
  255. //
  256. // TODO: Why not use a field for this instead of a property
  257. //
  258. public static string RemoteOperator
  259. {
  260. get { return Current.remoteOperator; }
  261. set { Current.remoteOperator = value; }
  262. }
  263. /// ****************************************************************
  264. /// public User [static]
  265. /// ----------------------------------------------------------------
  266. /// <summary>
  267. /// Returns the UserInfo associated with the current
  268. /// Context instance.
  269. /// </summary>
  270. /// ****************************************************************
  271. ///
  272. //
  273. // TODO: Why not use a field for this instead of a property
  274. //
  275. public static UserInfo User
  276. {
  277. get { return Current.userInfo; }
  278. set { Current.userInfo = value; }
  279. }
  280. /// ****************************************************************
  281. /// public ContextID [static]
  282. /// ----------------------------------------------------------------
  283. /// <summary>
  284. /// Returns the ContextID associated with the current
  285. /// Context instance.
  286. /// </summary>
  287. /// ****************************************************************
  288. ///
  289. public static Guid ContextID
  290. {
  291. get { return Current.contextID; }
  292. }
  293. /// ****************************************************************
  294. /// public ThreadID [static]
  295. /// ----------------------------------------------------------------
  296. /// <summary>
  297. /// Returns the ThreadID associated with the current
  298. /// Context instance.
  299. /// </summary>
  300. /// ****************************************************************
  301. ///
  302. public static int ThreadID
  303. {
  304. get { return Current.threadID; }
  305. }
  306. /// ****************************************************************
  307. /// public ContextType [static]
  308. /// ----------------------------------------------------------------
  309. /// <summary>
  310. /// Gets/sets the ContextType associated with the current
  311. /// Context instance.
  312. /// </summary>
  313. /// ****************************************************************
  314. ///
  315. //
  316. // TODO: Why not use a field for this instead of a property
  317. //
  318. public static UDDI.ContextType ContextType
  319. {
  320. get { return Current.contextType; }
  321. set { Current.contextType = value; }
  322. }
  323. public static UDDI.ExceptionSource ExceptionSource
  324. {
  325. get { return Current.exceptionSource; }
  326. set { Current.exceptionSource = value; }
  327. }
  328. /// ****************************************************************
  329. /// public ApiVersionMajor [static]
  330. /// ----------------------------------------------------------------
  331. /// <summary>
  332. /// Returns the major version number of the request associated
  333. /// with the current Context instance.
  334. /// </summary>
  335. /// ****************************************************************
  336. ///
  337. //
  338. // TODO: Why not use a field for this instead of a property
  339. //
  340. public static int ApiVersionMajor
  341. {
  342. get { return Current.apiVersionMajor; }
  343. set { Current.apiVersionMajor = value; }
  344. }
  345. }
  346. /// ********************************************************************
  347. /// public class UserInfo
  348. /// --------------------------------------------------------------------
  349. /// <summary>
  350. /// Stores information about an authenticated publisher.
  351. /// </summary>
  352. /// ********************************************************************
  353. ///
  354. //
  355. // SECURITY: Could probably use some SALT to fuzzy up the content
  356. // of this class when serialized as a ticket/token
  357. //
  358. public class UserInfo
  359. {
  360. //
  361. // pInvoke stuff to work with the SID strings
  362. //
  363. [DllImport("ADVAPI32.DLL", EntryPoint="ConvertStringSidToSidW",
  364. SetLastError=true,
  365. CharSet=CharSet.Unicode, ExactSpelling=true,
  366. CallingConvention=CallingConvention.StdCall)]
  367. public static extern int ConvertStringSidToSid( string sidStr, out IntPtr psid );
  368. [DllImport("ADVAPI32.DLL", EntryPoint="LookupAccountSidW",
  369. SetLastError=true,
  370. CharSet=CharSet.Unicode, ExactSpelling=true,
  371. CallingConvention=CallingConvention.StdCall)]
  372. public static extern int LookupAccountSid( string systemName,
  373. IntPtr psid,
  374. StringBuilder acctName,
  375. out int cbAcctName,
  376. StringBuilder domainName,
  377. out int cbDomainName,
  378. out int sidUse );
  379. [XmlAttribute( "a" )]
  380. public Guid guid = Guid.NewGuid();
  381. [XmlElement( "created", DataType="dateTime" )]
  382. public DateTime created = DateTime.Now;
  383. [XmlAttribute( "Role" )]
  384. public RoleType Role = RoleType.Anonymous;
  385. [XmlAttribute( "ID" )]
  386. public string ID = null;
  387. [XmlAttribute( "Language" )]
  388. public string IsoLangCode = "en";
  389. [XmlIgnore()]
  390. public string ImpersonatorID = null;
  391. [XmlIgnore()]
  392. public string Name = null;
  393. [XmlIgnore()]
  394. public string Email = null;
  395. [XmlIgnore()]
  396. public string Phone = null;
  397. [XmlIgnore()]
  398. public string CompanyName = null;
  399. [XmlIgnore()]
  400. public string AltPhone = null;
  401. [XmlIgnore()]
  402. public string AddressLine1 = null;
  403. [XmlIgnore()]
  404. public string AddressLine2 = null;
  405. [XmlIgnore()]
  406. public string City = null;
  407. [XmlIgnore()]
  408. public string StateProvince = null;
  409. [XmlIgnore()]
  410. public string PostalCode = null;
  411. [XmlIgnore()]
  412. public string Country = null;
  413. [XmlIgnore()]
  414. public bool TrackPassport = true;
  415. [XmlIgnore()]
  416. public bool Verified = false;
  417. [XmlIgnore()]
  418. public int BusinessLimit = 0;
  419. [XmlIgnore()]
  420. public int BusinessCount = 0;
  421. [XmlIgnore()]
  422. public int TModelLimit = 0;
  423. [XmlIgnore()]
  424. public int TModelCount = 0;
  425. [XmlIgnore()]
  426. public int ServiceLimit = 0;
  427. [XmlIgnore()]
  428. public int BindingLimit = 0;
  429. [XmlIgnore()]
  430. public int AssertionLimit = 0;
  431. [XmlIgnore()]
  432. public int AssertionCount = 0;
  433. [XmlIgnore()]
  434. public bool AllowPreassignedKeys = false;
  435. /// ****************************************************************
  436. /// public IsInRole [static]
  437. /// ----------------------------------------------------------------
  438. /// <summary>
  439. /// Checks membership of the windows identity of the current
  440. /// thread in a Windows Group.
  441. /// </summary>
  442. /// ****************************************************************
  443. ///
  444. public bool IsInRole( string strSID )
  445. {
  446. WindowsPrincipal prin = new WindowsPrincipal( WindowsIdentity.GetCurrent() );
  447. return IsInRole( strSID, prin );
  448. }
  449. public bool IsInRole( string strSID, IPrincipal principal )
  450. {
  451. return principal.IsInRole( GroupNameFromSid( strSID ) );
  452. }
  453. public string GroupNameFromSid( string strSid )
  454. {
  455. IntPtr psid;
  456. StringBuilder szstrSid = new StringBuilder( strSid );
  457. StringBuilder domainName = new StringBuilder( 1024 );
  458. StringBuilder acctName = new StringBuilder( 1024 );
  459. int cbDomainName = 1024;
  460. int cbAcctName = 1024;
  461. int sidUse = -1;
  462. int iRet = ConvertStringSidToSid( strSid, out psid );
  463. if( 0 == iRet )
  464. {
  465. // throw new UDDIException( ErrorType.E_fatalError, "An attempt to convert a security id to a group name failed. ConvertStringSidToSid failed. " );
  466. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_SID_CONVERSION_FAILED" );
  467. }
  468. iRet = LookupAccountSid( null, psid, acctName, out cbAcctName, domainName, out cbDomainName, out sidUse );
  469. if( 0 == iRet )
  470. {
  471. //throw new UDDIException( ErrorType.E_fatalError, "An attempt to convert a security id to a group name failed. An attempt to LookupAccountSid failed." );
  472. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_SID_LOOKUP_FAILED" );
  473. }
  474. return domainName.ToString() + "\\" + acctName.ToString();
  475. }
  476. /// ****************************************************************
  477. /// public IsUser
  478. /// ----------------------------------------------------------------
  479. /// <summary>
  480. /// </summary>
  481. /// ****************************************************************
  482. ///
  483. public bool IsUser
  484. {
  485. get { return Role >= RoleType.User; }
  486. }
  487. /// ****************************************************************
  488. /// public IsPublisher
  489. /// ----------------------------------------------------------------
  490. /// <summary>
  491. /// </summary>
  492. /// ****************************************************************
  493. ///
  494. public bool IsPublisher
  495. {
  496. get { return Role >= RoleType.Publisher; }
  497. }
  498. /// ****************************************************************
  499. /// public IsCoordinator
  500. /// ----------------------------------------------------------------
  501. /// <summary>
  502. /// </summary>
  503. /// ****************************************************************
  504. ///
  505. public bool IsCoordinator
  506. {
  507. get { return Role >= RoleType.Coordinator; }
  508. }
  509. /// ****************************************************************
  510. /// public IsAdministrator
  511. /// ----------------------------------------------------------------
  512. /// <summary>
  513. /// </summary>
  514. /// ****************************************************************
  515. ///
  516. public bool IsAdministrator
  517. {
  518. get { return Role >= RoleType.Administrator; }
  519. }
  520. /// ****************************************************************
  521. /// public IsImpersonated
  522. /// ----------------------------------------------------------------
  523. /// <summary>
  524. /// </summary>
  525. /// ****************************************************************
  526. ///
  527. public bool IsImpersonated
  528. {
  529. get
  530. {
  531. return ( null != ImpersonatorID && ID != ImpersonatorID );
  532. }
  533. }
  534. /// ****************************************************************
  535. /// public Register [static]
  536. /// ----------------------------------------------------------------
  537. /// <summary>
  538. /// </summary>
  539. /// ****************************************************************
  540. ///
  541. public void Register()
  542. {
  543. Debug.Enter();
  544. //
  545. // If the Name has not been populated during authentication
  546. // use the ID. This is needed to populate the authorizedName
  547. // field.
  548. //
  549. if( null == Name || 0 == Name.Length )
  550. {
  551. Name = ID;
  552. }
  553. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "UI_savePublisher" );
  554. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  555. sp.Parameters.Add( "@isoLangCode", SqlDbType.NVarChar, UDDI.Constants.Lengths.IsoLangCode );
  556. sp.Parameters.Add( "@name", SqlDbType.NVarChar, UDDI.Constants.Lengths.Name );
  557. sp.Parameters.Add( "@email", SqlDbType.NVarChar, UDDI.Constants.Lengths.Email );
  558. sp.Parameters.Add( "@phone", SqlDbType.NVarChar, UDDI.Constants.Lengths.Phone );
  559. sp.Parameters.Add( "@companyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.CompanyName );
  560. sp.Parameters.Add( "@altphone", SqlDbType.NVarChar, UDDI.Constants.Lengths.Phone );
  561. sp.Parameters.Add( "@addressLine1", SqlDbType.NVarChar, UDDI.Constants.Lengths.AddressLine );
  562. sp.Parameters.Add( "@addressLine2", SqlDbType.NVarChar, UDDI.Constants.Lengths.AddressLine );
  563. sp.Parameters.Add( "@city", SqlDbType.NVarChar, UDDI.Constants.Lengths.City );
  564. sp.Parameters.Add( "@stateProvince", SqlDbType.NVarChar, UDDI.Constants.Lengths.StateProvince );
  565. sp.Parameters.Add( "@postalCode", SqlDbType.NVarChar, UDDI.Constants.Lengths.PostalCode );
  566. sp.Parameters.Add( "@country", SqlDbType.NVarChar, UDDI.Constants.Lengths.Country );
  567. sp.Parameters.Add( "@flag", SqlDbType.Int );
  568. sp.Parameters.Add( "@tier", SqlDbType.NVarChar, UDDI.Constants.Lengths.Tier );
  569. sp.Parameters.SetString( "@PUID", ID );
  570. sp.Parameters.SetString( "@isoLangCode", IsoLangCode );
  571. sp.Parameters.SetString( "@name", Name );
  572. sp.Parameters.SetString( "@email", Email );
  573. sp.Parameters.SetString( "@phone", Phone );
  574. sp.Parameters.SetString( "@companyName", CompanyName );
  575. sp.Parameters.SetString( "@altphone", AltPhone );
  576. sp.Parameters.SetString( "@addressLine1", AddressLine1 );
  577. sp.Parameters.SetString( "@addressLine2", AddressLine2 );
  578. sp.Parameters.SetString( "@city", City );
  579. sp.Parameters.SetString( "@stateProvince", StateProvince );
  580. sp.Parameters.SetString( "@postalCode", PostalCode );
  581. sp.Parameters.SetString( "@country", Country );
  582. sp.Parameters.SetString( "@tier", Config.GetString( "Publisher.DefaultTier", "2" ) );
  583. int flag = 0;
  584. //
  585. // TODO: Comments or an enumeration please
  586. //
  587. if( !TrackPassport )
  588. flag = flag | 0x02;
  589. if( Verified )
  590. flag = flag | 0x01;
  591. sp.Parameters.SetInt( "@flag", flag );
  592. sp.ExecuteNonQuery();
  593. Debug.Leave();
  594. }
  595. /// ****************************************************************
  596. /// public IsRegistered
  597. /// ----------------------------------------------------------------
  598. /// <summary>
  599. /// Determines whether the current user is registered as a
  600. /// publisher.
  601. /// </summary>
  602. /// ****************************************************************
  603. ///
  604. public bool IsRegistered
  605. {
  606. get
  607. {
  608. Debug.Enter();
  609. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_publisher_isRegistered" );
  610. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  611. sp.Parameters.Add( "@returnValue", SqlDbType.Int, ParameterDirection.ReturnValue );
  612. sp.Parameters.SetString( "@PUID", ID );
  613. sp.ExecuteNonQuery();
  614. int returnValue = sp.Parameters.GetInt( "@returnValue" );
  615. Debug.Leave();
  616. return ( 0 == returnValue );
  617. }
  618. }
  619. /// ****************************************************************
  620. /// public IsVerified
  621. /// ----------------------------------------------------------------
  622. /// <summary>
  623. /// Determines whether the current user is registered as a
  624. /// publisher.
  625. /// </summary>
  626. /// ****************************************************************
  627. ///
  628. public bool IsVerified
  629. {
  630. get
  631. {
  632. Debug.Enter();
  633. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_publisher_isVerified" );
  634. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  635. sp.Parameters.Add( "@returnValue", SqlDbType.Int, ParameterDirection.ReturnValue );
  636. sp.Parameters.SetString( "@PUID", ID );
  637. sp.ExecuteNonQuery();
  638. int returnValue = sp.Parameters.GetInt( "@returnValue" );
  639. Debug.Leave();
  640. return ( 0 == returnValue );
  641. }
  642. }
  643. /// ****************************************************************
  644. /// public Login
  645. /// ----------------------------------------------------------------
  646. /// <summary>
  647. /// Logs the current user in.
  648. /// </summary>
  649. /// ****************************************************************
  650. ///
  651. public void Login()
  652. {
  653. Debug.Enter();
  654. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_publisher_login" );
  655. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID );
  656. sp.Parameters.Add( "@email", SqlDbType.NVarChar, UDDI.Constants.Lengths.Email, ParameterDirection.InputOutput );
  657. sp.Parameters.Add( "@name", SqlDbType.NVarChar, UDDI.Constants.Lengths.Name, ParameterDirection.Output );
  658. sp.Parameters.Add( "@phone", SqlDbType.VarChar, UDDI.Constants.Lengths.Phone, ParameterDirection.Output );
  659. sp.Parameters.Add( "@companyName", SqlDbType.NVarChar, UDDI.Constants.Lengths.CompanyName, ParameterDirection.Output );
  660. sp.Parameters.Add( "@altPhone", SqlDbType.VarChar, UDDI.Constants.Lengths.Phone, ParameterDirection.Output );
  661. sp.Parameters.Add( "@addressLine1", SqlDbType.NVarChar, UDDI.Constants.Lengths.AddressLine, ParameterDirection.Output );
  662. sp.Parameters.Add( "@addressLine2", SqlDbType.NVarChar, UDDI.Constants.Lengths.AddressLine, ParameterDirection.Output );
  663. sp.Parameters.Add( "@city", SqlDbType.NVarChar, UDDI.Constants.Lengths.City, ParameterDirection.Output );
  664. sp.Parameters.Add( "@stateProvince", SqlDbType.NVarChar, UDDI.Constants.Lengths.StateProvince, ParameterDirection.Output );
  665. sp.Parameters.Add( "@postalCode", SqlDbType.NVarChar, UDDI.Constants.Lengths.PostalCode, ParameterDirection.Output );
  666. sp.Parameters.Add( "@country", SqlDbType.NVarChar, UDDI.Constants.Lengths.Country, ParameterDirection.Output );
  667. sp.Parameters.Add( "@isoLangCode", SqlDbType.VarChar, UDDI.Constants.Lengths.IsoLangCode, ParameterDirection.Output );
  668. sp.Parameters.Add( "@businessLimit", SqlDbType.Int, ParameterDirection.Output );
  669. sp.Parameters.Add( "@businessCount", SqlDbType.Int, ParameterDirection.Output );
  670. sp.Parameters.Add( "@tModelLimit", SqlDbType.Int, ParameterDirection.Output );
  671. sp.Parameters.Add( "@tModelCount", SqlDbType.Int, ParameterDirection.Output );
  672. sp.Parameters.Add( "@serviceLimit", SqlDbType.Int, ParameterDirection.Output );
  673. sp.Parameters.Add( "@bindingLimit", SqlDbType.Int, ParameterDirection.Output );
  674. sp.Parameters.Add( "@assertionLimit", SqlDbType.Int, ParameterDirection.Output );
  675. sp.Parameters.Add( "@assertionCount", SqlDbType.Int, ParameterDirection.Output );
  676. sp.Parameters.SetString( "@PUID", ID );
  677. sp.Parameters.SetString( "@email", Email );
  678. sp.ExecuteNonQuery();
  679. Email = sp.Parameters.GetString( "@email" );
  680. Name = sp.Parameters.GetString( "@name" );
  681. Phone = sp.Parameters.GetString( "@phone" );
  682. CompanyName = sp.Parameters.GetString( "@companyName" );
  683. AltPhone = sp.Parameters.GetString( "@altPhone" );
  684. AddressLine1 = sp.Parameters.GetString( "@addressLine1" );
  685. AddressLine2 = sp.Parameters.GetString( "@addressLine2" );
  686. City = sp.Parameters.GetString( "@city" );
  687. StateProvince = sp.Parameters.GetString( "@stateProvince" );
  688. PostalCode = sp.Parameters.GetString( "@postalCode" );
  689. Country = sp.Parameters.GetString( "@country" );
  690. IsoLangCode = sp.Parameters.GetString( "@isoLangCode" );
  691. BusinessLimit = sp.Parameters.GetInt( "@businessLimit" );
  692. BusinessCount = sp.Parameters.GetInt( "@businessCount" );
  693. TModelLimit = sp.Parameters.GetInt( "@tModelLimit" );
  694. TModelCount = sp.Parameters.GetInt( "@tModelCount" );
  695. ServiceLimit = sp.Parameters.GetInt( "@serviceLimit" );
  696. BindingLimit = sp.Parameters.GetInt( "@bindingLimit" );
  697. AssertionLimit = sp.Parameters.GetInt( "@assertionLimit" );
  698. AssertionCount = sp.Parameters.GetInt( "@assertionCount" );
  699. Debug.Leave();
  700. }
  701. public void Serialize( Stream stream )
  702. {
  703. //
  704. // Serialize it as XML into a stream
  705. //
  706. StreamWriter writer = new StreamWriter( stream, Encoding.UTF8 );
  707. XmlSerializer serializer = new XmlSerializer( typeof( UserInfo ) );
  708. serializer.Serialize( writer, this );
  709. writer.Flush();
  710. stream.Position = 0;
  711. }
  712. public void CheckAge( int timeWindow )
  713. {
  714. TimeSpan duration = DateTime.Now - created;
  715. Debug.Write( SeverityType.Info,
  716. CategoryType.Authorization,
  717. "Ticket is dated: " + created.ToLongDateString() + ", " + created.ToLongTimeString() );
  718. if( duration.TotalMinutes > timeWindow )
  719. {
  720. #if never
  721. throw new UDDIException( UDDI.ErrorType.E_authTokenExpired,
  722. "The submitted credentials have expired." );
  723. #endif
  724. throw new UDDIException( UDDI.ErrorType.E_authTokenExpired, "UDDI_ERROR_CREDENTIALS_EXPIRED" );
  725. }
  726. }
  727. public void SetPublisherRole( string userID )
  728. {
  729. Role = RoleType.Publisher;
  730. ID = userID;
  731. }
  732. public void SetRole( IPrincipal principal )
  733. {
  734. //
  735. // Determine the role of the caller and assign it into the user object
  736. //
  737. if( IsInRole( Config.GetString( "GroupName.Administrators", "S-1-5-32-544" ), principal ) )
  738. {
  739. Role = RoleType.Administrator;
  740. }
  741. else if( IsInRole( Config.GetString( "GroupName.Coordinators", "S-1-5-32-544" ), principal ) )
  742. {
  743. Role = RoleType.Coordinator;
  744. }
  745. else if( IsInRole( Config.GetString( "GroupName.Publishers", "S-1-5-32-544" ), principal ) )
  746. {
  747. Role = RoleType.Publisher;
  748. }
  749. else if( IsInRole( Config.GetString( "GroupName.Users", "S-1-5-32-545" ), principal ) )
  750. {
  751. Role = RoleType.User;
  752. }
  753. else
  754. {
  755. Role = RoleType.Anonymous;
  756. }
  757. ID = principal.Identity.Name;
  758. Name = ID;
  759. }
  760. public void SetAllowPreassignedKeys( bool flag )
  761. {
  762. AllowPreassignedKeys = flag;
  763. }
  764. }
  765. }