Esempio n. 1
0
 public User(Credentials credentials,
             SysAuthToken token,
             string name,
             Rights rights, DateTime?utcNow = null) : this(credentials, token, UserStatus.User, name, null, rights, utcNow)
 {
 }
Esempio n. 2
0
        public User Authenticate(Credentials credentials)
        {
            if (credentials is BearerCredentials bearer)
            {
                var oauth       = App.ModuleRoot.Get <Services.IOAuthModule>();
                var accessToken = oauth.TokenRing.GetAsync <Tokens.AccessToken>(bearer.Token).GetAwaiter().GetResult(); //since this manager is sync-only
                if (accessToken != null)                                                                                //if token is valid
                {
                    if (SysAuthToken.TryParse(accessToken.SubjectSysAuthToken, out var sysToken))
                    {
                        return(Authenticate(sysToken));
                    }
                }
            }

            var sect = m_Config ?? App.ConfigRoot[CommonApplicationLogic.CONFIG_SECURITY_SECTION];

            if (sect.Exists)
            {
                IConfigSectionNode usern = sect.Configuration.EmptySection;

                if (credentials is IDPasswordCredentials idpass)
                {
                    usern = findUserNode(sect, idpass);
                }
                if (credentials is EntityUriCredentials enturi)
                {
                    usern = findUserNode(sect, enturi);
                }

                if (usern.Exists)
                {
                    var name   = usern.AttrByName(CONFIG_NAME_ATTR).ValueAsString(string.Empty);
                    var descr  = usern.AttrByName(CONFIG_DESCRIPTION_ATTR).ValueAsString(string.Empty);
                    var status = usern.AttrByName(CONFIG_STATUS_ATTR).ValueAsEnum(UserStatus.Invalid);

                    var rights = Rights.None;

                    var rightsn = usern[CONFIG_RIGHTS_SECTION];

                    if (rightsn.Exists)
                    {
                        var data = new MemoryConfiguration();
                        data.CreateFromNode(rightsn);
                        rights = new Rights(data);
                    }

                    return(new User(credentials,
                                    credToAuthToken(credentials),
                                    status,
                                    name,
                                    descr,
                                    rights, App.TimeSource.UTCNow));
                }
            }

            return(new User(credentials,
                            new SysAuthToken(),
                            UserStatus.Invalid,
                            StringConsts.SECURITY_NON_AUTHENTICATED,
                            StringConsts.SECURITY_NON_AUTHENTICATED,
                            Rights.None, App.TimeSource.UTCNow));
        }
Esempio n. 3
0
 public Task <User> AuthenticateAsync(Credentials credentials) => Task.FromResult(User.Fake);
Esempio n. 4
0
 public Task <User> AuthenticateAsync(Credentials credentials) => Task.FromResult(Authenticate(credentials));
Esempio n. 5
0
 public User Authenticate(Credentials credentials) => User.Fake;