Пример #1
0
        public static void ValidateAuthServerAuthorizationEndpoint(AuthServer authServer, IConfigurationSession configSession, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskErrorLoggingDelegate writeError)
        {
            if (authServer == null)
            {
                throw new ArgumentNullException("authServer");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("configSession");
            }
            if (writeWarning == null)
            {
                throw new ArgumentNullException("writeWarning");
            }
            if (writeError == null)
            {
                throw new ArgumentNullException("writeError");
            }
            ADObjectId containerId = AuthServer.GetContainerId(configSession);

            AuthServer[] array = configSession.Find <AuthServer>(containerId, QueryScope.OneLevel, null, null, ADGenericPagedReader <AuthServer> .DefaultPageSize);
            if (array == null || array.Length == 0)
            {
                return;
            }
            AuthServer authServer2 = array.FirstOrDefault((AuthServer existingAuthServer) => (existingAuthServer.Type == AuthServerType.ADFS || existingAuthServer.Type == AuthServerType.AzureAD) && existingAuthServer.IsDefaultAuthorizationEndpoint);

            if (authServer2 != null && authServer.IsDefaultAuthorizationEndpoint)
            {
                writeError(new TaskException(Strings.ErrorExistingAuthServerWithDefaultAuthorizationEndpoint(authServer2.Name)), ErrorCategory.InvalidArgument, null);
            }
            if (authServer2 == null && !authServer.IsDefaultAuthorizationEndpoint)
            {
                writeWarning(Strings.WarningNoAuthServerWithDefaultAuthorizationEndpoint);
            }
        }
Пример #2
0
        public static void ValidateAuthServerRealmAndUniqueness(AuthServer authServer, IConfigurationSession configSession, Task.TaskErrorLoggingDelegate writeError)
        {
            if (authServer == null)
            {
                throw new ArgumentNullException("authServer");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("configSession");
            }
            if (writeError == null)
            {
                throw new ArgumentNullException("writeError");
            }
            if (!authServer.IsModified(AuthServerSchema.IssuerIdentifier) && !authServer.IsModified(AuthServerSchema.Realm))
            {
                return;
            }
            bool flag  = OAuthCommon.IsRealmEmpty(authServer.Realm);
            bool flag2 = false;

            if (authServer.Type == AuthServerType.MicrosoftACS || authServer.Type == AuthServerType.AzureAD)
            {
                Guid guid;
                if (!OAuthTaskHelper.IsMultiTenancyEnabled)
                {
                    if (flag || !Guid.TryParse(authServer.Realm, out guid))
                    {
                        flag2 = true;
                    }
                }
                else if (!flag && !Guid.TryParse(authServer.Realm, out guid))
                {
                    flag2 = true;
                }
            }
            if (flag2)
            {
                writeError(new TaskException(Strings.ErrorInvalidAuthServerRealm(authServer.Realm)), ErrorCategory.InvalidArgument, null);
            }
            ADObjectId containerId = AuthServer.GetContainerId(configSession);

            AuthServer[] array = configSession.Find <AuthServer>(containerId, QueryScope.OneLevel, null, null, ADGenericPagedReader <AuthServer> .DefaultPageSize);
            if (array == null || array.Length == 0)
            {
                return;
            }
            AuthServer authServer2 = array.FirstOrDefault((AuthServer existingAuthServer) => string.Equals(existingAuthServer.IssuerIdentifier, authServer.IssuerIdentifier, StringComparison.OrdinalIgnoreCase) && existingAuthServer.Type == authServer.Type && OAuthCommon.IsRealmMatchIncludingEmpty(existingAuthServer.Realm, authServer.Realm) && !existingAuthServer.Id.Equals(authServer.Id));

            if (authServer2 != null)
            {
                writeError(new TaskException(Strings.ErrorDuplicateAuthServer(authServer2.Id.ToString())), ErrorCategory.InvalidArgument, null);
            }
            if (authServer.Type != AuthServerType.MicrosoftACS && authServer.Type != AuthServerType.AzureAD)
            {
                return;
            }
            authServer2 = array.FirstOrDefault((AuthServer existingAuthServer) => existingAuthServer.Type == authServer.Type && OAuthCommon.IsRealmMatchIncludingEmpty(existingAuthServer.Realm, authServer.Realm) && string.Equals(existingAuthServer.IssuerIdentifier, authServer.IssuerIdentifier, StringComparison.OrdinalIgnoreCase) && !existingAuthServer.Id.Equals(authServer.Id));
            if (authServer2 != null)
            {
                writeError(new TaskException(flag ? Strings.ErrorExistingAuthServerWithEmptyRealm(authServer2.Id.ToString()) : Strings.ErrorExistingAuthServerWithSameRealm(authServer2.Id.ToString(), authServer.Realm)), ErrorCategory.InvalidArgument, null);
            }
        }