Exemplo n.º 1
0
        public Guid AddUser(UserPrincipal retrievedUser, string domain, string authProvider, Guid userId, out Guid subjectId)
        {
            subjectId = Guid.NewGuid();
            var createMsg =
                MessageBuilder.New(
                    () => new UserMsgs.CreateUser(
                        userId,
                        retrievedUser.GivenName,
                        retrievedUser.Surname,
                        retrievedUser.DisplayName,
                        retrievedUser.EmailAddress));

            _userSvc.Handle(createMsg);
            _userSvc.Handle(
                MessageBuilder
                .From(createMsg)
                .Build(() =>
                       new UserMsgs.MapToAuthDomain(
                           userId,
                           retrievedUser.Sid.Value,
                           authProvider,
                           domain,
                           retrievedUser.SamAccountName)));
            var subject = new Subject(
                subjectId,
                userId,
                retrievedUser.Sid.Value,
                authProvider,
                domain,
                createMsg);

            _repo.Save(subject);
            return(userId);
        }
Exemplo n.º 2
0
        public void can_retrieve_correlated_aggregate()
        {
            var command1 = CorrelatedMessage.NewRoot();
            var id       = Guid.NewGuid();
            var agg      = new CorrelatedAggregate(id, command1);

            agg.RaiseCorrelatedEvent();
            agg.RaiseCorrelatedEvent();
            _repo.Save(agg);

            var command2  = CorrelatedMessage.NewRoot();
            var recovered = _repo.GetById <CorrelatedAggregate>(id, command2);

            Assert.NotNull(recovered);
            Assert.Equal(2, recovered.Version);//zero based, includes created

            recovered.RaiseCorrelatedEvent();
            recovered.RaiseCorrelatedEvent();

            _repo.Save(recovered);
            var command3   = CorrelatedMessage.NewRoot();
            var recovered2 = _repo.GetById <CorrelatedAggregate>(id, command3);

            Assert.NotNull(recovered2);
            Assert.Equal(4, recovered2.Version);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Given the create role command, creates a role created event.
        /// </summary>
        public CommandResponse Handle(ApplicationMsgs.CreateRole cmd)
        {
            var application = _repo.GetById <SecuredApplication>(cmd.AppId, cmd);
            var pol         = application.Policies.First(p => p.Id == cmd.PolicyId);

            pol.AddRole(cmd.RoleId ?? Guid.NewGuid(), cmd.Name);
            _repo.Save(application);
            return(cmd.Succeed());
        }
Exemplo n.º 4
0
        public CommandResponse Handle(ApplicationMsgs.CreateApplication cmd)
        {
            if (_rm.ApplicationExists(cmd.Name, new Version(cmd.SecurityModelVersion)))
            {
                throw new DuplicateApplicationException(cmd.Name, cmd.SecurityModelVersion);
            }
            var app = new Domain.SecuredApplication(
                cmd.ApplicationId,
                cmd.DefaultPolicyId,
                cmd.Name,
                cmd.SecurityModelVersion,
                cmd.OneRolePerUser,
                cmd);

            _repo.Save(app);
            return(cmd.Succeed());
        }