예제 #1
0
        /// <summary>
        /// Ensures the user has entered login information.
        /// </summary>
        /// <remarks>
        /// If the user did not enter any information, UserCredential will be assigned the "anonymous" status.
        /// </remarks>
        public virtual void EnsureUserIsAuthenticated()
        {
            if (_current.Identity.IsAuthenticated)
            {
                return;
            }
            Debug.Assert(CurrentPrincipal != null);

            IExtensionPortManager manager = ApplicationManager.Current.ExtensionPortManager;
            IExtensionPort <ICredentialServiceExtenderContract> port;

            port = manager.GetExtensionPort <ICredentialServiceExtenderContract>();
            if (port.Extenders.Count() < 1)
            {
                throw new InvalidOperationException
                          ("No extender found for extension port ICredentialServiceExtenderContract.  The service is unable to ensure that user is authenticated by itself.");
            }

            foreach (IExtender <ICredentialServiceExtenderContract> extender in port.Extenders)
            {
                extender.GetImplementation().NegociateAuthentication(CurrentPrincipal);
                if (CurrentPrincipal.Identity.IsAuthenticated)
                {
                    return;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Starts the current service.
        /// </summary>
        public virtual void Start()
        {
            IExtensionPortManager manager = ApplicationManager.Current.ExtensionPortManager;

            if (manager.GetExtensionPort <ICredentialServiceExtenderContract>() == null)
            {
                manager.RegisterExtensionPort <ICredentialServiceExtenderContract>(new ExtensionPortBase <ICredentialServiceExtenderContract>());
            }

            //Create an anonymous user on service startup.
            _current = new SecurePrincipal();
            System.AppDomain.CurrentDomain.SetThreadPrincipal(_current);
        }