Repository navigation
Expand file tree
/
Copy pathModuleConfig.cfc
More file actions
88 lines (77 loc) · 4.54 KB
/
Copy pathModuleConfig.cfc
File metadata and controls
88 lines (77 loc) · 4.54 KB
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
component {
// The module has no required dependencies. SQLTokenStorage uses queryExecute(), which is built
// into CFML. QBTokenStorage loads qb only when an application chooses that storage provider.
this.title = "rememberMe";
// Register each model in onLoad() with an explicit WireBox name.
this.autoMapModels = false;
// Load the remember() application helper.
this.applicationHelper = [ "helpers/Mixins.cfm" ];
function configure() {
variables.settings = {
userServiceClass = "",
tokenEncryptKey = "", // Create a key with generateSecretKey("AES", 256).
tokenEncryptAlgorithm = "aes",
validatorHashAlgorithm = "MD5",
days = 30,
autoPurge = true, // Set this to false to disable the daily removal of old token rows.
purgeGraceDays = 1, // Keep an expired row for this many days. Use 0 to remove it after expiration.
purgeTime = "04:00", // Run the daily purge at this time in the server's time zone.
tokenStorageClass = "SQLTokenStorage@rememberMe", // WireBox name for a provider that follows ITokenStorage.cfc.
table = "user_remember", // Table used by the SQL and qb storage providers.
datasource = "" // Leave this empty to use the application's default datasource.
};
// Register the event announced after the service recalls a user.
variables.interceptorSettings = {
customInterceptionPoints = [
"onRecall"
]
};
}
function onLoad() {
binder.map( "RememberMeService@rememberMe" ).to( "#moduleMapping#.models.RememberMeService" );
// Use the dependency-free SQL provider by default.
binder.map( "SQLTokenStorage@rememberMe" ).to( "#moduleMapping#.models.SQLTokenStorage" );
// A singleton is one shared instance. MemoryTokenStorage must use a singleton so its saved
// tokens are still available when another service asks for the provider.
binder
.map( "MemoryTokenStorage@rememberMe" )
.to( "#moduleMapping#.models.MemoryTokenStorage" )
.asSingleton();
// This optional provider asks WireBox for qb only after an application selects the provider.
// The mapping can exist even when qb is not installed.
binder.map( "QBTokenStorage@rememberMe" ).to( "#moduleMapping#.models.QBTokenStorage" );
// Build the service and storage during startup. The purge task needs both objects later.
// WireBox reads a component file the first time it builds an object from a mapping. If that
// first build fails, WireBox removes the mapping. Without the restore code below, later
// requests cannot use that mapping until the application restarts. Building the objects
// here reports the first failure in the startup log before the scheduler runs.
try {
wirebox.getInstance( "RememberMeService@rememberMe" );
} catch ( any e ) {
// Keep loading the application if the service cannot build. Restore the service mapping
// if WireBox removed it. The next request can then try the build again.
if ( !binder.mappingExists( "RememberMeService@rememberMe" ) ) {
binder.map( "RememberMeService@rememberMe" ).to( "#moduleMapping#.models.RememberMeService" );
}
log.error( "rememberMe could not build RememberMeService during startup. #e.message# #e.detail#", e );
}
try {
// Ask WireBox for the configured storage in the same way that RememberMeService does.
wirebox.getInstance( dsl = settings.tokenStorageClass );
} catch ( any e ) {
// Restore only the default storage mapping owned by this module. A custom mapping
// belongs to the host application and may be registered by a module that starts later.
// Do not replace a custom mapping or stop the application from loading. The service can
// try to find the custom storage again when it is first used.
if (
settings.tokenStorageClass == "SQLTokenStorage@rememberMe"
&& !binder.mappingExists( "SQLTokenStorage@rememberMe" )
) {
binder.map( "SQLTokenStorage@rememberMe" ).to( "#moduleMapping#.models.SQLTokenStorage" );
}
log.error( "rememberMe could not build token storage [#settings.tokenStorageClass#] during startup. #e.message# #e.detail#", e );
}
}
function onUnload() {
}
}