/
Program.cs
106 lines (95 loc) · 5.56 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.ExpressApp.Security.ClientServer;
using System.Configuration;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Xpo;
using DevExpress.ExpressApp.MiddleTier;
using SecuredExportExample.Module.BusinessObjects;
using SecuredExportExample.Module.SecurityObjects;
using System.ServiceModel;
using DevExpress.ExpressApp.Security.ClientServer.Wcf;
namespace SecuredExportExample.MiddleTierSecurityServer {
class Program {
private static void serverApplication_DatabaseVersionMismatch(object sender, DatabaseVersionMismatchEventArgs e) {
e.Updater.Update();
e.Handled = true;
}
private static void serverApplication_CreateCustomObjectSpaceProvider(object sender, CreateCustomObjectSpaceProviderEventArgs e) {
e.ObjectSpaceProvider = new XPObjectSpaceProvider(e.ConnectionString, e.Connection);
}
static void Main(string[] args) {
try {
ValueManager.ValueManagerType = typeof(MultiThreadValueManager<>).GetGenericTypeDefinition();
InMemoryDataStoreProvider.Register();
string connectionString = InMemoryDataStoreProvider.ConnectionString;
Console.WriteLine("Starting...");
ServerApplication serverApplication = new ServerApplication();
// Change the ServerApplication.ApplicationName property value. It should be the same as your client application name.
serverApplication.ApplicationName = "SecuredExportExample";
// Add your client application's modules to the ServerApplication.Modules collection here.
serverApplication.Modules.Add(new DevExpress.ExpressApp.SystemModule.SystemModule());
serverApplication.Modules.Add(new DevExpress.ExpressApp.Win.SystemModule.SystemWindowsFormsModule());
serverApplication.Modules.Add(new DevExpress.ExpressApp.Security.SecurityModule());
serverApplication.Modules.Add(new SecuredExportExample.Module.SecuredExportExampleModule());
serverApplication.DatabaseVersionMismatch += new EventHandler<DatabaseVersionMismatchEventArgs>(serverApplication_DatabaseVersionMismatch);
serverApplication.CreateCustomObjectSpaceProvider += new EventHandler<CreateCustomObjectSpaceProviderEventArgs>(serverApplication_CreateCustomObjectSpaceProvider);
serverApplication.ConnectionString = connectionString;
Console.WriteLine("Setup...");
serverApplication.Setup();
Console.WriteLine("CheckCompatibility...");
serverApplication.CheckCompatibility();
serverApplication.Dispose();
Console.WriteLine("Starting server...");
QueryRequestSecurityStrategyHandler securityProviderHandler = delegate() {
SecurityStrategyComplex security = new SecurityStrategyComplex(
typeof(Employee), typeof(ExtendedSecurityRole), new AuthenticationStandard());
security.CustomizeRequestProcessors +=
delegate(object sender, CustomizeRequestProcessorsEventArgs e) {
List<IOperationPermission> result = new List<IOperationPermission>();
if (security != null) {
Employee user = security.User as Employee;
if (user != null) {
foreach (ExtendedSecurityRole role in user.Roles) {
if (role.CanExport) {
result.Add(new ExportPermission());
}
}
}
}
IPermissionDictionary permissionDictionary = new PermissionDictionary((IEnumerable<IOperationPermission>)result);
e.Processors.Add(typeof(ExportPermissionRequest), new ExportPermissionRequestProcessor(permissionDictionary));
};
return security;
};
WcfDataServerHelper.AddKnownType(typeof(ExportPermissionRequest));
SecuredDataServer dataServer = new SecuredDataServer(
connectionString, XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary,
securityProviderHandler);
ServiceHost serviceHost = new ServiceHost(new WcfSecuredDataServer(dataServer));
serviceHost.AddServiceEndpoint(typeof(IWcfSecuredDataServer),
WcfDataServerHelper.CreateDefaultBinding(), "http://localhost:1451/DataServer");
serviceHost.Open();
Console.WriteLine("Server is started. Press Enter to stop.");
#if !EASYTEST
Console.ReadLine();
#else
// 20 seconds is enough to pass all tests:
System.Threading.Thread.Sleep(20000);
#endif
Console.WriteLine("Stopping...");
serviceHost.Close();
Console.WriteLine("Server is stopped.");
}
catch (Exception e) {
Console.WriteLine("Exception occurs: " + e.Message);
Console.WriteLine("Press Enter to close.");
Console.ReadLine();
}
}
}
}