internal virtual bool PostAuthnCheck(OperationContext operationContext, IAuthenticationInfo authenticationInfo)
 {
     AdminRoleDefinition[] array = this.GetAdminRoles();
     if (array != null)
     {
         foreach (AdminRoleDefinition adminRoleDefinition in array)
         {
             if (authenticationInfo.Sid != null)
             {
                 if (authenticationInfo.Sid == adminRoleDefinition.Sid)
                 {
                     MrsTracer.Authorization.Debug("AuthorizationManagerBase.PostAuthnCheck: client is in '{0}' role, MRS access is granted by Sid.", new object[]
                     {
                         adminRoleDefinition.RoleName
                     });
                     return(true);
                 }
             }
             else if (authenticationInfo.WindowsPrincipal.IsInRole(adminRoleDefinition.Sid))
             {
                 MrsTracer.Authorization.Debug("AuthorizationManagerBase.PostAuthnCheck: client is in '{0}' role, MRS access is granted.", new object[]
                 {
                     adminRoleDefinition.RoleName
                 });
                 return(true);
             }
         }
     }
     MrsTracer.Authorization.Debug("AuthorizationManagerBase.PostAuthnCheck: client is not an Admin, MRS access is denied.", new object[0]);
     return(false);
 }
Ejemplo n.º 2
0
        public async Task <bool> CheckInPeriod(IStObjMap stObjMap, IAuthenticationInfo authenticationInfo)
        {
            var sqlDatabase = stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            var group       = stObjMap.StObjs.Obtain <CustomGroupTable>();
            int userId      = authenticationInfo.ActualUser.UserId;

            using (var ctx = new SqlStandardCallContext())
            {
                GroupQueries       groupQueries       = new GroupQueries(ctx, sqlDatabase);
                TimedPeriodQueries timedPeriodQueries = new TimedPeriodQueries(ctx, sqlDatabase);

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                PeriodData periodData = await timedPeriodQueries.GetCurrentPeriod(groupData.ZoneId);

                DateTime currentDateTime        = DateTime.UtcNow;
                int      shoulbBeLowerOrEqual   = DateTime.Compare(periodData.BegDate, currentDateTime);
                int      shouldBeGreaterOrEqual = DateTime.Compare(periodData.EndDate, currentDateTime);

                if (shoulbBeLowerOrEqual > 0 || shouldBeGreaterOrEqual < 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 3
0
 protected void NotifySuccess(IAuthenticationToken token, IAuthenticationInfo info)
 {
     if (LoginSuccessful != null)
     {
         LoginSuccessful(this, new SuccessfulLoginEventArgs(token, info));
     }
 }
Ejemplo n.º 4
0
        public async Task WriteSecretAsync(IAuthenticationInfo auth, string path, string value)
        {
            await Task.CompletedTask;

            CheckPathAndCapability(auth, path, "write");
            secrets[path] = value;
        }
Ejemplo n.º 5
0
        public async Task <bool> CheckPeriodGivenDate(IStObjMap stObjMap, IAuthenticationInfo authenticationInfo, DateTime begDate, DateTime endDate)
        {
            var sqlDatabase = stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
            var group       = stObjMap.StObjs.Obtain <CustomGroupTable>();
            int userId      = authenticationInfo.ActualUser.UserId;

            using (var ctx = new SqlStandardCallContext())
            {
                GroupQueries       groupQueries       = new GroupQueries(ctx, sqlDatabase);
                TimedPeriodQueries timedPeriodQueries = new TimedPeriodQueries(ctx, sqlDatabase);

                GroupData groupData = await groupQueries.GetIdSchoolByConnectUser(userId);

                PeriodData periodData = await timedPeriodQueries.GetCurrentPeriod(groupData.ZoneId);

                int shouldBeGreater = begDate.CompareTo(periodData.BegDate);
                int shouldBeLower   = endDate.CompareTo(periodData.EndDate);

                if (shouldBeGreater >= 0 && shouldBeLower <= 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 6
0
        public async Task DeleteSecretAsync(IAuthenticationInfo auth, string path)
        {
            await Task.CompletedTask;

            CheckPathAndCapability(auth, path, "delete");
            secrets.Remove(path);
        }
Ejemplo n.º 7
0
        private Policy GetPolicy(IAuthenticationInfo auth)
        {
            Policy found;

            if (auth is UserPasswordAuthenticationInfo)
            {
                var    userPassword = (UserPasswordAuthenticationInfo)auth;
                string policyName;
                if (usernamePasswords.TryGetValue(userPassword.User + ":" + userPassword.Password, out policyName))
                {
                    policies.TryGetValue(policyName, out found);
                    return(found);
                }
            }
            if (auth is TokenAuthenticationInfo)
            {
                var    token = (TokenAuthenticationInfo)auth;
                string policyName;
                if (tokens.TryGetValue(token.Token, out policyName))
                {
                    policies.TryGetValue(policyName, out found);
                    return(found);
                }
            }

            throw new Exception("InMemoryStore notSupported IAuthenticationInfo");
        }
Ejemplo n.º 8
0
        public async Task <int> CheckIfUserExists(IStObjMap stObjMap, IAuthenticationInfo authenticationInfo, string mail, string userName, string firstName, string lastName)
        {
            using (var ctx = new SqlStandardCallContext())
            {
                var sqlDatabase = stObjMap.StObjs.Obtain <SqlDefaultDatabase>();
                var userTable   = stObjMap.StObjs.Obtain <CustomUserTable>();
                var actorEmail  = stObjMap.StObjs.Obtain <ActorEMailTable>();
                var basic       = stObjMap.StObjs.Obtain <IBasicAuthenticationProvider>();

                UserQueries userQueries = new UserQueries(ctx, sqlDatabase);

                int currentIdUser = authenticationInfo.ActualUser.UserId;

                int idUser = await userQueries.CheckEmail(mail);

                if (idUser != 0)
                {
                    return(idUser);
                }
                else
                {
                    string tempPwd     = RandomPassword();
                    string subject     = "Vous êtes invité à rejoindre la plateforme InProject";
                    string mailContent = "Afin de vous connectez a la plateforme InProject voici votre mot de passe provisoire: " + tempPwd + " il est conseillé de modifier ce mot de passe lors de votre première connection";
                    int    newUserId   = await userTable.CreateUserAsync(ctx, currentIdUser, userName, firstName, lastName);

                    await actorEmail.AddEMailAsync(ctx, 1, newUserId, mail, true, false);

                    await basic.CreateOrUpdatePasswordUserAsync(ctx, 1, newUserId, tempPwd);

                    //await _emailSender.SendMessage( mail, subject, mailContent );
                    return(newUserId);
                }
            }
        }
Ejemplo n.º 9
0
 public AccountController(IOptions <SpaOptions> spaOptions, IAuthenticationTypeSystem typeSystem, IStObjMap stObjMap, IWebFrontAuthLoginService loginService, IAuthenticationInfo authenticationInfo)
 {
     _spaOptions         = spaOptions;
     _typeSystem         = typeSystem;
     _stObjMap           = stObjMap;
     _loginService       = loginService;
     _authenticationInfo = authenticationInfo;
 }
Ejemplo n.º 10
0
        public async Task DeleteIfExists(IAuthenticationInfo authenticationInfo)
        {
            await logger.Log(new StoreResourceLogDto(this, StoreResourceLogDtoState.Delete));

            var client = storeResolver.CreateClient(path, authenticationInfo);

            await client.DeleteSecretAsync(GetRelativePath(path));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from Hashicorp Vault.
 /// </summary>
 /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
 /// <param name="vaultUri">The Vault uri with port.</param>
 /// <param name="authenticationInfo">The authentication information for Vault</param>
 /// <param name="secretLocationPaths">The paths for the secrets to load.</param>
 /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
 public static IConfigurationBuilder AddVault(
     this IConfigurationBuilder configurationBuilder,
     string vaultUri,
     IAuthenticationInfo authenticationInfo,
     params string[] secretLocationPaths)
 {
     return(configurationBuilder.AddVault(vaultUri, authenticationInfo, asJson: false, secretLocationPaths));
 }
Ejemplo n.º 12
0
 public DnsWatcherDbContext(DbContextOptions options,
                            IAuthenticationInfo authenticationInfo,
                            IDateTime dateTime)
     : base(options)
 {
     _authenticationInfo = authenticationInfo;
     _dateTime           = dateTime;
 }
Ejemplo n.º 13
0
        public async Task Write(IAuthenticationInfo authenticationInfo, string value)
        {
            await logger.Log(new StoreResourceLogDto(this, StoreResourceLogDtoState.Write));

            var client = storeResolver.CreateClient(path, authenticationInfo);

            await client.WriteSecretAsync(GetRelativePath(path), value);
        }
Ejemplo n.º 14
0
 public SuccessfulLoginEventArgs(IAuthenticationToken token, IAuthenticationInfo info)
     : base(token)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     _info = info;
 }
Ejemplo n.º 15
0
 public SuccessfulLoginEventArgs(IAuthenticationToken token, IAuthenticationInfo info)
     : base(token)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     _info = info;
 }
        public static IAuthenticationProvider CreateAuthenticationProvider(IAuthenticationInfo authenticationInfo, Uri baseAddress, TimeSpan?serviceTimeout = null, bool continueAsyncTasksOnCapturedContext = false, Action <HttpClient> postHttpClientInitializeAction = null)
        {
            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.AppId)
            {
                return(new AppIdAuthenticationProvider(authenticationInfo as AppIdAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.AppRole)
            {
                return(new AppRoleAuthenticationProvider(authenticationInfo as AppRoleAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.AwsEc2)
            {
                return(new AwsEc2AuthenticationProvider(authenticationInfo as AwsEc2AuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.GitHub)
            {
                return(new GitHubAuthenticationProvider(authenticationInfo as GitHubAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.LDAP)
            {
                return(new LDAPAuthenticationProvider(authenticationInfo as LDAPAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.Certificate)
            {
                var certificationInfo = authenticationInfo as CertificateAuthenticationInfo;

                var handler = new WebRequestHandler();
                handler.ClientCertificates.Add(certificationInfo.ClientCertificate);

                return(new CertificateAuthenticationProvider(certificationInfo, new HttpDataAccessManager(baseAddress, handler, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.Token)
            {
                return(new TokenAuthenticationProvider(authenticationInfo as TokenAuthenticationInfo));
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.UsernamePassword)
            {
                return(new UsernamePasswordAuthenticationProvider(authenticationInfo as UsernamePasswordAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext));
            }

            var customAuthenticationInfo = authenticationInfo as CustomAuthenticationInfo;

            if (customAuthenticationInfo != null)
            {
                return(new CustomAuthenticationProvider(customAuthenticationInfo, continueAsyncTasksOnCapturedContext));
            }

            throw new NotSupportedException("The requested authentication backend type is not supported: " + authenticationInfo.AuthenticationBackendType);
        }
        public static IAuthenticationProvider CreateAuthenticationProvider(IAuthenticationInfo authenticationInfo, Uri baseAddress, TimeSpan? serviceTimeout = null, bool continueAsyncTasksOnCapturedContext = false, Action<HttpClient> postHttpClientInitializeAction = null)
        {
            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.AppId)
            {
                return new AppIdAuthenticationProvider(authenticationInfo as AppIdAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.AppRole)
            {
                return new AppRoleAuthenticationProvider(authenticationInfo as AppRoleAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.AwsEc2)
            {
                return new AwsEc2AuthenticationProvider(authenticationInfo as AwsEc2AuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.GitHub)
            {
                return new GitHubAuthenticationProvider(authenticationInfo as GitHubAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.LDAP)
            {
                return new LDAPAuthenticationProvider(authenticationInfo as LDAPAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.Certificate)
            {
                var certificationInfo = authenticationInfo as CertificateAuthenticationInfo;

                var handler = new WebRequestHandler();
                handler.ClientCertificates.Add(certificationInfo.ClientCertificate);

                return new CertificateAuthenticationProvider(certificationInfo, new HttpDataAccessManager(baseAddress, handler, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.Token)
            {
                return new TokenAuthenticationProvider(authenticationInfo as TokenAuthenticationInfo);
            }

            if (authenticationInfo.AuthenticationBackendType == AuthenticationBackendType.UsernamePassword)
            {
                return new UsernamePasswordAuthenticationProvider(authenticationInfo as UsernamePasswordAuthenticationInfo, new HttpDataAccessManager(baseAddress, serviceTimeout: serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction), continueAsyncTasksOnCapturedContext);
            }

            var customAuthenticationInfo = authenticationInfo as CustomAuthenticationInfo;

            if (customAuthenticationInfo != null)
            {
                return new CustomAuthenticationProvider(customAuthenticationInfo, continueAsyncTasksOnCapturedContext);
            }

            throw new NotSupportedException("The requested authentication backend type is not supported: " + authenticationInfo.AuthenticationBackendType);
        }
Ejemplo n.º 18
0
        public async Task <string> Read(IAuthenticationInfo authenticationInfo)
        {
            await logger.Log(new StoreResourceLogDto(this, StoreResourceLogDtoState.Read));

            var client = storeResolver.CreateClient(path, authenticationInfo);

            var result = await client.ReadSecretAsync(GetRelativePath(path));

            return(result);
        }
Ejemplo n.º 19
0
        public IStoreClient CreateClient(string path, IAuthenticationInfo authenticationInfo)
        {
            var p1 = path.Split('/')[0];

            if (p1 == "vault")
            {
                return(vaultStoreClientFactory.CreateClient(new Uri("http://localhost:8200"), authenticationInfo));
            }

            throw new Exception("unknown path to create client");
        }
Ejemplo n.º 20
0
        public async Task <Policy> GetPolicyAsync(IAuthenticationInfo auth, string name)
        {
            await Task.CompletedTask;
            Policy found;

            if (policies.TryGetValue(name, out found))
            {
                return(found);
            }

            throw new Exception("MemoryStore Policy not found");
        }
Ejemplo n.º 21
0
        public void Merge(IAuthenticationInfo other)
        {
            if (other == null || other.Principals == null || other.Principals.Count == 0)
            {
                return;
            }

            if (Principals == null)
            {
                Principals = other.Principals;
            }
            else
            {
                if (!(Principals is IMutablePrincipalCollection))
                {
                    Principals = new SimplePrincipalCollection(Principals);
                }
                ((IMutablePrincipalCollection)Principals).AddAll(other.Principals);
            }

            if (other.Credentials == null)
            {
                return;
            }
            if (Credentials == null)
            {
                Credentials = other.Credentials;

                return;
            }

            ISet <object> credentials;

            if (Credentials is ISet <object> )
            {
                credentials = (ISet <object>)Credentials;
            }
            else
            {
                Credentials = credentials = new HashSet <object>();
            }

            if (other.Credentials is IEnumerable)
            {
                var enumerable = (IEnumerable)other.Credentials;

                credentials.UnionWith(enumerable.Cast <object>());
            }
            else
            {
                credentials.Add(other.Credentials);
            }
        }
Ejemplo n.º 22
0
        public void Merge(IAuthenticationInfo other)
        {
            if (other == null || other.Principals == null || other.Principals.Count == 0)
            {
                return;
            }

            if (Principals == null)
            {
                Principals = other.Principals;
            }
            else
            {
                if (!(Principals is IMutablePrincipalCollection))
                {
                    Principals = new SimplePrincipalCollection(Principals);
                }
                ((IMutablePrincipalCollection) Principals).AddAll(other.Principals);
            }

            if (other.Credentials == null)
            {
                return;
            }
            if (Credentials == null)
            {
                Credentials = other.Credentials;

                return;
            }

            ISet<object> credentials;
            if (Credentials is ISet<object>)
            {
                credentials = (ISet<object>) Credentials;
            }
            else
            {
                Credentials = credentials = new HashSet<object>();
            }

            if (other.Credentials is IEnumerable)
            {
                var enumerable = (IEnumerable) other.Credentials;

                credentials.UnionWith(enumerable.Cast<object>());
            }
            else
            {
                credentials.Add(other.Credentials);
            }
        }
Ejemplo n.º 23
0
        public async Task <string> ReadSecretAsync(IAuthenticationInfo auth, string path)
        {
            CheckPathAndCapability(auth, path, "read");
            await Task.CompletedTask;
            string found;

            if (secrets.TryGetValue(path, out found))
            {
                return(found);
            }

            throw new Exception("MemoryStore Read not found");
        }
Ejemplo n.º 24
0
        private async Task <SshConnection> GetWebServerSshConnection(IAuthenticationInfo authenticationInfo)
        {
            var sshUri = await WebServerSshUri.Read(authenticationInfo);

            var user = await WebServerUser.Read(authenticationInfo);

            var password = await WebServerPassword.Read(authenticationInfo);

            return(new SshConnection()
            {
                SshUri = new Uri(sshUri),
                User = user,
                Password = password,
            });
        }
Ejemplo n.º 25
0
        public void Merge(IAuthenticationInfo other)
        {
            _authcInfo.Merge(other);

            if (other is SimpleAccount)
            {
                var account = (SimpleAccount)other;
                if (account.CredentialsExpired)
                {
                    CredentialsExpired = account.CredentialsExpired;
                }
                if (account.Locked)
                {
                    Locked = true;
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates a session with the two minimum, necessary components
        /// provided as parameters.
        /// </summary>
        public VaultSession(string address, string token)
        {
            VaultAddress = address;
            VaultToken   = token;

            _vaultAddr = new Uri(address);
            _vaultBase = new Uri(_vaultAddr, "v1/");


            if (!string.IsNullOrWhiteSpace(token))
            {
                _vaultToken = token;
                _authnInfo  = new TokenAuthenticationInfo(token);
            }

            _dataAccessManager = new HttpDataAccessManager(_vaultBase);
            VaultClient        = VaultClientFactory.CreateVaultClient(new Uri(address), _authnInfo);
        }
Ejemplo n.º 27
0
 public IStoreClient CreateClient(Uri uri, IAuthenticationInfo authenticationInfo)
 {
     if (authenticationInfo is TokenAuthenticationInfo)
     {
         var auth = (TokenAuthenticationInfo)authenticationInfo;
         return(new VaultStoreClient(
                    uri,
                    new VaultSharp.Backends.Authentication.Models.Token.TokenAuthenticationInfo(auth.Token)));
     }
     else if (authenticationInfo is UserPasswordAuthenticationInfo)
     {
         var auth = (UserPasswordAuthenticationInfo)authenticationInfo;
         return(new VaultStoreClient(
                    uri,
                    new VaultSharp.Backends.Authentication.Models.UsernamePassword.UsernamePasswordAuthenticationInfo(auth.User, auth.Password)));
     }
     throw new Exception("Unsupported IAuthenticationInfo");
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from Hashicorp Vault.
        /// </summary>
        /// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
        /// <param name="vaultUri">The Vault uri with port.</param>
        /// <param name="roleId">The AppRole role_id to use for authentication.</param>
        /// <param name="secretId">The secret_id to use for authentication.</param>
        /// <param name="secretLocationPaths">The paths for the secrets to load.</param>
        /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
        public static IConfigurationBuilder AddVault(
            this IConfigurationBuilder configurationBuilder,
            string vaultUri,
            IAuthenticationInfo authenticationInfo,
            params string[] secretLocationPaths)
        {
            if (string.IsNullOrWhiteSpace(vaultUri))
            {
                throw new ArgumentException("VaultUri must be a valid URI", nameof(vaultUri));
            }
            var uri = new Uri(vaultUri);

            var vaultClient = VaultClientFactory.CreateVaultClient(
                uri,
                authenticationInfo,
                continueAsyncTasksOnCapturedContext: false);

            return(AddVault(configurationBuilder, vaultClient, new DefaultVaultSecretManager(), secretLocationPaths));
        }
Ejemplo n.º 29
0
 internal override bool PostAuthnCheck(OperationContext operationContext, IAuthenticationInfo authenticationInfo)
 {
     if (operationContext.ServiceSecurityContext.IsAnonymous)
     {
         return(false);
     }
     MRSProxyAuthorizationManager.AuthenticationData authenticationData = this.GetAuthenticationData(operationContext);
     if (authenticationData.IsAuthorized)
     {
         return(true);
     }
     if (authenticationInfo.IsCertificateAuthentication)
     {
         authenticationData.IsAuthorized = true;
     }
     else
     {
         authenticationData.IsAuthorized = base.PostAuthnCheck(operationContext, authenticationInfo);
     }
     return(authenticationData.IsAuthorized);
 }
Ejemplo n.º 30
0
        public IAuthenticationInfo Authenticate(IAuthenticationToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            Log.TraceFormat("Authentication attempt received for token [{0}]", token);
            try
            {
                IAuthenticationInfo info = DoAuthenticate(token);
                if (info == null)
                {
                    throw new AuthenticationException(
                              string.Format(Properties.Resources.NoAccountInformationForTokenMessage, token));
                }

                Log.DebugFormat("Authentication successful for token [{0}]. Returned account [{1}]", token, info);
                NotifySuccess(token, info);

                return(info);
            }
            catch (Exception e)
            {
                AuthenticationException ae = null;
                if (e is AuthenticationException)
                {
                    ae = (AuthenticationException)e;
                }
                if (ae == null)
                {
                    ae = new AuthenticationException(
                        string.Format(Properties.Resources.AuthenticationFailedForTokenMessage, token));
                }
                NotifyFailure(token, ae);

                throw ae;
            }
        }
 public ODConnection(string rootUrl, IAuthenticationInfo auth)
 {
     HttpRequestFactory = new Http.HttpFactoryDefault();
     RootUrl            = rootUrl;
     Authentication     = auth;
 }
Ejemplo n.º 32
0
        private void CheckPathAndCapability(IAuthenticationInfo auth, string path, string capability)
        {
            var policy = GetPolicy(auth);

            CheckPathAndCapability(policy, path, "write");
        }
Ejemplo n.º 33
0
        public async Task WriteUser(IAuthenticationInfo auth, string user, string password, string policy)
        {
            await Task.CompletedTask;

            usernamePasswords[user + ":" + password] = policy;
        }
Ejemplo n.º 34
0
        public void Merge(IAuthenticationInfo other)
        {
            _authcInfo.Merge(other);

            if (other is SimpleAccount)
            {
                var account = (SimpleAccount) other;
                if (account.CredentialsExpired)
                {
                    CredentialsExpired = account.CredentialsExpired;
                }
                if (account.Locked)
                {
                    Locked = true;
                }
            }
        }
Ejemplo n.º 35
0
 public ModuleAuthInfo(ILoginModule module,
   IAuthenticationInfo authentication_info) {
   Module = module;
   AuthenticationInfo = authentication_info;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Creates an instance of the vault client, with the provided <see cref="IAuthenticationInfo" /> used to authenticate and authorize the user.
 /// This is the typical client you would need for your consuming applications.
 /// <para>
 /// If you need an instance of an administrative/root user based <see cref="IVaultClient" />, pass a <see cref="IAuthenticationInfo" /> with a root policy mapping.
 /// If you need an instance of an unauthenticated <see cref="IVaultClient" />, pass a <value>null</value> value for <see cref="IAuthenticationInfo" />.
 /// An unauthenticated client can do very few operations. e.g. Check seal status, initialization status etc.
 /// </para><para>var vaultClient = VaultClientFactory.CreateVaultClient(new Uri("http://127.0.0.1:8200", new GitHubAuthenticationInfo(personalAccessToken: "YOUR_TOKEN"));</para><para>var administrativeVaultClient = VaultClientFactory.CreateVaultClient(new Uri("http://127.0.0.1:8200", new TokenAuthenticationInfo(token: "ROOT_POLICY_TOKEN"));</para><para>var unauthenticatedVaultClient = VaultClientFactory.CreateVaultClient(new Uri("http://127.0.0.1:8200", authenticationInfo: null));</para>
 /// </summary>
 /// <param name="vaultServerUriWithPort"><para>[required]</para>
 /// The vault server URI with port.</param>
 /// <param name="authenticationInfo"><para>[optional]</para>
 /// The authentication information. e.g. GitHub, AppId, LDAP etc.</param>
 /// <param name="continueAsyncTasksOnCapturedContext"><para>[optional]</para>
 /// if set to <c>true</c> [continue asynchronous tasks on captured context].</param>
 /// <param name="serviceTimeout"><para>[optional]</para>
 /// The timeout value for the Vault Service calls. Do not specify a value, if you want to go with the default timeout values.</param>
 /// <param name="postHttpClientInitializeAction"><para>[optional]</para>
 /// A post-processing delegate on the <see cref="HttpClient"/> instance used by the library.
 /// This can be used to setup any custom message handlers, proxy settings etc.
 /// Please note that the delegate will get an instance of <see cref="HttpClient"/> that is initialized with the address
 /// and timeout settings.
 /// </param>
 /// <returns>
 /// An instance of the <see cref="IVaultClient" /> interface implementation.
 /// </returns>
 public static IVaultClient CreateVaultClient(Uri vaultServerUriWithPort, IAuthenticationInfo authenticationInfo, bool continueAsyncTasksOnCapturedContext = false, TimeSpan? serviceTimeout = null, Action<HttpClient> postHttpClientInitializeAction = null)
 {
     IVaultClient vaultClient = new VaultClient(vaultServerUriWithPort, authenticationInfo, continueAsyncTasksOnCapturedContext, serviceTimeout, postHttpClientInitializeAction: postHttpClientInitializeAction);
     return vaultClient;
 }