Example #1
0
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     //this is where AD FS passes us the config data, if such data was supplied at registration of the adapter
     if (configData != null)
     {
         if (configData.Data != null)
         {
             // load the config file
             // TODO: Handle errors and exceptions
             using (StreamReader reader = new StreamReader(configData.Data, Encoding.UTF8))
             {
                 XmlRootAttribute xRoot = new XmlRootAttribute
                 {
                     ElementName = "server",
                     IsNullable  = true
                 };
                 XmlSerializer serializer    = new XmlSerializer(typeof(ADFSserver), xRoot);
                 ADFSserver    server_config = (ADFSserver)serializer.Deserialize(reader);
                 admin_pw         = server_config.adminpw;
                 admin_user       = server_config.adminuser;
                 ssl              = server_config.ssl.ToLower() == "false" ? false : true;
                 use_upn          = server_config.upn.ToLower() == "false" ? false : true;
                 privacyIDEArealm = server_config.realm;
                 privacyIDEAurl   = server_config.url;
                 uidefinition     = server_config.@interface;
             }
         }
     }
 }
Example #2
0
 /// <summary>
 /// 读取配置文件
 /// </summary>
 /// <param name="configData"></param>
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     if (configData != null)
     {
         if (configData.Data != null)
         {
             using (StreamReader reader = new StreamReader(configData.Data, Encoding.UTF8))
             {
                 try
                 {
                     var config = reader.ReadToEnd();
                     apiinfo = CommonHelper.Deseralize <API_UrlInfo>(config);
                 }
                 catch
                 {
                     throw new ArgumentException();
                 }
             }
         }
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
Example #3
0
        public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
        {
            if (configData != null)
            {
                if (configData.Data != null)
                {
                    using (StreamReader reader = new StreamReader(configData.Data, Encoding.UTF8))
                    {
                        //Config should be in a json format, and needs to be registered with the
                        //-ConfigurationFilePath parameter when registering the MFA Adapter (Register-AdfsAuthenticationProvider cmdlet)
                        try
                        {
                            var config    = reader.ReadToEnd();
                            var js        = new DataContractJsonSerializer(typeof(SRSMFAConf));
                            var ms        = new MemoryStream(UTF8Encoding.UTF8.GetBytes(config));
                            var mfaConfig = (SRSMFAConf)js.ReadObject(ms);

                            server = mfaConfig.server;

                            EventLog.WriteEntry("Application", "Config loaded with following server address: " + server, EventLogEntryType.Information);
                        }
                        catch
                        {
                            EventLog.WriteEntry("Application", "Unable to load config data. Check that it is registered and correct.", EventLogEntryType.Information);
                            throw new ArgumentException();
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     /* The OnAuthenticationPipelineLoad method is called whenever the Authentication Provider is loaded by AD FS into it's pipeline.
      * It allows your adapter to initialize itself. AD FS will 'tell' your adapter which information AD FS has.
      * The IAuthenticationMethodConfigData contains a single property called Data.
      * For the developers; this property is of type Stream. In our sample Authentication Provider will not use this configData.
      * The method returns nothing.
      * */
 }
Example #5
0
        // Called when the authentication provider is loaded by AD FS into it's pipeline.
        // This is where AD FS passes us the config data as a Stream, if such data was supplied at registration of the adapter
        public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
        {
            int id = System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(this);

            logger.TraceEvent(TraceEventType.Verbose, 0, "OnAuthenticationPipelineLoad(verAdapter={0}, obj={1})",
                              AuthenticationAdapterMetadata.VERSION, id);
            Logging.Log.LoadAuthProviderStart(id, AuthenticationAdapterMetadata.VERSION);

            if (configData.Data != null)
            {
                try
                {
                    string cfgStr = (new System.IO.StreamReader(configData.Data)).ReadToEnd();
                    // logger.TraceEvent(TraceEventType.Verbose, 0, "Cfg:\n========\n" + cfgStr + "\n========\n");
                    configData.Data.Position = 0;
                    cfgMid = WebClientConfig.CreateConfig(cfgStr);
                    logger.TraceEvent(TraceEventType.Verbose, 0, "Config.Mid: " + cfgMid);
                    MobileId.Logging.Log.ConfigInfo(getWebClient().GetClientVersion(), cfgMid.ToString());
                    configData.Data.Position = 0;
                    cfgAdfs = AdfsConfig.CreateConfig(cfgStr);
                    logger.TraceEvent(TraceEventType.Verbose, 0, "Config.Adfs: " + cfgAdfs);
                    Logging.Log.ConfigInfo(AuthenticationAdapterMetadata.VERSION, cfgAdfs.ToString());
                }
                catch (Exception ex)
                {
                    logger.TraceData(TraceEventType.Error, 0, ex);
                    Logging.Log.ConfigError(ex.Message);
                    throw ex;
                }
            }
            else
            {
                Logging.Log.ConfigError("config is null");
                throw new ArgumentNullException("configData is null");
            }

            // Verify EventLog Source
            //if (!EventLog.SourceExists(EVENTLOGSource))
            //    EventLog.CreateEventSource(EVENTLOGSource, EVENTLOGGroup);
            //EventLog.WriteEntry(EVENTLOGSource, "Adapter loaded", EventLogEntryType.Information, 900);

            // The EventSources are created by the installer normally. If Mobile ID for ADFS was installed manually and
            // EventSource were not created, we will repair it here. It requires administrative privileges though.
            if (!EventLog.SourceExists("MobileId.Client"))
            {
                EventLog.CreateEventSource("MobileId.Client", "Application");
            }

            if (!EventLog.SourceExists("MobileId.Adfs"))
            {
                EventLog.CreateEventSource("MobileId.Adfs", "Application");
            }
        }
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     try
     {
         _secretStorageProvider = new DynamoDbSecretStorageProvider();
         _usedCodeProvider      = new DynamoDbUsedCodeProvider();
     }
     catch (Exception ex)
     {
         Logger.Log(ex.Message);
         Logger.Log(ex.StackTrace);
     }
 }
        /// <summary>
        /// Called whenever the Authentication Provider is loaded into the
        /// AD FS pipeline
        /// </summary>
        /// <param name="configData"></param>
        public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
        {
            appConfig    = new AppConfigurationReg();
            radiusClient = new RadiusClient(appConfig.Server, appConfig.SharedSecret, appConfig.TimeOut,
                                            appConfig.AuthenticationPort, appConfig.AccountingPort);

            debugLogging = appConfig.Debug;
            if (this.debugLogging)
            {
                Logging.LogMessage(
                    "Currently using the following configuration:" + Environment.NewLine +
                    "Server: " + appConfig.Server + Environment.NewLine +
                    "Authentication port: " + appConfig.AuthenticationPort + Environment.NewLine +
                    "Accounting port: " + appConfig.AccountingPort + Environment.NewLine +
                    "Shared secret: " + appConfig.SharedSecret + Environment.NewLine +
                    "Timeout: " + appConfig.TimeOut);
            }
        }
Example #8
0
        public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
        {
#if DEBUG
            Debug.WriteLine($"{Helper.debugPrefix} Loading version {Assembly.GetExecutingAssembly().GetName().Version.ToString()}");
#endif

            //this is where AD FS passes us the config data, if such data was supplied at registration of the adapter
            if ((configData != null) && (configData.Data != null))
            {
                try
                {
                    // load the config file
                    using (StreamReader reader = new StreamReader(configData.Data, Encoding.UTF8))
                    {
                        XmlRootAttribute xRoot = new XmlRootAttribute
                        {
                            ElementName = "server",
                            IsNullable  = true
                        };
                        XmlSerializer serializer    = new XmlSerializer(typeof(ADFSserver), xRoot);
                        XmlReader     xmlreader     = XmlReader.Create(reader);
                        ADFSserver    server_config = (ADFSserver)serializer.Deserialize(xmlreader);
                        xmlreader.Dispose();
                        admin_pw         = server_config.adminpw;
                        admin_user       = server_config.adminuser;
                        ssl              = server_config.ssl.ToLower(new CultureInfo(Metadata.AvailableLcids[0])) == "true";
                        privacyIDEArealm = server_config.realm;
                        privacyIDEAurl   = server_config.url;
                        uidefinition     = server_config.@interface;
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
#if DEBUG
                    Debug.WriteLine($"{Helper.debugPrefix} OnAuthenticationPipelineLoad() exception: {ex.Message}");
#endif
                    Helper.LogEvent($"OnAuthenticationPipelineLoad() exception: {ex.Message}", EventLogEntryType.Error);
                }
            }
        }
Example #9
0
        public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData ConfigData)
        {
            //this is where AD FS passes us the Config data, if such data was supplied at registration of the adapter
            if (ConfigData != null)
            {
                if (ConfigData.Data != null)
                {
                    using (StreamReader reader = new StreamReader(ConfigData.Data, Encoding.UTF8))
                    {
                        //Config should be in a json format, and needs to be registered with the
                        //-ConfigurationFilePath parameter when registering the MFA Adapter (Register-AdfsAuthenticationProvider cmdlet)
                        try
                        {
                            string Config = reader.ReadToEnd();
                            DataContractJsonSerializer JsonSer = new DataContractJsonSerializer(typeof(SmsAdapterConfig));
                            MemoryStream     MemStrConfig      = new MemoryStream(UTF8Encoding.UTF8.GetBytes(Config));
                            SmsAdapterConfig MFAConfig         = (SmsAdapterConfig)JsonSer.ReadObject(MemStrConfig);

                            SMSCURL                = MFAConfig.SMSCURL;
                            SMSCUserName           = MFAConfig.SMSCUserName;
                            SMSCPassword           = MFAConfig.SMSCPassword;
                            SMSCSender             = MFAConfig.SMSCSender;
                            LDAPdomainName         = MFAConfig.LDAPdomainName;
                            PinAttributeName       = MFAConfig.PinAttributeName;
                            OTPCodeLength          = MFAConfig.OTPCodeLength;
                            TelNumberAttributeName = MFAConfig.TelNumberAttributeName;
                            SmsTemplate            = MFAConfig.SmsTemplate;
                            DebugEnabled           = MFAConfig.DebugEnabled;
                        }
                        catch
                        {
                            throw new ArgumentException();
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #10
0
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
 }
Example #11
0
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     DummyLogger.Log("IAuthenticationAdapter.OnAuthenticationPipelineLoad");
 }
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     // Do nothing
 }
Example #13
0
 /// <summary>
 /// This is where AD FS passes us the config data, if such data was supplied at registration of the adapter.
 /// </summary>
 /// <param name="configData">Contains a single property called Data and is of type Stream</param>
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     //throw new NotImplementedException();
 }
Example #14
0
        /// <summary>
        /// Called when the provider is loaded by the AD FS service. The config will be loaded in this function.
        /// </summary>
        /// <param name="configData"></param>
        public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
        {
            Log("OnAuthenticationPipelineLoad: Provider Version " + version);

            var registryReader = new RegistryReader(Log);

            // Read logging entry first to be able to log the reading of the rest if needed
            this.debuglog = registryReader.Read("debug_log") == "1";

            // Read the other defined keys into a dict
            List <string> configKeys = new List <string>(new string[]
                                                         { "use_upn", "url", "disable_ssl", "enable_enrollment", "service_user", "service_pass", "service_realm",
                                                           "realm", "trigger_challenges", "send_empty_pass" });

            var configDict = new Dictionary <string, string>();

            configKeys.ForEach(key =>
            {
                string value = registryReader.Read(key);
                Log("Read value '" + value + "' for key '" + key + "'");
                configDict[key] = value;
            });

            string url = GetFromDict(configDict, "url");

            if (string.IsNullOrEmpty(url))
            {
                Error("No server URL configured. Can not initialize privacyIDEA without a server URL.");
                throw new Exception("No server URL configured. Can not initialize privacyIDEA without a server URL.");
            }

            // Note: the config asks if ssl verify should be disabled, while the constructor parameter indicates if ssl verify should be enabled!
            bool shouldUseSSL = GetFromDict(configDict, "disable_ssl", "0") != "1";

            this.privacyIDEA        = new PrivacyIDEA(url, "PrivacyIDEA-ADFS", shouldUseSSL);
            this.privacyIDEA.Logger = this;

            string serviceUser = GetFromDict(configDict, "service_user", "");
            string servicePass = GetFromDict(configDict, "service_pass", "");

            if (!string.IsNullOrEmpty(serviceUser) && !string.IsNullOrEmpty(servicePass))
            {
                this.privacyIDEA.SetServiceAccount(serviceUser, servicePass, GetFromDict(configDict, "service_realm"));
            }

            this.use_upn = GetFromDict(configDict, "use_upn", "0") == "1";

            this.enrollmentEnabled = GetFromDict(configDict, "enable_enrollment", "0") == "1";
            this.enrollmentApps    = registryReader.ReadMultiValue("enrollment_apps");

            this.triggerChallenge = GetFromDict(configDict, "trigger_challenges", "0") == "1";
            if (!this.triggerChallenge)
            {
                // Only if triggerChallenge is disabled, sendEmptyPassword COULD be set
                this.sendEmptyPassword = GetFromDict(configDict, "send_empty_pass", "0") == "1";
            }
            this.privacyIDEA.Realm = GetFromDict(configDict, "realm", "");
            var realmmap = registryReader.GetRealmMapping();

            Log("realmmapping: " + string.Join(" , ", realmmap));
            this.privacyIDEA.RealmMap = realmmap;
        }
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     //this is where AD FS passes us the config data, if such data was supplied at registration of the adapter
 }
 public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
 {
     //this is where AD FS passes us the config data, if such data was supplied at registration of the adapter
 }