public EmailPassword(IPortalApplication portalApplication, IAuthenticationRepository authenticationRepository,
		                     PasswordSettings settings, IAuthenticationModule authenticationModule) : base(portalApplication)
		{
			AuthenticationRepository = authenticationRepository;
			Settings = settings;
			AuthenticationModule = authenticationModule;
		}
        public static void Main()
        {
            try
            {
// <Snippet1>
// <Snippet2>
                IEnumerator registeredModules = AuthenticationManager.RegisteredModules;
                // Display all the modules that are already registered with the system.
                DisplayAllModules();
                registeredModules.Reset();
                registeredModules.MoveNext();
                // Get the first Authentication module registered with the system.
                IAuthenticationModule authenticationModule1 = (IAuthenticationModule)registeredModules.Current;
                // Call the UnRegister() method to unregister the first authentication module from the system.
                String authenticationScheme = authenticationModule1.AuthenticationType;
                AuthenticationManager.Unregister(authenticationScheme);
                Console.WriteLine("\nSuccessfully unregistered '{0}", authenticationModule1 + "'.");
                // Display all modules to see that the module was unregistered.
                DisplayAllModules();
// </Snippet2>
                // Calling 'Register()' method to register 'authenticationModule1'  module back again.
                AuthenticationManager.Register(authenticationModule1);
                Console.WriteLine("\nSuccessfully re-registered '{0}", authenticationModule1 + "'.");
                // Display the modules to verify that 'authenticationModule1' has been registered back again.
                DisplayAllModules();
// </Snippet1>
                Console.WriteLine("Press any key to continue");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("\n The following Exception was raised : {0}", e.Message);
            }
        }
Example #3
0
 public static void Unregister(IAuthenticationModule authenticationModule)
 {
     if (authenticationModule is null)
     {
         throw new ArgumentNullException(nameof(authenticationModule));
     }
 }
Example #4
0
        static void DoUnregister(string authenticationScheme, bool throwEx)
        {
            EnsureModules();
            lock (modules) {
                IAuthenticationModule module = null;
                foreach (IAuthenticationModule mod in modules)
                {
                    string modtype = mod.AuthenticationType;
                    if (String.Compare(modtype, authenticationScheme, true) == 0)
                    {
                        module = mod;
                        break;
                    }
                }

                if (module == null)
                {
                    if (throwEx)
                    {
                        throw new InvalidOperationException("Scheme not registered.");
                    }
                }
                else
                {
                    modules.Remove(module);
                }
            }
        }
Example #5
0
        /// <devdoc>
        ///    <para>Unregisters authentication modules for an authentication scheme.</para>
        /// </devdoc>
        public static void Unregister(IAuthenticationModule authenticationModule)
        {
#if FEATURE_MONO_CAS
            ExceptionHelper.UnmanagedPermission.Demand();
#endif
            Instance.Unregister(authenticationModule);
        }
		public Wayf(IPortalApplication portalApplication, IAuthenticationRepository authenticationRepository,
		            IWayfFilter wayfFilter, IAuthenticationModule authenticationModule) : base(portalApplication)
		{
			_wayfFilter = wayfFilter;
			AuthenticationRepository = authenticationRepository;
			AuthenticationModule = authenticationModule;
		}
        /// <devdoc>
        ///    <para>
        ///       Binds an authentication response to a request for pre-authentication.
        ///    </para>
        /// </devdoc>
        // Create binding between an authorization response and the module
        // generating that response
        // This association is used for deciding which module to invoke
        // for preauthentication purposes
        public override void BindModule(Uri uri, Authorization response, IAuthenticationModule module)
        {
            GlobalLog.Assert(
                module.CanPreAuthenticate,
                "AuthenticationManager::BindModule()|module.CanPreAuthenticate == false");

            if (response.ProtectionRealm != null)
            {
                // The authentication module specified which Uri prefixes
                // will be preauthenticated
                string[] prefix = response.ProtectionRealm;

                for (int k = 0; k < prefix.Length; k++)
                {
                    //
                    // PrefixLookup is thread-safe
                    //
                    moduleBinding.Add(prefix[k], module.AuthenticationType);
                }
            }
            else
            {
                // Otherwise use the default policy for "fabricating"
                // some protection realm generalizing the particular Uri
                string prefix = generalize(uri);
                //
                // PrefixLookup is thread-safe
                //
                moduleBinding.Add(prefix, module.AuthenticationType);
            }
        }
