private static IEnumerable <IUserIdentity> Fill(HashSet <Guid> orgIds, UserSecurityContext ctx) { if (orgIds != null) { IIdentityProvider idp = IdentityManager.Instance.GetProvider(ctx); if (idp != null) { if (orgIds.Count > 0) { IUserIdentity id; HashSet <IUserIdentity> uids = new HashSet <IUserIdentity>(); foreach (Guid cur in orgIds) { id = idp.Get(cur); if (!Guid.Empty.Equals(id)) { uids.Add(id); } } return(uids); } } } return(null); }
public bool Activate(Guid token) { if (!Guid.Empty.Equals(token)) { if (resetTokens.ContainsKey(token)) { IIdentityProvider idProv = IdentityManager.Instance.GetProvider(ctx); UserIdentityBase userId = idProv.Get(resetTokens[token].Token); if (userId != null && userId.UserState != UserState.Dead) { resetTokens.Remove(token); userId.UserState = UserState.Active; if (idProv.Update(userId)) { IRoleProvider roles = AuthorizationManager.Instance.GetRoleProvider(ctx); if (roles != null) { Role r = roles.Get(new Guid("a55c4810-de06-466e-8f30-4f02b138186f")); if (r != null) { return(roles.AddToRole(r, userId)); } } } } } } return(false); }
private static void Get(HttpContext context, UserSecurityContext ctx, JObject body) { IUserAffiliationProvider prov = UserAffiliationManager.Instance.GetProvider(ctx); if (prov != null) { CompoundIdentity orgId = JsonUtils.ToId(body[JsonUtils.OwnerId]); if (orgId == null) { Guid userId = JsonUtils.ToGuid(body[userId]); IEnumerable <CompoundIdentity> ids = null; if (Guid.Empty.Equals(userId) || userId.Equals(ctx.Identity)) { //this is for self ids = prov.GetIds(ctx.User); } else { //this is for other IIdentityProvider idp = IdentityManager.Instance.GetProvider(ctx); if (idp != null) { IUserIdentity uid = idp.Get(userId); //make sure this is a valid user if (uid != null) { ids = prov.GetIds(uid); } } } if (ids != null) { JArray orgs = JsonUtils.ToJson(ids); if (orgs != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, orgs); return; } } } else //we're searching by org rather than by user { IOrganizationProvider oProv = OrganizationManager.Instance.GetOrganizationProvider(ctx); if (oProv != null) { Organization org = oProv.Get(orgId); if (org != null) { JArray uids = JsonUtils.ToJson(prov.GetIds(org)); if (uids != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, uids); return; } } } } RestUtils.Push(context.Response, JsonOpStatus.Failed); } }
public bool ChangePass(Guid sid, string user, Guid token, string newPass) { if (!Guid.Empty.Equals(sid)) { if (resetTokens.ContainsKey(token)) { ModuleRuntimeSession sess = Session.Prov.Get(sid); if (sess != null) { IIdentityProvider idProv = IdentityManager.Instance.GetProvider(ctx); UserIdentityBase userId = idProv.Get(resetTokens[token].Token); if (userId != null && userId.UserState != UserState.Dead) { IAuthenticationProvider authProv = AuthenticationManager.Instance.GetProvider(ctx); if (authProv.AddCredential(userId, new UserPasswordCredential(user, newPass))) { resetTokens.Remove(token); sess.SetUserBinding(userId.Uid, sess.Binding); Session.Prov.Update(sess); return(true); } } } } } return(false); }
public static TKey GetId <T, TKey>(this IIdentityProvider <TKey> identityProvider, T instance) where T : IIdentifiable <TKey> { var func = identityProvider.Get <T>().Compile(); return(func.Invoke(instance)); }
private static Expression <Func <T, bool> > CreateExpression(IIdentityProvider <TKey> identity, IEnumerable <TKey> keys) { var expression = identity.Get <T>(); var containsMethod = GetMethodInfo <TKey>(Enumerable.Contains); return(Expression.Lambda <Func <T, bool> >(Expression.Call(null, containsMethod, Expression.Constant(keys), expression.Body), expression.Parameters)); }
public static bool IsActive(this IIdentityProvider provider, IUserIdentity user) { if (provider != null && user != null) { UserIdentityBase uib = provider.Get(user.Uid); if (uib != null) { return(uib.UserState == UserState.Active); } } return(false); }
public static bool Validate(this IIdentityProvider provider, string identifier, string password, string role = "") { var principal = provider.Get(identifier); if (null == principal) { return(false); } if (false == string.IsNullOrEmpty(role) && false == principal.IsInRole(role)) { return(false); } return(provider.Validate(principal.Identity, password)); }
public static UserIdentityBase GetUser(HttpContext context) { Guid sid = Get(context); if (!Guid.Empty.Equals(sid)) { ModuleRuntimeSession sess = Prov.Get(sid); if (sess != null && !Guid.Empty.Equals(sess.UserId)) { return(IdProv.Get(sess.UserId)); } } return(null); }
public FactProcessor( DataChangesDetector <TFact> changesDetector, IBulkRepository <TFact> repository, IReadOnlyCollection <IFactDependencyProcessor> depencencyProcessors, IIdentityProvider <long> factIdentityProvider) { _repository = repository; _depencencyProcessors = depencencyProcessors; _indirectDepencencyProcessors = depencencyProcessors.Where(p => p.DependencyType == DependencyType.Indirect).ToArray(); _changesDetector = changesDetector; _findSpecificationProvider = new FindSpecificationProvider <TFact, long>(factIdentityProvider); _identityProvider = factIdentityProvider.Get <TFact>().Compile(); }
public bool ChangePass(Guid sid, string user, string oldPass, string newPass) { if (!Guid.Empty.Equals(sid)) { ModuleRuntimeSession sess = Session.Prov.Get(sid); if (sess != null && !Guid.Empty.Equals(sess.UserId)) //user must be logged in with a session to change password { IIdentityProvider idProv = IdentityManager.Instance.GetProvider(ctx); IUserIdentity userId = idProv.Get(sess.UserId); if (userId != null) { IAuthenticationProvider authProv = AuthenticationManager.Instance.GetProvider(ctx); return(authProv.ReplaceCredential(userId, new UserPasswordCredential(user, oldPass), new UserPasswordCredential(user, newPass))); } } } return(false); }
public TransportMessage TransportMessage(IServiceBusConfiguration configuration, IIdentityProvider identityProvider) { Guard.AgainstNull(identityProvider, nameof(identityProvider)); if (_local && !configuration.HasInbox) { throw new InvalidOperationException(Resources.SendToSelfException); } var identity = identityProvider.Get(); var result = new TransportMessage { RecipientInboxWorkQueueUri = _local ? configuration.Inbox.WorkQueue.Uri.ToString() : _recipientInboxWorkQueueUri, SenderInboxWorkQueueUri = string.IsNullOrEmpty(_sendInboxWorkQueueUri) ? configuration.HasInbox ? configuration.Inbox.WorkQueue.Uri.ToString() : string.Empty : _sendInboxWorkQueueUri, PrincipalIdentityName = identity != null ? identity.Name : AnonymousName, IgnoreTillDate = _ignoreTillDate, ExpiryDate = _expiryDate, Priority = _priority, MessageType = Message.GetType().FullName, AssemblyQualifiedName = Message.GetType().AssemblyQualifiedName, EncryptionAlgorithm = _encryptionAlgorithm ?? configuration.EncryptionAlgorithm, CompressionAlgorithm = _compressionAlgorithm ?? configuration.CompressionAlgorithm, MessageReceivedId = HasTransportMessageReceived ? _transportMessageReceived.MessageId : Guid.Empty, CorrelationId = _correlationId, SendDate = DateTime.Now }; result.Headers.Merge(Headers); return(result); }
public IEnumerable <IUserIdentity> Get(Organization org) { IEnumerable <Guid> ids = GetIds(org); //note, this should be empty if CanGet(org) is true and null if CanGet(org) is false if (ids != null) { List <IUserIdentity> users = new List <IUserIdentity>(); IUserIdentity tmp; IIdentityProvider iProv = IdProvider; foreach (Guid id in ids) { tmp = iProv.Get(id); if (tmp != null) { users.Add(tmp); } } return(users); } return(null); }
private readonly Dictionary <Guid, LoginToken> resetTokens = new Dictionary <Guid, LoginToken>(); //stored tokens here are key:token, value:<token, userid> public Guid Reset(string user, bool deleteCred) { IIdentityProvider idProv = IdentityManager.Instance.GetProvider(ctx); IEnumerable <UserIdentityBase> users = idProv.Get(user, UserType.Person); if (users != null) { foreach (UserIdentityBase u in users) { if (u.UserState != UserState.Dead && u.UserState != UserState.Unknown) { if (deleteCred) { IAuthenticationProvider authProv = AuthenticationManager.Instance.GetProvider(ctx); authProv.DeleteCredential(u, new UserPasswordCredential(user, user)); //TODO -- make sure this can work to kill a current credential } Guid tok = Guid.NewGuid(); resetTokens.Add(tok, new LoginToken(tok, u.Uid)); return(tok); } } } return(Guid.Empty); }
static void Create(UserSecurityContext context) { IIdentityProvider idProv = IdentityManager.Instance.GetProvider(context); OrganizationProviderBase orgProv = OrganizationManager.Instance.GetOrganizationProvider(context); UserAffiliationProviderBase prov = UserAffiliationManager.Instance.GetProvider(context); Organization org = orgProv.Get(new Osrs.Data.CompoundIdentity(new Guid("5914629d-dd2d-4f1f-a06f-1b199fe19b37"), new Guid("f9e1d49f-0b91-41cc-a88f-a24afa1a669e"))); IEnumerable <UserIdentityBase> ids = idProv.Get(); foreach (UserIdentityBase cur in ids) { if (!prov.HasAffiliation(cur, org)) { Console.WriteLine("Adding user " + cur.Name + " to org " + org.Name); prov.Add(cur, org); Console.WriteLine("Has affiliation? " + prov.HasAffiliation(cur, org) + ": " + cur.Name + " to " + org.Name); } else { Console.WriteLine("Already has affiliation " + cur.Name + " to org " + org.Name); } } }
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"); }