Esempio n. 1
0
        public ServiceResponse<ServiceCredentials> RegisterNewAccount(string ServiceLRI, string DomainLRI, string Username, string passwordHash)
        {
            //get LRI from domain / username / hash
            LRI UserLRI = IDMgr.GetUserLRI(new LRI(ServiceLRI), DomainLRI, Username, passwordHash);
            if (UserLRI == null)
            {
                return new ServiceResponse<ServiceCredentials>(true);
            }
            else
            {
                if (ClientAccountLookup.ContainsKey(UserLRI))
                {
                    ServiceResponse<ServiceCredentials> Resp = new ServiceResponse<ServiceCredentials>();
                    Resp.Error = true;
                    Resp.ErrorCode = 2;
                    Resp.Message = "A user with that LRI is already registered with this system.";
                    Resp.ResponseObject = null;
                    return Resp;
                }
                else
                {
                    //we need this info
                    UserInfo info = new UserInfo();//UserManager.Identities[UserLRI.LRIString];
                    info.passwordHash = passwordHash;
                    info.Identity = IDMgr.GetUserLIdentity(new LRI(ServiceLRI), DomainLRI, Username, passwordHash);

                    //create new account and add this LRI info
                    ClientAccount Acct = new ClientAccount();
                    Acct._id = LDocumentManager.RequestGUID();
                    Acct.AccountLRI = new LRI(LCHARMSConfig.GetSection().LRI + "/" + Acct._id);
                    ClientAccountLookupByAcctID[Acct._id] = Acct;
                    AddIdentityToAccount(Acct._id, info, UserLRI);
                    //ServiceCredentials sc = new ServiceCredentials();
                    //Acct.ServiceCredentialsByLRI[userlri] =

                    //create a header for the account
                    string ID = LDocumentManager.RequestGUID();
                    LDocumentHeader NewFileHeader = new LDocumentHeader();
                    LRI hlri = new LRI(LCHARMSConfig.GetSection().LRI + "/" + ID);
                    NewFileHeader.DocType = DocumentType.DOC_HEADER;
                    NewFileHeader.DocumentID = ID;
                    NewFileHeader.FQDT = "lcharms.client.account";
                    NewFileHeader.FileName = Username.ToLower() + ".client.account";
                    NewFileHeader.DocumentLRI = hlri.ToString();
                    NewFileHeader.IsCopy = false;
                    NewFileHeader.LastAccessDate = DateTime.Now;
                    NewFileHeader.DataLength = 0;

                    //create an ACL for this new file
                    // assign it to the creation user

                    DocManager.AuthManager.CreateACE(ID, info.Identity, LDocACLPermission.GRANT |
                                        LDocACLPermission.WRITE |
                                        LDocACLPermission.READ |
                                        LDocACLPermission.ACCESS_NEXT_VERSION |
                                        LDocACLPermission.ACCESS_PREV_VERSION);
                    DocManager.AuthManager.CreateACE(ID, DocManager.AuthManager.PublicIdentity, LDocACLPermission.DENY);

                    Acct.AccountHeader = NewFileHeader;
                    SaveAccount(Acct);

                    return LoginID(UserLRI, passwordHash,false);
                }
            }
        }
Esempio n. 2
0
        //login the ID and other IDs associated with the account.
        public ServiceResponse<ServiceCredentials> LoginID(LRI userLRI, string passwordHash, bool LoginAll = true)
        {
            //get account that matches
            if (ClientAccountLookup.ContainsKey(userLRI))
            {
                //login ID
                if(IDMgr.LoginWithHash(userLRI,passwordHash))
                {

                    //get acct
                    ClientAccount acct = ClientAccountLookup[userLRI];
                    //if this is the first login for this account, create a SessionKey
                    if (acct.ClientSessionKey == "")
                    {
                        acct.ClientSessionKey = Guid.NewGuid().ToString();

                    }
                    if (LoginAll)
                    {
                        //todo: if other accounts not logged in, log them in? (LoginAll)
                    }
                    //populate ServiceCredentials
                    ServiceCredentials creds =
                        new ServiceCredentials(userLRI.ToString(), IDMgr.Sessions[userLRI.ToString()].Session.SessionKey);
                    creds.ClientSessionKey = acct.ClientSessionKey;
                    creds.ClientAccountLRI = acct.AccountLRI;
                    ClientAccountLookupBySessionKey[acct.ClientSessionKey] = acct;
                    //return session key in the service response
                    ServiceResponse<ServiceCredentials> resp = new ServiceResponse<ServiceCredentials>();
                    resp.ResponseObject = creds;
                    resp.Message = "OK";
                    return resp;
                } else
                {
                    return new ServiceResponse<ServiceCredentials>(true);
                }
            }
            else
            {
                return new ServiceResponse<ServiceCredentials>(true);
            }
        }