Example #8
0
        /// <devdoc>
        ///    <para>Unregisters authentication modules for an authentication scheme.</para>
        /// </devdoc>
        public static void Unregister(IAuthenticationModule authenticationModule)
        {
#if !DISABLE_CAS_USE
            ExceptionHelper.UnmanagedPermission.Demand();
#endif
            Instance.Unregister(authenticationModule);
        }
Example #9
0
        public virtual bool ShouldSendCredential(Uri challengeUri, WebRequest request,
                                                 NetworkCredential credential, IAuthenticationModule authenticationModule)
        {
            Zone z = Zone.CreateFromUrl(challengeUri.AbsoluteUri);

            return(z.SecurityZone == SecurityZone.Intranet);
        }
Example #10
0
 public NtlmClient()
 {
     if (ntlmAuthType != null)
     {
         authObject = (IAuthenticationModule)Activator.CreateInstance(ntlmAuthType);
     }
 }
        private static void DoUnregister(string authenticationScheme, bool throwEx)
        {
            AuthenticationManager.EnsureModules();
            ArrayList obj = AuthenticationManager.modules;

            lock (obj)
            {
                IAuthenticationModule authenticationModule = null;
                foreach (object obj2 in AuthenticationManager.modules)
                {
                    IAuthenticationModule authenticationModule2 = (IAuthenticationModule)obj2;
                    string authenticationType = authenticationModule2.AuthenticationType;
                    if (string.Compare(authenticationType, authenticationScheme, true) == 0)
                    {
                        authenticationModule = authenticationModule2;
                        break;
                    }
                }
                if (authenticationModule == null)
                {
                    if (throwEx)
                    {
                        throw new InvalidOperationException("Scheme not registered.");
                    }
                }
                else
                {
                    AuthenticationManager.modules.Remove(authenticationModule);
                }
            }
        }
        internal void ClearSession(HttpWebRequest httpWebRequest)
        {
            PrepareState(httpWebRequest);
            ISessionAuthenticationModule myModule = Module as ISessionAuthenticationModule;

            Module = null;

            if (myModule != null)
            {
                try {
                    myModule.ClearSession(httpWebRequest);
                }
                catch (Exception exception) {
                    if (NclUtilities.IsFatal(exception))
                    {
                        throw;
                    }

                    GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::ClearSession() " + myModule.ToString() + ".Update() caught exception:" + exception.Message);
                }
                catch {
                    GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::ClearSession() " + myModule.ToString() + ".Update() caught exception: Non-CLS Compliant Exception");
                }
            }
        }
        /// <summary>Preauthenticates a request.</summary>
        /// <returns>An instance of the <see cref="T:System.Net.Authorization" /> class if the request can be preauthenticated; otherwise, null. If <paramref name="credentials" /> is null, this method returns null.</returns>
        /// <param name="request">A <see cref="T:System.Net.WebRequest" /> to an Internet resource. </param>
        /// <param name="credentials">The <see cref="T:System.Net.ICredentials" /> associated with the request. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="request" /> is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" />
        /// </PermissionSet>
        public static Authorization PreAuthenticate(WebRequest request, ICredentials credentials)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (credentials == null)
            {
                return(null);
            }
            AuthenticationManager.EnsureModules();
            ArrayList obj = AuthenticationManager.modules;

            lock (obj)
            {
                foreach (object obj2 in AuthenticationManager.modules)
                {
                    IAuthenticationModule authenticationModule = (IAuthenticationModule)obj2;
                    Authorization         authorization        = authenticationModule.PreAuthenticate(request, credentials);
                    if (authorization != null)
                    {
                        authorization.Module = authenticationModule;
                        return(authorization);
                    }
                }
            }
            return(null);
        }
Example #14
0
        static void EnsureModules()
        {
            lock (locker) {
                if (modules != null)
                {
                    return;
                }

                modules = new ArrayList();
#if NET_2_1
                modules.Add(new NtlmClient());
                modules.Add(new DigestClient());
                modules.Add(new BasicClient());
#elif CONFIGURATION_DEP
                object cfg = ConfigurationManager.GetSection("system.net/authenticationModules");
                AuthenticationModulesSection s = cfg as AuthenticationModulesSection;
                if (s != null)
                {
                    foreach (AuthenticationModuleElement element in s.AuthenticationModules)
                    {
                        IAuthenticationModule module = null;
                        try {
                            Type type = Type.GetType(element.Type, true);
                            module = (IAuthenticationModule)Activator.CreateInstance(type);
                        } catch {}
                        modules.Add(module);
                    }
                }
#else
                ConfigurationSettings.GetConfig("system.net/authenticationModules");
#endif
            }
        }
