Ejemplo n.º 1
0
 private static void RemoveProxy(this CommandProxy commandProxy)
 {
     if (CommandProxies.Contains(commandProxy))
     {
         CommandProxies.Remove(commandProxy);
     }
 }
Ejemplo n.º 2
0
 private static void AddProxy(this CommandProxy commandProxy)
 {
     if (!CommandProxies.Contains(commandProxy))
     {
         CommandProxies.Add(commandProxy);
     }
 }
 static EventAggregatorProxyHub()
 {
     eventProxy = new EventProxy();
     try
     {
         commandProxy = GlobalHost.DependencyResolver.Resolve<CommandProxy>();
     }
     catch
     {
     }
     commandProxy = commandProxy ?? new CommandProxy();
 }
Ejemplo n.º 4
0
        public async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CommandProxy proxy = CommandProxy.Deserialize(Parameters.Text);
                AuthenticationResultProxy result = await CommandExecuter.ExecuteAsync(proxy);

                Result.Text = result.Serialize();
            }
            catch (Exception ex)
            {
                Result.Text = "Exception thrown: " + ex.Message;
            }
        }
Ejemplo n.º 5
0
 internal Mapping(CommandProxy command)
 {
     _rawMapping = new Format.Mapping(command.MappingType, command.Description.Id);
     Command     = command.Create(_rawMapping.Settings);
     _conditions = new ConditionTuple();
 }
