-
Notifications
You must be signed in to change notification settings - Fork 1
/
OperationLogger.cs
120 lines (102 loc) · 4.9 KB
/
OperationLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using System.Collections.Concurrent;
using System.Web;
using System;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.Web.ClientControls;
namespace AuthorizationService.Services {
public class OperationLogger: WebDocumentViewerOperationLogger,
IWebDocumentViewerAuthorizationService,
IExportingAuthorizationService
{
public override void ReportOpening(string reportId, string documentId, XtraReport report)
{
if (HttpContext.Current.Session == null) {
return;
}
SaveUsedEntityId(Constants.ReportDictionaryName, reportId);
SaveUsedEntityId(Constants.DocumentDictionaryName, documentId);
}
public override void BuildStarted(string reportId, string documentId,
ReportBuildProperties buildProperties)
{
SaveUsedEntityId(Constants.ReportDictionaryName, reportId);
SaveUsedEntityId(Constants.DocumentDictionaryName, documentId);
}
public override ExportedDocument ExportDocumentStarting(string documentId,
string asyncExportOperationId, string format, ExportOptions options,
PrintingSystemBase printingSystem, Func<ExportedDocument> doExportSynchronously)
{
SaveUsedEntityId(Constants.ExportedDocumentDictionaryName, asyncExportOperationId);
return base.ExportDocumentStarting(documentId, asyncExportOperationId, format, options,
printingSystem, doExportSynchronously);
}
public override void ReleaseDocument(string documentId) {
}
bool IWebDocumentViewerAuthorizationService.CanCreateDocument() {
return CheckUserAuthorized();
}
bool IWebDocumentViewerAuthorizationService.CanCreateReport() {
return CheckUserAuthorized();
}
bool IWebDocumentViewerAuthorizationService.CanReadDocument(string documentId) {
return CheckEntityAvailability(Constants.DocumentDictionaryName, documentId);
}
bool IWebDocumentViewerAuthorizationService.CanReadReport(string reportId) {
return CheckEntityAvailability(Constants.ReportDictionaryName, reportId);
}
bool IWebDocumentViewerAuthorizationService.CanReleaseDocument(string documentId) {
return CheckEntityAvailability(Constants.DocumentDictionaryName, documentId);
}
bool IWebDocumentViewerAuthorizationService.CanReleaseReport(string reportId) {
return CheckEntityAvailability(Constants.ReportDictionaryName, reportId);
}
public bool CanReadExportedDocument(string exportDocumentId) {
return CheckEntityAvailability(Constants.ExportedDocumentDictionaryName, exportDocumentId);
}
bool CheckUserAuthorized() {
var user = HttpContext.Current.User;
if (user == null || user.Identity == null || !user.Identity.IsAuthenticated)
{
return false;
}
return true;
}
void SaveUsedEntityId(string dictionaryName, string id) {
if (string.IsNullOrEmpty(id))
return;
ConcurrentDictionary<string, bool> dictionary = null;
lock (HttpContext.Current.Session.SyncRoot) {
if (HttpContext.Current.Session[dictionaryName] == null)
HttpContext.Current.Session[dictionaryName] = dictionary
= new ConcurrentDictionary<string, bool>();
}
if (dictionary == null)
dictionary = ((ConcurrentDictionary<string, bool>)HttpContext.Current.
Session[dictionaryName]);
dictionary.AddOrUpdate(id, false, (_1, _2) => false);
}
bool CheckEntityAvailability(string dictionaryName, string id) {
if (string.IsNullOrEmpty(id) || !CheckUserAuthorized())
return false;
lock (HttpContext.Current.Session.SyncRoot) {
if (HttpContext.Current.Session[dictionaryName] == null)
return false;
}
return
((ConcurrentDictionary<string, bool>)HttpContext.Current.
Session[dictionaryName]).ContainsKey(id);
}
void DisposeEntityRequested(string dictionaryName, string id) {
if (string.IsNullOrEmpty(id))
return;
lock (HttpContext.Current.Session.SyncRoot) {
if (HttpContext.Current.Session[dictionaryName] == null)
return;
}
((ConcurrentDictionary<string, bool>)HttpContext.Current.
Session[dictionaryName]).AddOrUpdate(id, true, (_1, _2) => true);
}
}
}