Example #15
0
 /// <summary>Removes the specified authentication module from the list of registered modules.</summary>
 /// <param name="authenticationModule">The <see cref="T:System.Net.IAuthenticationModule" /> to remove from the list of registered modules. </param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="authenticationModule" /> is null. </exception>
 /// <exception cref="T:System.InvalidOperationException">The specified <see cref="T:System.Net.IAuthenticationModule" /> is not registered. </exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public static void Unregister(IAuthenticationModule authenticationModule)
 {
     if (authenticationModule == null)
     {
         throw new ArgumentNullException("authenticationModule");
     }
     DoUnregister(authenticationModule.AuthenticationType, throwEx: true);
 }
 /// <include file='doc\AuthenticationManager.uex' path='docs/doc[@for="ConnectionGroupAuthentication.GetGroupAuthorization"]/*' />
 internal static Authorization GetGroupAuthorization(IAuthenticationModule thisModule, string token, bool finished, NTAuthentication authSession, bool shareAuthenticatedConnections)
 {
     return
         (new Authorization(
              token,
              finished,
              (shareAuthenticatedConnections) ? null : (thisModule.GetType().FullName + "/" + authSession.UniqueUserId)));
 }
 internal NTAuthentication GetSecurityContext(IAuthenticationModule module)
 {
     if (module != this.Module)
     {
         return(null);
     }
     return(this.SecurityContext);
 }
Example #18
0
		public NtlmClient ()
		{
#if SECURITY_DEP
			authObject = new Mono.Http.NtlmClient ();
#else
			authObject = null;
#endif
		}
 public void FixtureSetUp()
 {
     policy     = new IntranetZoneCredentialPolicy();
     uri        = new Uri("http://www.mono-project.com");
     request    = WebRequest.Create(uri);
     credential = new NetworkCredential("me", "mine");
     module     = new Module("type", true, "token");
 }
Example #20
0
        public NtlmClient()
        {
#if SECURITY_DEP
            authObject = new Mono.Http.NtlmClient();
#else
            authObject = null;
#endif
        }