Ejemplo n.º 6
0
        public static async Task <AuthenticationResultProxy> ExecuteAsync(CommandProxy proxy)
        {
            AuthenticationResultProxy resultProxy = null;
            AuthenticationResult      result      = null;

            foreach (var command in proxy.Commands)
            {
                var arg = command.Arguments;
                switch (command.CommandType)
                {
                case CommandType.ClearDefaultTokenCache:
                {
                    var dummyContext = new AuthenticationContext("https://dummy/dummy", false);
                    dummyContext.TokenCache.Clear();
                    break;
                }

                case CommandType.SetEnvironmentVariable:
                {
                    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                    localSettings.Values[arg.EnvironmentVariable] = arg.EnvironmentVariableValue;

                    break;
                }

                case CommandType.SetCorrelationId:
                {
                    context.CorrelationId = arg.CorrelationId;
                    break;
                }

                case CommandType.CreateContextA:
                {
                    context = new AuthenticationContext(arg.Authority);
                    break;
                }

                case CommandType.CreateContextAV:
                {
                    context = new AuthenticationContext(arg.Authority, arg.ValidateAuthority);
                    break;
                }

                case CommandType.CreateContextAVT:
                {
                    TokenCache tokenCache = null;
                    if (arg.TokenCacheType == TokenCacheType.InMemory)
                    {
                        tokenCache = new TokenCache()
                        {
                            // The default token cache in ADAL WinRT is persistent. This is how to make it in-memory only cache.
                            BeforeAccess = delegate { },
                            AfterAccess  = delegate { }
                        };
                    }

                    context = new AuthenticationContext(arg.Authority, arg.ValidateAuthority, tokenCache);
                    break;
                }

                case CommandType.ClearUseCorporateNetwork:
                {
                    //context.UseCorporateNetwork = false;
                    break;
                }

                case CommandType.SetUseCorporateNetwork:
                {
                    //context.UseCorporateNetwork = true;
                    break;
                }

                case CommandType.AquireTokenAsyncRCUPa:
                {
                    UserCredential credential = new UserCredential(arg.UserName);

                    result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, credential);

                    break;
                }

                case CommandType.AquireTokenAsyncRCRe:
                {
                    result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri);

                    break;
                }

                case CommandType.AquireTokenAsyncRCRePUX:
                {
                    result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri,
                                                             (arg.PromptBehavior == PromptBehaviorProxy.Always)?PromptBehavior.Always :
                                                             (arg.PromptBehavior == PromptBehaviorProxy.Never)?PromptBehavior.Never : PromptBehavior.Auto,
                                                             (arg.UserName != null)?new UserIdentifier(arg.UserName, UserIdentifierType.OptionalDisplayableId) : UserIdentifier.AnyUser, arg.Extra);

                    break;
                }

                case CommandType.AquireTokenAsyncRCReP:
                {
                    result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri,
                                                             (arg.PromptBehavior == PromptBehaviorProxy.Always)?PromptBehavior.Always :
                                                             (arg.PromptBehavior == PromptBehaviorProxy.Never)?PromptBehavior.Never : PromptBehavior.Auto);

                    break;
                }

                case CommandType.AquireTokenAsyncRCRePU:
                {
                    result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri,
                                                             (arg.PromptBehavior == PromptBehaviorProxy.Always)?PromptBehavior.Always :
                                                             (arg.PromptBehavior == PromptBehaviorProxy.Never)?PromptBehavior.Never : PromptBehavior.Auto,
                                                             (arg.UserName != null)?new UserIdentifier(arg.UserName, UserIdentifierType.OptionalDisplayableId) : UserIdentifier.AnyUser);

                    break;
                }

                case CommandType.AcquireTokenByRefreshTokenAsyncRC:
                {
                    result = await context.AcquireTokenByRefreshTokenAsync(arg.RefreshToken, arg.ClientId);

                    break;
                }

                case CommandType.AcquireTokenByRefreshTokenAsyncRCRe:
                {
                    result = await context.AcquireTokenByRefreshTokenAsync(arg.RefreshToken, arg.ClientId, arg.Resource);

                    break;
                }

                case CommandType.CreateFromResourceUrlAsync:
                {
                    var parameters = await AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(arg.Extra));

                    resultProxy = new AuthenticationResultProxy
                    {
                        AuthenticationParametersAuthority = parameters.Authority,
                        AuthenticationParametersResource  = parameters.Resource
                    };
                    break;
                }

                case CommandType.CreateFromResponseAuthenticateHeader:
                {
                    var parameters = AuthenticationParameters.CreateFromResponseAuthenticateHeader(arg.Extra);
                    resultProxy = new AuthenticationResultProxy
                    {
                        AuthenticationParametersAuthority = parameters.Authority,
                        AuthenticationParametersResource  = parameters.Resource
                    };
                    break;
                }

                /*case CommandType.AcquireTokenByRefreshTokenAsyncRCC:
                 * {
                 *  result = await context.AcquireTokenByRefreshTokenAsync(arg.RefreshToken, arg.ClientId,
                 *      (arg.ClientId != null && arg.ClientSecret != null) ? new ClientCredential(arg.ClientId, arg.ClientSecret) : null);
                 *  break;
                 * }*/

                default:
                    throw new Exception("Unknown command");
                }
            }

            return(resultProxy ??
                   new AuthenticationResultProxy
            {
                AccessToken = result.AccessToken,
                AccessTokenType = result.AccessTokenType,
                ExpiresOn = result.ExpiresOn,
                IsMultipleResourceRefreshToken =
                    result.IsMultipleResourceRefreshToken,
                RefreshToken = result.RefreshToken,
                IdToken = result.IdToken,
                TenantId = result.TenantId,
                UserInfo = result.UserInfo,
                Error = result.Error,
                ErrorDescription = result.ErrorDescription,
                Status =
                    (result.Status == AuthenticationStatus.Success)
                                   ? AuthenticationStatusProxy.Success
                                   : ((result.Status == AuthenticationStatus.ClientError) ? AuthenticationStatusProxy.ClientError : AuthenticationStatusProxy.ServiceError)
            });
        }
        public static async Task<AuthenticationResultProxy> ExecuteAsync(CommandProxy proxy)
        {
            AuthenticationResultProxy resultProxy = null;
            AuthenticationResult result = null;

            foreach (var command in proxy.Commands)
            {
                var arg = command.Arguments;
                switch (command.CommandType)
                {
                    case CommandType.ClearDefaultTokenCache:
                    {
                        var dummyContext = new AuthenticationContext("https://dummy/dummy", false);
                        dummyContext.TokenCache.Clear();
                        break;
                    }

                    case CommandType.SetEnvironmentVariable:
                    {
                        var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                        localSettings.Values[arg.EnvironmentVariable] = arg.EnvironmentVariableValue;

                        break;
                    }

                    case CommandType.SetCorrelationId:
                    {
                        context.CorrelationId = arg.CorrelationId;
                        break;
                    }

                    case CommandType.CreateContextA:
                    {
                        context = new AuthenticationContext(arg.Authority);
                        break;
                    }

                    case CommandType.CreateContextAV:
                    {
                        context = new AuthenticationContext(arg.Authority, arg.ValidateAuthority);
                        break;
                    }

                    case CommandType.CreateContextAVT:
                    {
                        TokenCache tokenCache = null;
                        if (arg.TokenCacheType == TokenCacheType.InMemory)
                        {
                            tokenCache = new TokenCache()
                                         {
                                             // The default token cache in ADAL WinRT is persistent. This is how to make it in-memory only cache.
                                             BeforeAccess = delegate { },                                          
                                             AfterAccess = delegate { }                                          
                                         };
                        }

                        context = new AuthenticationContext(arg.Authority, arg.ValidateAuthority, tokenCache);
                        break;
                    }

                    case CommandType.ClearUseCorporateNetwork:
                    {
                        //context.UseCorporateNetwork = false;
                        break;
                    }

                    case CommandType.SetUseCorporateNetwork:
                    {
                        //context.UseCorporateNetwork = true;
                        break;
                    }

                    case CommandType.AquireTokenAsyncRC:
                    {
                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId);
                        break;
                    }

                    case CommandType.AquireTokenAsyncRCUPa:
                    {
                        UserCredential credential = new UserCredential(arg.UserName);

                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, credential);
                        break;
                    }

                    case CommandType.AquireTokenAsyncRCRe:
                    {
                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri);
                        break;
                    }

                    case CommandType.AquireTokenAsyncRCRePUX:
                    {
                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri, 
                            (arg.PromptBehavior == PromptBehaviorProxy.Always) ? PromptBehavior.Always :
                            (arg.PromptBehavior == PromptBehaviorProxy.Never) ? PromptBehavior.Never : PromptBehavior.Auto,
                            (arg.UserName != null) ? new UserIdentifier(arg.UserName, UserIdentifierType.OptionalDisplayableId) : UserIdentifier.AnyUser, arg.Extra);
                        break;
                    }

                    case CommandType.AquireTokenAsyncRCReP:
                    {
                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri, 
                            (arg.PromptBehavior == PromptBehaviorProxy.Always) ? PromptBehavior.Always :
                            (arg.PromptBehavior == PromptBehaviorProxy.Never) ? PromptBehavior.Never : PromptBehavior.Auto);
                        break;
                    }

                    case CommandType.AquireTokenAsyncRCRePU:
                    {
                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, arg.RedirectUri,                            
                            (arg.PromptBehavior == PromptBehaviorProxy.Always) ? PromptBehavior.Always :
                            (arg.PromptBehavior == PromptBehaviorProxy.Never) ? PromptBehavior.Never : PromptBehavior.Auto,
                            (arg.UserName != null) ? new UserIdentifier(arg.UserName, UserIdentifierType.OptionalDisplayableId) : UserIdentifier.AnyUser);
                        break;
                    }

                    case CommandType.AquireTokenAsyncRCP:
                    {
                        result = await context.AcquireTokenAsync(arg.Resource, arg.ClientId, 
                            (arg.PromptBehavior == PromptBehaviorProxy.Always) ? PromptBehavior.Always :
                            (arg.PromptBehavior == PromptBehaviorProxy.Never) ? PromptBehavior.Never : PromptBehavior.Auto);
                        break;
                    }

                    case CommandType.AcquireTokenByRefreshTokenAsyncRC:
                    {
                        result = await context.AcquireTokenByRefreshTokenAsync(arg.RefreshToken, arg.ClientId);
                        break;
                    }

                    case CommandType.AcquireTokenByRefreshTokenAsyncRCRe:
                    {
                        result = await context.AcquireTokenByRefreshTokenAsync(arg.RefreshToken, arg.ClientId, arg.Resource);
                        break;
                    }

                    case CommandType.CreateFromResourceUrlAsync:
                    {
                        var parameters = await AuthenticationParameters.CreateFromResourceUrlAsync(new Uri(arg.Extra));
                        resultProxy = new AuthenticationResultProxy
                                 {
                                     AuthenticationParametersAuthority = parameters.Authority,
                                     AuthenticationParametersResource = parameters.Resource
                                 };
                        break;
                    }

                    case CommandType.CreateFromResponseAuthenticateHeader:
                    {
                        var parameters = AuthenticationParameters.CreateFromResponseAuthenticateHeader(arg.Extra);
                        resultProxy = new AuthenticationResultProxy
                        {
                            AuthenticationParametersAuthority = parameters.Authority,
                            AuthenticationParametersResource = parameters.Resource
                        };
                        break;
                    }

                    /*case CommandType.AcquireTokenByRefreshTokenAsyncRCC:
                    {
                        result = await context.AcquireTokenByRefreshTokenAsync(arg.RefreshToken, arg.ClientId,
                            (arg.ClientId != null && arg.ClientSecret != null) ? new ClientCredential(arg.ClientId, arg.ClientSecret) : null);
                        break;
                    }*/

                    default:
                        throw new Exception("Unknown command");
                }
            }

            return resultProxy ?? 
                       new AuthenticationResultProxy
                       {
                           AccessToken = result.AccessToken,
                           AccessTokenType = result.AccessTokenType,
                           ExpiresOn = result.ExpiresOn,
                           IsMultipleResourceRefreshToken =
                               result.IsMultipleResourceRefreshToken,
                           RefreshToken = result.RefreshToken,
                           IdToken = result.IdToken,
                           TenantId = result.TenantId,
                           UserInfo = result.UserInfo,
                           Error = result.Error,
                           ErrorDescription = result.ErrorDescription,
                           Status =
                               (result.Status == AuthenticationStatus.Success)
                                   ? AuthenticationStatusProxy.Success
                                   : ((result.Status == AuthenticationStatus.ClientError) ? AuthenticationStatusProxy.ClientError : AuthenticationStatusProxy.ServiceError)
                       };
        }
Ejemplo n.º 8
0
 public Mapping CreateMapping(CommandProxy command)
 {
     return(new Mapping(command));
 }
Ejemplo n.º 9
0
 public static void RegisterProxy(this CommandProxy commandProxy)
 {
     Logger.Information($"Registering {commandProxy.CommandName} proxy.");
     AppDomainManager.RegisterProxyCommand(commandProxy);
     AddProxy(commandProxy);
 }