Exemple #1
0
        static void Main(string[] args)
        {
            ConfigurationManager.Instance.Bootstrap();
            ConfigurationManager.Instance.Initialize();
            ConfigurationManager.Instance.Start();
            Console.WriteLine("Config: " + ConfigurationManager.Instance.State.ToString());

            LogManager.Instance.Bootstrap();
            LogManager.Instance.Initialize();
            LogManager.Instance.Start();

            Console.WriteLine("Log: " + LogManager.Instance.State.ToString());

            AuthorizationManager.Instance.Bootstrap();
            AuthorizationManager.Instance.Initialize();
            AuthorizationManager.Instance.Start();
            Console.WriteLine("Auth: " + AuthorizationManager.Instance.State.ToString());

            LocalSystemUser     u   = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
            UserSecurityContext ctx = new UserSecurityContext(u);

            RegisterPerms(ctx);

            Console.WriteLine("Bootstrapping");
            IdentityManager.Instance.Bootstrap();
            Console.WriteLine("State: " + IdentityManager.Instance.State.ToString());
            Console.WriteLine("Initializing");
            IdentityManager.Instance.Initialize();
            Console.WriteLine("State: " + IdentityManager.Instance.State.ToString());
            Console.WriteLine("Starting");
            IdentityManager.Instance.Start();
            Console.WriteLine("State: " + IdentityManager.Instance.State.ToString());


            if (IdentityManager.Instance.State == Osrs.Runtime.RunState.Running)
            {
                IIdentityProvider perms = IdentityManager.Instance.GetProvider(ctx);
                Console.WriteLine("AdminUser Exists: " + perms.Exists(SecurityUtils.AdminIdentity));
                Console.WriteLine("CanCreate: " + perms.CanCreate());
            }

            Console.WriteLine("Done, enter to exit");
            Console.ReadLine();
        }
