示例#1
0
        //public static IUserGroupPermissionProvider DefaultUserGroupPermissionProvider()
        //{
        //    return new DefaultUserGroupPermissionProvider();
        //}

        public override Task <AdobeConnectUser> FindAsync(string userName, string password)
        {
            Task <AdobeConnectUser> taskInvoke = Task.Run(async() =>
            {
                string[] parts      = userName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                string companyToken = parts[0];
                string acDomain     = parts[1];
                string acLogin      = parts[2];

                if (!_acDomainValidator.IsValid(companyToken, acDomain))
                {
                    _logger?.Warn($"[UserManager.FindAsync] AC domain is not valid for companyToken. AcDomain={acDomain}");
                    return(null);
                }

                string sessionToken;
                var connectionDetails = new ConnectionDetails(new Uri(acDomain));
                var provider          = new AdobeConnectProvider(connectionDetails);
                UserInfo acPrincipal  = TryLogin(provider, new AdobeConnectAccess(new Uri(acDomain), acLogin, password), out sessionToken);
                _logger?.Info($"[UserManager.FindAsync] ACSession={sessionToken}");

                if (acPrincipal == null)
                {
                    _logger?.Warn($"[UserManager.FindAsync] Principal not found. AcDomain={acDomain}, AcLogin={acLogin}");
                    return(null);
                }

                var roles = new List <string>();
                if (_userAuthorizationProvider != null)
                {
                    roles.AddRange(_userAuthorizationProvider.GetUserPermissions(provider, acPrincipal));
                }

                var applicationUser = new AdobeConnectUser
                {
                    Id       = acPrincipal.UserId,
                    UserName = acLogin,

                    CompanyToken   = companyToken,
                    AcDomain       = acDomain,
                    AcSessionToken = sessionToken,
                    Roles          = roles
                };
                var store = Store as IEdugameCloudUserStore <AdobeConnectUser>;
                if (store != null)
                {
                    var user = await store.FindByPrincipalIdAndCompanyTokenAndAcDomainAsync(applicationUser.Id, companyToken,
                                                                                            acDomain);
                    if (user == null)
                    {
                        _logger?.Warn($"[UserManager.FindAsync] UserStore.CreateAsync. PrincipalId={applicationUser.Id}");
                        await store.CreateAsync(applicationUser, password);
                    }
                }

                return(applicationUser);
            });

            return(taskInvoke);
        }
示例#2
0
        public Task <AdobeConnectUser> FindAsync(string userName, string password)
        {
            string[] parts        = userName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            string   companyToken = parts[0];
            string   acDomain     = parts[1];
            string   acLogin      = parts[2];

            if (!_acDomainValidator.IsValid(companyToken, acDomain))
            {
                _logger?.Warn($"[UserManager.FindAsync] AC domain is not valid for companyToken. AcDomain={acDomain}");
                return(Task.FromResult <AdobeConnectUser>(null));
            }

            string   sessionToken;
            var      connectionDetails = new ConnectionDetails(new Uri(acDomain));
            var      provider          = new AdobeConnectProvider(connectionDetails);
            UserInfo acPrincipal       = TryLogin(provider, new AdobeConnectAccess(new Uri(acDomain), acLogin, password), out sessionToken);

            _logger?.Info($"[UserManager.FindAsync] ACSession={sessionToken}");

            if (acPrincipal == null)
            {
                _logger?.Warn($"[UserManager.FindAsync] Principal not found. AcDomain={acDomain}, AcLogin={acLogin}");
                return(Task.FromResult <AdobeConnectUser>(null));
            }

            var roles = new List <string>();

            if (_userAuthorizationProvider != null)
            {
                roles.AddRange(_userAuthorizationProvider.GetUserPermissions(provider, acPrincipal));
            }

            var applicationUser = new AdobeConnectUser
            {
                Id       = acPrincipal.UserId,
                UserName = acLogin,

                CompanyToken   = companyToken,
                AcDomain       = acDomain,
                AcSessionToken = sessionToken,
                Roles          = roles
            };

            return(Task.FromResult(applicationUser));
        }