public async Task LogForSignature(string nodeId, string fileId, string nextGroup, string nextOwner) { try { var nodeEntry = await _alfrescoHttpClient.GetNodeInfo(nodeId); var personEntry = await _alfrescoHttpClient.GetPerson(nextOwner); var groupEntry = await _alfrescoHttpClient.GetGroup(nextGroup); var pid = nodeEntry?.GetPid(); // Audit log for a document await _auditLogService.Record(nodeId, SpisumNames.NodeTypes.Document, pid, NodeTypeCodes.Dokument, EventCodes.PostoupeniAgende, string.Format(TransactinoHistoryMessages.DocumentForSignature, personEntry?.Entry?.DisplayName, groupEntry?.Entry?.DisplayName)); // Audit log for a file if (fileId != null) { await _auditLogService.Record(fileId, SpisumNames.NodeTypes.Document, pid, NodeTypeCodes.Dokument, EventCodes.PostoupeniAgende, string.Format(TransactinoHistoryMessages.DocumentForSignature, personEntry?.Entry?.DisplayName, groupEntry?.Entry?.DisplayName)); } } catch (Exception ex) { Log.Logger?.Error(ex, "Audit log failed"); } }
public async Task Init() { if (_initiated) { return; } _initiated = true; var configGroups = (_alfrescoConfig?.Groups != null ? JsonConvert.DeserializeObject <List <GroupModel> >(File.ReadAllText(_alfrescoConfig.Groups)) : new List <GroupModel>()).Select(x => x.Body).ToList(); var configUsers = _alfrescoConfig?.Users != null ? JsonConvert.DeserializeObject <List <UserARM> >(File.ReadAllText(_alfrescoConfig.Users)) : new List <UserARM>(); configUsers.Insert(0, SpisumAdmin); configUsers.Insert(0, EmailboxAdmin); configUsers.Insert(0, DataboxAdmin); configUsers.Insert(0, SpisumSuperuser); foreach (var user in configUsers) { await CheckCreateUser(user); } // add system user to all groups configGroups.Add(new GroupBodyCreate { Id = SpisumNames.Groups.RepositoryGroup }); configGroups.Add(new GroupBodyCreate { Id = SpisumNames.Groups.MailroomGroup }); foreach (var group in configGroups) { await _initialUser.CheckCreateGroupAndAddPerson(SpisumNames.SystemUsers.Spisum, group.Id); } // delete alfresco default users var deleteUsers = new[] { "abeecher", "mjackson" }; foreach (var user in deleteUsers) { try { var userInfo = await _alfrescoHttpClient.GetPerson(user); await _alfrescoHttpClient.DeletePerson(user); } catch { } } }
public UserCreateValidator(IAlfrescoHttpClient alfrescoHttpClient) { RuleFor(o => o) .Cascade(CascadeMode.StopOnFirstFailure) .Must(o => new Regex(@"^([a-zA-Z0-9_]+)$").IsMatch(o.Id)) .MustAsync(async(context, cancellationToken) => { try { await alfrescoHttpClient.GetPerson(context.Id); return(false); } catch { return(true); } }) .MustAsync(async(context, cancellationToken) => { var groups = new List <string>(); groups.AddRangeUnique(context.Groups); groups.AddRangeUnique(context.SignGroups); groups.Add(context.MainGroup); foreach (var group in groups) { if (!await groupExist(alfrescoHttpClient, group)) { return(false); } } return(true); }); }
public async Task <Authorization> Login(string username, string password) { var response = await _alfrescoHttpClient.Login(new TicketBody { UserId = username, Password = password }); var alfrescoProfile = await _alfrescoHttpClient.GetPerson("-me-", ImmutableList <Parameter> .Empty .Add(new Parameter(HeaderNames.Authorization, $"Basic {response.Entry.Id.ToAlfrescoAuthentication()}", ParameterType.HttpHeader))); return(_mapper.Map <Authorization>((response, alfrescoProfile, _alfrescoConfiguration, _signerConfiguration))); }
protected override async Task <AuthenticateResult> HandleAuthenticateAsync() { string authorization = Request.Headers[HeaderNames.Authorization]; if (string.IsNullOrEmpty(authorization)) { return(AuthenticateResult.Fail("Authentication not provided.")); } ClaimsPrincipal principal = null; if (!_simpleMemoryCache.IsExist(authorization)) { var alfrescoProfile = await _alfrescoHttpClient.GetPerson("-me-"); if (alfrescoProfile?.Entry?.Id != null) { principal = _mapper.Map <ClaimsPrincipal>((alfrescoProfile, authorization)); } if (principal?.Claims == null) { return(AuthenticateResult.Fail("Authentication not provided.")); } lock (Sync) { if (!_simpleMemoryCache.IsExist(authorization)) { _simpleMemoryCache.Create(authorization, principal, new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(_alfrescoConfiguration.TokenExpire ?? 30), Priority = CacheItemPriority.High }); } } } else { principal = _simpleMemoryCache.Get <ClaimsPrincipal>(authorization); } return(AuthenticateResult.Success(new AuthenticationTicket(principal, new AuthenticationProperties { AllowRefresh = false, IsPersistent = true }, "Alfresco Scheme"))); }
public async Task <NodeEntry> ToDocument(string conceptId, string authorId, string subject, int attachmentCount, GenerateSsid ssidConfiguration, DateTime?settleTo = null) { var authorInfo = await _alfrescoHttpClient.GetPerson(authorId); if (authorInfo == null) { throw new BadRequestException("", "Provided author does not exists"); } var myNode = await _alfrescoHttpClient.GetNodeInfo(AlfrescoNames.Aliases.My); var conceptInfo = await _alfrescoHttpClient.GetNodeInfo(conceptId); // Create a copy of concept var conceptCopyInfo = await _alfrescoHttpClient.NodeCopy(conceptId, new NodeBodyCopy { TargetParentId = myNode?.Entry?.Id, Name = IdGenerator.GenerateId() }); // Copy association of components var conceptChildrens = await _nodesService.GetSecondaryChildren(conceptId, SpisumNames.Associations.Components); await conceptChildrens.ForEachAsync(async x => { // Remove old versions old file and associate with new node await _nodesService.RemoveAllVersions(x?.Entry?.Id); }); var properties = conceptInfo?.Entry?.Properties?.As <JObject>().ToDictionary(); var authorProperties = authorInfo?.Entry?.Properties?.As <JObject>().ToDictionary(); // Save properties var documentInfo = await _alfrescoHttpClient.UpdateNode(conceptCopyInfo?.Entry?.Id, new NodeBodyUpdate { NodeType = SpisumNames.NodeTypes.Document } .AddProperty(SpisumNames.Properties.Pid, null) .AddProperty(SpisumNames.Properties.Author, authorId) .AddProperty(SpisumNames.Properties.Subject, subject) .AddProperty(SpisumNames.Properties.SettleToDate, settleTo) .AddProperty(SpisumNames.Properties.AttachmentsCount, attachmentCount) .AddProperty(SpisumNames.Properties.AuthorId, authorProperties.GetNestedValueOrDefault(SpisumNames.Properties.UserId)?.ToString()) .AddProperty(SpisumNames.Properties.AuthorOrgId, authorProperties.GetNestedValueOrDefault(SpisumNames.Properties.UserOrgId)?.ToString()) .AddProperty(SpisumNames.Properties.AuthorOrgName, authorProperties.GetNestedValueOrDefault(SpisumNames.Properties.UserOrgName)?.ToString()) .AddProperty(SpisumNames.Properties.AuthorOrgUnit, authorProperties.GetNestedValueOrDefault(SpisumNames.Properties.UserOrgUnit)?.ToString()) .AddProperty(SpisumNames.Properties.AuthorJob, authorProperties.GetNestedValueOrDefault(SpisumNames.Properties.UserJob)?.ToString()) .AddProperty(SpisumNames.Properties.AuthorOrgAddress, authorProperties.GetNestedValueOrDefault(SpisumNames.Properties.UserOrgAddress)?.ToString()) .AddProperty(SpisumNames.Properties.KeepForm, SpisumNames.StoreForm.Original) .AddProperty(SpisumNames.Properties.SenderType, SpisumNames.SenderType.Own) .AddProperty(SpisumNames.Properties.Sender, SpisumNames.Other.Own) .AddProperty(SpisumNames.Properties.Sender_Name, SpisumNames.Other.Own) .AddProperty(SpisumNames.Properties.Sender_Address, SpisumNames.Other.Own) .AddProperty(SpisumNames.Properties.Sender_Contact, SpisumNames.Other.Own) .AddProperty(SpisumNames.Properties.State, SpisumNames.State.Unprocessed) .AddProperty(AlfrescoNames.ContentModel.Owner, properties.GetNestedValueOrDefault(AlfrescoNames.ContentModel.Owner, "id")?.ToString()) .AddProperty(SpisumNames.Properties.Version, 1) ); // Create permissions for the node await _nodesService.CreatePermissions(conceptCopyInfo?.Entry?.Id, _identityUser.RequestGroup, _identityUser.Id); await _nodesService.MoveByPath(conceptCopyInfo?.Entry?.Id, SpisumNames.Paths.EvidenceDocumentsForProcessing(_identityUser.RequestGroup)); // Generate Ssid var conceptEntry = await _nodesService.GenerateSsid(conceptCopyInfo?.Entry?.Id, ssidConfiguration); // Delete deleted components var deletedComponents = await _nodesService.GetSecondaryChildren(conceptId, SpisumNames.Associations.DeletedComponents); await deletedComponents.ForEachAsync(async x => { await _nodesService.DeleteNodePermanent(x?.Entry?.Id); }); // Delete concept await _nodesService.DeleteNodePermanent(conceptId); try { var conceptPid = conceptInfo?.GetPid(); // Audit log for a document await _auditLogService.Record(documentInfo?.Entry.Id, SpisumNames.NodeTypes.Document, conceptPid, NodeTypeCodes.Dokument, EventCodes.Zalozeni, TransactinoHistoryMessages.ConceptToDocument); var fileId = await _documentService.GetDocumentFileId(documentInfo?.Entry.Id); if (fileId != null) { await _auditLogService.Record(fileId, SpisumNames.NodeTypes.Document, conceptPid, NodeTypeCodes.Dokument, EventCodes.Zalozeni, TransactinoHistoryMessages.ConceptToDocument); } } catch (Exception ex) { Log.Logger?.Error(ex, "Audit log failed"); } return(conceptEntry); }
public async Task <PersonEntryFixed> GetUserInfo([FromRoute] string userId) { return(await _alfrescoHttpClient.GetPerson(userId)); }