Esempio n. 1
0
        public AudienceAddRoleCommand()
        {
            _conf = (IConfiguration) new ConfigurationBuilder()
                    .AddJsonFile("clisettings.json", optional: false, reloadOnChange: true)
                    .Build();

            _map = new MapperConfiguration(x => x.AddProfile <AutoMapperProfile_EF6>())
                   .CreateMapper();

            var env = new ContextService(InstanceContext.DeployedOrLocal);

            _uow = new UnitOfWork(_conf["Databases:IdentityEntities_EF6"], env);

            _service = new AdminService(_conf)
            {
                Grant = new ResourceOwnerGrantV2(_conf)
            };

            IsCommand("audience-add-role", "Add role to audience");

            HasRequiredOption("a|audience=", "Enter existing audience", arg =>
            {
                if (string.IsNullOrEmpty(arg))
                {
                    throw new ConsoleHelpAsException($"  *** No audience given ***");
                }

                _audience = _uow.Audiences.Get(QueryExpressionFactory.GetQueryExpression <E_Audience>()
                                               .Where(x => x.Name == arg).ToLambda())
                            .SingleOrDefault();

                if (_audience == null)
                {
                    throw new ConsoleHelpAsException($"  *** No audience '{arg}' ***");
                }
            });

            HasRequiredOption("r|role=", "Enter existing role", arg =>
            {
                if (string.IsNullOrEmpty(arg))
                {
                    throw new ConsoleHelpAsException($"  *** No role given ***");
                }

                _role = _uow.Roles.Get(QueryExpressionFactory.GetQueryExpression <E_Role>()
                                       .Where(x => x.Name == arg).ToLambda())
                        .SingleOrDefault();

                if (_role == null)
                {
                    throw new ConsoleHelpAsException($"  *** No role '{arg}' ***");
                }
            });
        }
Esempio n. 2
0
        public void CreateAudiences()
        {
            if (foundIssuer == null)
            {
                CreateIssuers();
            }

            /*
             * create test audiences
             */

            foundAudience = _uow.Audiences.Get(QueryExpressionFactory.GetQueryExpression <E_Audience>()
                                               .Where(x => x.Name == TestDefaultConstants.AudienceName).ToLambda())
                            .SingleOrDefault();

            if (foundAudience == null)
            {
                foundAudience = _uow.Audiences.Create(
                    _map.Map <E_Audience>(new AudienceV1()
                {
                    IssuerId    = foundIssuer.Id,
                    Name        = TestDefaultConstants.AudienceName,
                    IsLockedOut = false,
                    IsDeletable = true,
                }));

                _uow.Commit();

                _uow.AuthActivity.Create(
                    _map.Map <E_AuthActivity>(new AuthActivityV1()
                {
                    AudienceId   = foundAudience.Id,
                    LoginType    = GrantFlowType.ClientCredentialV2.ToString(),
                    LoginOutcome = GrantFlowResultType.Success.ToString(),
                }));

                _uow.Commit();
            }
        }
Esempio n. 3
0
        public AudienceEditCommand()
        {
            _conf = (IConfiguration) new ConfigurationBuilder()
                    .AddJsonFile("clisettings.json", optional: false, reloadOnChange: true)
                    .Build();

            _map = new MapperConfiguration(x => x.AddProfile <AutoMapperProfile_EF6>())
                   .CreateMapper();

            var env = new ContextService(InstanceContext.DeployedOrLocal);

            _uow = new UnitOfWork(_conf["Databases:IdentityEntities_EF6"], env);

            _service = new AdminService(_conf)
            {
                Grant = new ResourceOwnerGrantV2(_conf)
            };

            IsCommand("audience-edit", "Edit audience");

            HasRequiredOption("a|audience=", "Enter existing audience", arg =>
            {
                if (string.IsNullOrEmpty(arg))
                {
                    throw new ConsoleHelpAsException($"  *** No audience given ***");
                }

                _audience = _uow.Audiences.Get(QueryExpressionFactory.GetQueryExpression <E_Audience>()
                                               .Where(x => x.Name == arg).ToLambda(),
                                               new List <Expression <Func <E_Audience, object> > >()
                {
                    x => x.AudienceRoles,
                    x => x.Roles,
                })
                            .SingleOrDefault();

                if (_audience == null)
                {
                    throw new ConsoleHelpAsException($"  *** No audience '{arg}' ***");
                }
            });

            HasOption("n|name=", "Enter name", arg =>
            {
                if (string.IsNullOrEmpty(arg))
                {
                    throw new ConsoleHelpAsException($"  *** No name given ***");
                }

                _audience.Name = arg;
            });

            HasOption("d|description=", "Enter description", arg =>
            {
                if (string.IsNullOrEmpty(arg))
                {
                    throw new ConsoleHelpAsException($"  *** No description given ***");
                }

                _audience.Description = arg;
            });

            HasOption("E|enabled=", "Is user enabled", arg =>
            {
                _isLockedOut = bool.Parse(arg);
            });

            HasOption("D|deletable=", "Is user deletable", arg =>
            {
                _isDeletable = bool.Parse(arg);
            });
        }