Example #21
0
        public static void Main(string[] args)
        {
            try
            {
                string url, userName, passwd, domain;
                if (args.Length < 4)
                {
                    // Proceed with defaults.
                    Client.PrintUsage();
                    Console.WriteLine("\nTo proceed with defaults values press 'y' ,press any other character to exit:");
                    string option = Console.ReadLine();
                    if (option == "Y" || option == "y")
                    {
                        url      = "http://gopik/clonebasicsite/WebForm1.aspx";
                        userName = "******";
                        passwd   = "passwd1";
                        domain   = "gopik";
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    url      = args[0];
                    userName = args[1];
                    passwd   = args[2];
                    domain   = args[3];
                }
                Console.WriteLine();

                CloneBasic authenticationModule = new CloneBasic();
                // Register CloneBasic authentication module with the system.
                AuthenticationManager.Register(authenticationModule);
                Console.WriteLine("\nSuccessfully registered our custom authentication module \"CloneBasic\" ");
                // The AuthenticationManager calls all authentication modules sequentially until one of them responds with;
                // an authorization instance. We have to unregister "Basic" here as it almost always returns an authorization;
                // thereby defeating our purpose to test CloneBasic.
                AuthenticationManager.Unregister("Basic");

                IEnumerator registeredModules = AuthenticationManager.RegisteredModules;
                Console.WriteLine("\r\nThe following authentication modules are now registered with the system");
                while (registeredModules.MoveNext())
                {
                    Console.WriteLine("\r \n Module : {0}", registeredModules.Current);
                    IAuthenticationModule currentAuthenticationModule = (IAuthenticationModule)registeredModules.Current;
                    Console.WriteLine("\t  CanPreAuthenticate : {0}", currentAuthenticationModule.CanPreAuthenticate);
                }
                // Calling Our Test Client.
                GetPage(url, userName, passwd, domain);
            }
            catch (Exception e)
            {
                Console.WriteLine("\n The following exception was raised : {0}", e.Message);
            }
        }
        /// <include file='doc\AuthenticationManager.uex' path='docs/doc[@for="AuthenticationManager.Authenticate"]/*' />
        /// <devdoc>
        ///    <para>Call each registered authentication module to determine the first module that
        ///       can respond to the authentication request.</para>
        /// </devdoc>
        public static Authorization Authenticate(string challenge, WebRequest request, ICredentials credentials)
        {
            //
            // parameter validation
            //
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            if (challenge == null)
            {
                throw new ArgumentNullException("challenge");
            }

            GlobalLog.Print("AuthenticationManager::Authenticate() challenge:[" + challenge + "]");

            Authorization response = null;

            lock (typeof(AuthenticationManager)) {
                //
                // fastest way of iterating on the ArryList
                //
                for (int i = 0; i < ModuleList.Count; i++)
                {
                    IAuthenticationModule authenticationModule = (IAuthenticationModule)ModuleList[i];
                    //
                    // the AuthenticationModule will
                    // 1) return a valid string on success
                    // 2) return null if it knows it cannot respond
                    // 3) throw if it could have responded but unexpectedly failed to do so
                    //

                    HttpWebRequest httpWebRequest = request as HttpWebRequest;
                    if (httpWebRequest != null)
                    {
                        httpWebRequest.CurrentAuthenticationState.Module = authenticationModule;
                    }
                    response = authenticationModule.Authenticate(challenge, request, credentials);

                    if (response != null)
                    {
                        //
                        // fond the Authentication Module, return it
                        //
                        response.Module = authenticationModule;
                        GlobalLog.Print("AuthenticationManager::Authenticate() found IAuthenticationModule:[" + authenticationModule.AuthenticationType + "]");
                        break;
                    }
                }
            }

            return(response);
        }
Example #23
0
        public static void Register(IAuthenticationModule authenticationModule)
        {
            if (authenticationModule == null)
            {
                throw new ArgumentNullException("authenticationModule");
            }

            DoUnregister(authenticationModule.AuthenticationType, false);
            lock (modules)
                modules.Add(authenticationModule);
        }
// <Snippet3>
        static void DisplayAllModules()
        {
            IEnumerator registeredModules = AuthenticationManager.RegisteredModules;

            Console.WriteLine("\n\tThe following modules are now registered with the system:");
            while (registeredModules.MoveNext())
            {
                Console.WriteLine("\n\t\tModule : {0}", registeredModules.Current);
                IAuthenticationModule currentAuthenticationModule = (IAuthenticationModule)registeredModules.Current;
                Console.WriteLine("\t\t\t CanPreAuthenticate : {0}", currentAuthenticationModule.CanPreAuthenticate);
            }
        }
Example #25
0
        static IAuthenticationModule CreateInstance(string typeName, XmlNode node)
        {
            IAuthenticationModule module = null;

            try {
                Type type = Type.GetType(typeName, true);
                module = (IAuthenticationModule)Activator.CreateInstance(type);
            } catch (Exception e) {
                HandlersUtil.ThrowException(e.Message, node);
            }

            return(module);
        }
        /// <summary>Registers an authentication module with the authentication manager.</summary>
        /// <param name="authenticationModule">The <see cref="T:System.Net.IAuthenticationModule" /> to register with the authentication manager. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="authenticationModule" /> is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public static void Register(IAuthenticationModule authenticationModule)
        {
            if (authenticationModule == null)
            {
                throw new ArgumentNullException("authenticationModule");
            }
            AuthenticationManager.DoUnregister(authenticationModule.AuthenticationType, false);
            ArrayList obj = AuthenticationManager.modules;

            lock (obj)
            {
                AuthenticationManager.modules.Add(authenticationModule);
            }
        }
Example #27
0
    public virtual bool ShouldSendCredential(Uri challengeUri,
                                             WebRequest request,
                                             NetworkCredential credential,
                                             IAuthenticationModule authModule)
    {
        Console.WriteLine("Checking custom credential policy.");
        if (request.RequestUri.Host == "www.contoso.com" ||
            challengeUri.IsLoopback == true)
        {
            return(true);
        }

        return(false);
    }
        private static IAuthenticationModule findModule(string authenticationType)
        {
            ArrayList moduleList = ModuleList;

            for (int i = 0; i < moduleList.Count; i++)
            {
                IAuthenticationModule module2 = (IAuthenticationModule)moduleList[i];
                if (string.Compare(module2.AuthenticationType, authenticationType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(module2);
                }
            }
            return(null);
        }
// <Snippet8>
        // Display registered authentication modules.
        private static void displayRegisteredModules()
        {
            // The AuthenticationManager calls all authentication modules sequentially
            // until one of them responds with an authorization instance.  Show
            // the current registered modules.
            IEnumerator registeredModules = AuthenticationManager.RegisteredModules;

            Console.WriteLine("\r\nThe following authentication modules are now registered with the system:");
            while (registeredModules.MoveNext())
            {
                Console.WriteLine("\r \n Module : {0}", registeredModules.Current);
                IAuthenticationModule currentAuthenticationModule = (IAuthenticationModule)registeredModules.Current;
                Console.WriteLine("\t  CanPreAuthenticate : {0}", currentAuthenticationModule.CanPreAuthenticate);
            }
        }
Example #30
0
 public bool ShouldSendCredential(Uri challengeUri,
                                  WebRequest request,
                                  NetworkCredential credential,
                                  IAuthenticationModule authModule)
 {
     Console.WriteLine("Checking custom credential policy for HTTPS and basic.");
     // Determine whether the base implementation returned false for basic and https.
     if (request.RequestUri.Scheme == Uri.UriSchemeHttps &&
         authModule.AuthenticationType == "Basic")
     {
         Console.WriteLine("Sending credential for HTTPS and basic.");
         return(true);
     }
     return(false);
 }
Example #31
0
//        public static NetworkCredential getCredentialsForUserAndPassword(string url, string userName, string password) {
//            CredentialCache credsCache = new CredentialCache();
//            displayRegisteredModules();
//            NetworkCredential creds = new NetworkCredential(getUserNameWithoutDomain(userName), password, getUserDomain(userName));
//            return creds;
        //            credsCache.Add(new Uri(url), "Negotiate", creds);
        //            credsCache.Add(new Uri(url), "Ntlm", creds);
        //            credsCache.Add(new Uri(url), "Basic", creds);
//            return credsCache;
//        }

#if false
        private static void displayRegisteredModules()
        {
            IEnumerator registeredModules = AuthenticationManager.RegisteredModules;

            Debug.WriteLine("\r\nThe following authentication modules are now registered with the system:");

            while (registeredModules.MoveNext())
            {
                Debug.WriteLine(string.Format("\r \n Module : {0}", registeredModules.Current));

                IAuthenticationModule currentAuthenticationModule = (IAuthenticationModule)registeredModules.Current;

                Debug.WriteLine(string.Format("\t  CanPreAuthenticate : {0}", currentAuthenticationModule.CanPreAuthenticate));
            }
        }
Example #32
0
        /// <devdoc>
        ///    <para>Unregisters authentication modules for an authentication scheme.</para>
        /// </devdoc>
        public override void Unregister(IAuthenticationModule authenticationModule)
        {
            if (authenticationModule == null)
            {
                throw new ArgumentNullException("authenticationModule");
            }

            GlobalLog.Print(
                "AuthenticationManager::Unregister() unregistering :["
                + authenticationModule.AuthenticationType + "]");

            string normalizedAuthenticationType = authenticationModule.AuthenticationType.ToUpperInvariant();

            UnregisterInternal(normalizedAuthenticationType);
        }
 internal static void BindModule(Uri uri, Authorization response, IAuthenticationModule module)
 {
     if (response.ProtectionRealm != null)
     {
         string[] protectionRealm = response.ProtectionRealm;
         for (int i = 0; i < protectionRealm.Length; i++)
         {
             s_ModuleBinding.Add(protectionRealm[i], module.AuthenticationType);
         }
     }
     else
     {
         string prefix = generalize(uri);
         s_ModuleBinding.Add(prefix, module.AuthenticationType);
     }
 }
 internal static void BindModule(Uri uri, Authorization response, IAuthenticationModule module)
 {
     if (response.ProtectionRealm != null)
     {
         string[] protectionRealm = response.ProtectionRealm;
         for (int i = 0; i < protectionRealm.Length; i++)
         {
             s_ModuleBinding.Add(protectionRealm[i], module.AuthenticationType);
         }
     }
     else
     {
         string prefix = generalize(uri);
         s_ModuleBinding.Add(prefix, module.AuthenticationType);
     }
 }
Example #35
0
        public MyNtlmClient(IAuthenticationModule ntlm)
        {
            this.ntlm = ntlm;

            var path = "/Workspace/samba-3.6.9/source3/bin/ntlm_auth";

            var psi = new ProcessStartInfo (
                path, "--helper-protocol=ntlmssp-client-1 --debuglevel=10 " +
                "--diagnostics --username=test --password=yeknom --domain=PROVCON-FAUST " +
                "--workstation=PROVCON-FAUST --configfile=/usr/local/etc/smb.conf");
            psi.RedirectStandardError = false;
            psi.RedirectStandardInput = true;
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;

            pipe = Process.Start (psi);

            // Console.WriteLine (pipe.Id);
            // Console.ReadLine ();

            pipe.StandardInput.WriteLine ("SF NTLMSSP_NEGOTIATE_56");
            var result = pipe.StandardOutput.ReadLine ();
            Console.WriteLine (result);
        }
       internal void ClearSession(HttpWebRequest httpWebRequest) {
            PrepareState(httpWebRequest);
            ISessionAuthenticationModule myModule = Module as ISessionAuthenticationModule;
            Module = null;

            if (myModule!=null) {
                try {
                    myModule.ClearSession(httpWebRequest);
                }
                catch (Exception exception) {
                    if (NclUtilities.IsFatal(exception)) throw;

                    GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::ClearSession() " + myModule.ToString() + ".Update() caught exception:" + exception.Message);
                }
            }

        }
 internal NTAuthentication GetSecurityContext(IAuthenticationModule module) {
     GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::GetSecurityContext(" + module.AuthenticationType + ") returning NTAuthentication#" + ValidationHelper.HashString((object)module==(object)Module ? SecurityContext : null));
     return (object)module==(object)Module ? SecurityContext : null;
 }
 internal static Authorization GetGroupAuthorization(
     IAuthenticationModule thisModule, 
     string token, 
     bool finished, 
     NTAuthentication authSession, 
     bool shareAuthenticatedConnections, 
     bool mutualAuth) 
 {
     return new Authorization(
             token,
             finished,
             (shareAuthenticatedConnections) ? null 
                 : (thisModule.GetType().FullName + "/" + authSession.UniqueUserId),
             mutualAuth);
 }
Example #39
0
        /// <include file='doc\AuthenticationManager.uex' path='docs/doc[@for="AuthenticationManager.Unregister"]/*' />
        /// <devdoc>
        ///    <para>Unregisters authentication modules for an authentication scheme.</para>
        /// </devdoc>
        public static void Unregister(IAuthenticationModule authenticationModule) {
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
            if (authenticationModule == null) {
                throw new ArgumentNullException("authenticationModule");
            }

            GlobalLog.Print("AuthenticationManager::Unregister() unregistering :[" + authenticationModule.AuthenticationType + "]");

            lock (typeof(AuthenticationManager)) {

                if (!ModuleList.Contains(authenticationModule)) {
                    throw new InvalidOperationException(SR.GetString(SR.net_authmodulenotregistered));
                }

                ModuleList.Remove(authenticationModule);
            }
        }
Example #40
0
 private ModuleResult InvokeAuthenticate(IAuthenticationModule arg1, IHttpContext arg2)
 {
     return arg1.Authenticate(arg2);
 }
 /// <devdoc>
 ///    <para>Unregisters authentication modules for an authentication scheme.</para>
 /// </devdoc>
 public static void Unregister(IAuthenticationModule authenticationModule) 
 {
     ExceptionHelper.UnmanagedPermission.Demand();
     Instance.Unregister(authenticationModule);
 }
 bool ICredentialPolicy.ShouldSendCredential(Uri challengeUri, WebRequest request, NetworkCredential credential, IAuthenticationModule authenticationModule)
 {
     return true;
 }
 /// <devdoc>
 ///    <para>Registers an authentication module with the authentication manager.</para>
 /// </devdoc>
 public static void Register(IAuthenticationModule authenticationModule) {
     ExceptionHelper.UnmanagedPermission.Demand();
     if (authenticationModule == null) {
         throw new ArgumentNullException("authenticationModule");
     }
     GlobalLog.Print("AuthenticationManager::Register() registering :[" + authenticationModule.AuthenticationType + "]");
     lock (s_ModuleBinding) {
         IAuthenticationModule existentModule = findModule(authenticationModule.AuthenticationType);
         if (existentModule != null) {
             ModuleList.Remove(existentModule);
         }
         ModuleList.Add(authenticationModule);
     }
 }
Example #44
0
        /// <devdoc>
        ///    <para>Registers an authentication module with the authentication manager.</para>
        /// </devdoc>
        public override void Register(IAuthenticationModule authenticationModule)
        {
            if (authenticationModule == null)
            {
                throw new ArgumentNullException("authenticationModule");
            }

            GlobalLog.Print(
                "AuthenticationManager::Register() registering :[" + authenticationModule.AuthenticationType + "]");

            string normalizedAuthenticationType = authenticationModule.AuthenticationType.ToUpperInvariant();

            this.moduleList.AddOrUpdate(
                normalizedAuthenticationType,
                authenticationModule,
                (key, value) => authenticationModule);
        }
Example #45
0
 public static void Unregister(IAuthenticationModule authenticationModule) { }
Example #46
0
        /// <devdoc>
        ///    <para>Unregisters authentication modules for an authentication scheme.</para>
        /// </devdoc>
        public override void Unregister(IAuthenticationModule authenticationModule)
        {
            if (authenticationModule == null)
            {
                throw new ArgumentNullException("authenticationModule");
            }

            GlobalLog.Print(
                "AuthenticationManager::Unregister() unregistering :[" 
                + authenticationModule.AuthenticationType + "]");

            string normalizedAuthenticationType = authenticationModule.AuthenticationType.ToUpperInvariant();
            UnregisterInternal(normalizedAuthenticationType);
        }
Example #47
0
        /// <devdoc>
        ///    <para>
        ///       Binds an authentication response to a request for pre-authentication.
        ///    </para>
        /// </devdoc>
        // Create binding between an authorization response and the module
        // generating that response
        // This association is used for deciding which module to invoke
        // for preauthentication purposes
        public override void BindModule(Uri uri, Authorization response, IAuthenticationModule module)
        {
            GlobalLog.Assert(
                module.CanPreAuthenticate, 
                "AuthenticationManager::BindModule()|module.CanPreAuthenticate == false");

            if (response.ProtectionRealm != null)
            {
                // The authentication module specified which Uri prefixes
                // will be preauthenticated
                string[] prefix = response.ProtectionRealm;

                for (int k = 0; k < prefix.Length; k++)
                {
                    //
                    // PrefixLookup is thread-safe
                    //
                    moduleBinding.Add(prefix[k], module.AuthenticationType.ToUpperInvariant());
                }
            }
            else
            {
                // Otherwise use the default policy for "fabricating"
                // some protection realm generalizing the particular Uri
                string prefix = generalize(uri);
                //
                // PrefixLookup is thread-safe
                //
                moduleBinding.Add(prefix, module.AuthenticationType);
            }
        }
Example #48
0
        // Create binding between an authorization response and the module
        // generating that response
        // This association is used for deciding which module to invoke
        // for preauthentication purposes
        private static void createModuleBinding(WebRequest request, Authorization response, IAuthenticationModule module) {
            if (!module.CanPreAuthenticate) {
                return;
            }

            if (response.ProtectionRealm!=null) {
                // The authentication module specified which Uri prefixes
                // will be preauthenticated
                string[] prefix = response.ProtectionRealm;

                for (int k=0; k<prefix.Length; k++) {
                    //
                    // PrefixLookup is thread-safe
                    //
                    s_ModuleBinding.Add(prefix[k], module.AuthenticationType);
                }
            }
            else {
                // Otherwise use the default policy for "fabricating"
                // some protection realm generalizing the particular Uri
                // Consider: should this be ChallengedUri?
                string prefix = generalize(request.RequestUri);
                //
                // PrefixLookup is thread-safe
                //
                s_ModuleBinding.Add(prefix, module.AuthenticationType);
            }

            return;
        }
 internal void SetSecurityContext(NTAuthentication securityContext, IAuthenticationModule module) {
     GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::SetSecurityContext(" + module.AuthenticationType + ") was NTAuthentication#" + ValidationHelper.HashString(SecurityContext) + " now NTAuthentication#" + ValidationHelper.HashString(securityContext));
     SecurityContext = securityContext;
 }
		public void FixtureSetUp ()
		{
			policy = new IntranetZoneCredentialPolicy ();
			uri = new Uri ("http://www.mono-project.com");
			request = WebRequest.Create (uri);
			credential = new NetworkCredential ("me", "mine");
			module = new Module ("type", true, "token");
		}
        // These four authentication modules require a Channel Binding Token to be able to preauthenticate over https.
        // After a successful authentication, they will cache the CBT used on the ServicePoint.  In order to PreAuthenticate,
        // they require that a CBT has previously been cached.  Any other module should be allowed to try preauthentication
        // without a cached CBT
#if DEBUG
        // This method is only called as part of an assert
        protected static bool ModuleRequiresChannelBinding(IAuthenticationModule authenticationModule)
        {
            return (authenticationModule is NtlmClient || authenticationModule is KerberosClient ||
                    authenticationModule is NegotiateClient || authenticationModule is DigestClient);
        }
		public virtual bool ShouldSendCredential (Uri challengeUri, WebRequest request,
			NetworkCredential credential, IAuthenticationModule authenticationModule)
		{
			Zone z = Zone.CreateFromUrl (challengeUri.AbsoluteUri);
			return (z.SecurityZone == SecurityZone.Intranet);
		}
Example #53
0
		public static void Unregister (IAuthenticationModule authenticationModule)
		{
			if (authenticationModule == null)
				throw new ArgumentNullException ("authenticationModule");

			DoUnregister (authenticationModule.AuthenticationType, true);
		}
 /// <devdoc>
 ///    <para>
 ///       Binds an authentication response to a request for pre-authentication.
 ///    </para>
 /// </devdoc>
 // Create binding between an authorization response and the module
 // generating that response
 // This association is used for deciding which module to invoke
 // for preauthentication purposes
 public abstract void BindModule(Uri uri, Authorization response, IAuthenticationModule module);
Example #55
0
		public static void Register (IAuthenticationModule authenticationModule)
		{
			if (authenticationModule == null)
				throw new ArgumentNullException ("authenticationModule");

			DoUnregister (authenticationModule.AuthenticationType, false);
			lock (modules)
				modules.Add (authenticationModule);
		}
        /// <devdoc>
        ///    <para>Unregisters authentication modules for an authentication scheme.</para>
        /// </devdoc>
        public static void Unregister(IAuthenticationModule authenticationModule) 
        {
#if FEATURE_MONO_CAS
            ExceptionHelper.UnmanagedPermission.Demand();
#endif
            Instance.Unregister(authenticationModule);
        }
 /// <devdoc>
 ///    <para>
 ///       Binds an authentication response to a request for pre-authentication.
 ///    </para>
 /// </devdoc>
 // Create binding between an authorization response and the module
 // generating that response
 // This association is used for deciding which module to invoke
 // for preauthentication purposes
 internal static void BindModule(Uri uri, Authorization response, IAuthenticationModule module) 
 {
     Instance.BindModule(uri, response, module);
 }
 /// <devdoc>
 ///    <para>Unregisters authentication modules for an authentication scheme.</para>
 /// </devdoc>
 public abstract void Unregister(IAuthenticationModule authenticationModule);
Example #59
0
 public bool ShouldSendCredential(Uri challengeUri, WebRequest request, NetworkCredential credential, IAuthenticationModule authenticationModule)
 {
     switch (MapUrlToZone(challengeUri))
     {
         // Always send credentials (including default credentials) to these zones
         case SecurityZone.Intranet:
         case SecurityZone.Trusted:
         case SecurityZone.MyComputer:
             return true;
         // Don't send default credentials to any of these zones
         case SecurityZone.Internet:
         case SecurityZone.Untrusted:
         default:
             return !IsDefaultCredentials(credential);
     }
 }
Example #60
0
        /// <include file='doc\AuthenticationManager.uex' path='docs/doc[@for="AuthenticationManager.Register"]/*' />
        /// <devdoc>
        ///    <para>Registers an authentication module with the authentication manager.</para>
        /// </devdoc>
        public static void Register(IAuthenticationModule authenticationModule) {
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
            if (authenticationModule == null) {
                throw new ArgumentNullException("authenticationModule");
            }

            GlobalLog.Print("AuthenticationManager::Register() registering :[" + authenticationModule.AuthenticationType + "]");

            lock (typeof(AuthenticationManager)) {

                IAuthenticationModule existentModule = findModule(authenticationModule.AuthenticationType);

                if (existentModule != null) {
                    ModuleList.Remove(existentModule);
                }

                ModuleList.Add(authenticationModule);
            }
        }