Exemple #2
0
        private void SignUp(HttpContext context, CancellationToken cancel)
        {
            string url = this.ActivateUrl;

            if (!string.IsNullOrEmpty(url))
            {
                IQueryCollection qry = context.Request.Query;
                string           ty  = qry[type];
                if (knownType.Equals(ty))
                {
                    string u = qry[user];
                    if (!string.IsNullOrEmpty(u))
                    {
                        string p = qry[pass];
                        if (!string.IsNullOrEmpty(p))
                        {
                            if (ValidUserEmail(u))
                            {
                                IIdentityProvider idProv = IdentityManager.Instance.GetProvider(ctx);
                                if (!idProv.Exists(u))
                                {
                                    IAuthenticationProvider authProv = AuthenticationManager.Instance.GetProvider(ctx);
                                    UserIdentityBase        user     = idProv.CreateUser(u);
                                    user.UserState = UserState.Pending;
                                    idProv.Update(user);
                                    UserPasswordCredential cred = new UserPasswordCredential(u, p);
                                    if (authProv.AddCredential(user, cred))
                                    {
                                        Guid token = Authenticator.Instance.Reset(u, false); //create a reset token
                                        //notice we create a url with the token at the end, this COULD map to the REST api directly - but is expected instead not to
                                        //we instead expect this to be a simple page that makes the rest request and "looks pretty" to confirm and perhaps send the user then back to the signin page.
                                        if (url.EndsWith("?"))
                                        {
                                            url = url + token.ToString();
                                        }
                                        else
                                        {
                                            url = url + "?" + token.ToString();
                                        }

                                        if (SendEmail(u, url, false))
                                        {
                                            RestUtils.Push(context.Response, JsonOpStatus.Ok);
                                            return;
                                        }
                                        else
                                        {
                                            idProv.Delete(user.Uid);
                                            authProv.DeleteCredential(user, cred);
                                            RestUtils.Push(context.Response, JsonOpStatus.Failed, "\"Couldn't send email\"");
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        idProv.Delete(user.Uid);
                                        authProv.DeleteCredential(user, cred);
                                        RestUtils.Push(context.Response, JsonOpStatus.Failed, "\"Couldn't set credential\"");
                                        return;
                                    }
                                }
                                else
                                {
                                    RestUtils.Push(context.Response, JsonOpStatus.Failed, "\"UserExists\"");
                                    return;
                                }
                            }
                            else
                            {
                                RestUtils.Push(context.Response, JsonOpStatus.Failed, "\"InvalidEmail\"");
                                return;
                            }
                        }
                    }
                }
            }
            RestUtils.Push(context.Response, JsonOpStatus.Failed);
        }
Exemple #3
0
        static void DoWork(string[] args)
        {
            AuthenticationManager.Instance.Bootstrap();
            Console.WriteLine("Authent state: " + AuthenticationManager.Instance.State);
            if (AuthenticationManager.Instance.State != Osrs.Runtime.RunState.Bootstrapped)
            {
                return;
            }

            AuthenticationManager.Instance.Initialize();
            Console.WriteLine("Authent state: " + AuthenticationManager.Instance.State);
            if (AuthenticationManager.Instance.State != Osrs.Runtime.RunState.Initialized)
            {
                return;
            }

            AuthenticationManager.Instance.Start();
            Console.WriteLine("Authent state: " + AuthenticationManager.Instance.State);
            if (AuthenticationManager.Instance.State != Osrs.Runtime.RunState.Running)
            {
                return;
            }

            LocalSystemUser     u   = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
            UserSecurityContext ctx = new UserSecurityContext(u);

            string            myUname = "*****@*****.**";
            IIdentityProvider accts   = IdentityManager.Instance.GetProvider(ctx);
            UserIdentityBase  user    = null;

            if (!accts.Exists(myUname))
            {
                Console.WriteLine("Creating user account");
                user = accts.CreateUser(myUname);
            }
            else
            {
                Console.WriteLine("Fetching user account");
                IEnumerable <UserIdentityBase> users = accts.Get(myUname, UserType.Person);
                if (users != null)
                {
                    foreach (UserIdentityBase cur in users)
                    {
                        user = cur;
                        break;
                    }
                }
            }

            if (user == null)
            {
                Console.WriteLine("Failed to get/create user");
                return;
            }


            IAuthenticationProvider provider = AuthenticationManager.Instance.GetProvider(ctx);
            UserPasswordCredential  cred     = new UserPasswordCredential(myUname, "Hello World");
            IUserIdentity           u2       = provider.Authenticate(cred);

            if (u2 == null)
            {
                Console.WriteLine("Didn't authenticate -- adding credential");
                if (!provider.AddCredential(user, cred))
                {
                    Console.WriteLine("Failed to add credential");
                    return;
                }

                u2 = provider.Authenticate(cred);
                if (u2 == null)
                {
                    Console.WriteLine("Didn't authenticate -- giving up");
                    return;
                }
                else
                {
                    Console.WriteLine("Authenticated second try");
                }
            }
            else
            {
                Console.WriteLine("Authenticated first try");
            }

            Console.WriteLine("Replacing credential with same (should fail)");
            if (provider.ReplaceCredential(u2, cred, cred))
            {
                Console.WriteLine("Replace credential succeeded -- a failing result");
                return;
            }
            else
            {
                Console.WriteLine("Replace credential failed -- a successful result");
            }

            UserPasswordCredential cred2 = new UserPasswordCredential(myUname, "Alabaster Barkers 123");

            Console.WriteLine("Replacing credential with different (should succeed)");
            if (provider.ReplaceCredential(u2, cred, cred2))
            {
                Console.WriteLine("Replace credential succeeded -- a successful result");
            }
            else
            {
                Console.WriteLine("Replace credential failed -- a failing result");
                return;
            }

            u2 = provider.Authenticate(cred);
            if (u2 == null)
            {
                Console.WriteLine("Didn't authenticate with old credential -- successful");
                u2 = provider.Authenticate(cred2);
                if (u2 != null)
                {
                    Console.WriteLine("Authenticated with new credential -- successful");
                    return;
                }
            }
            Console.WriteLine("Password change didn't work out");
        }