-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModuleConfig.cfc
More file actions
137 lines (121 loc) · 4.63 KB
/
Copy pathModuleConfig.cfc
File metadata and controls
137 lines (121 loc) · 4.63 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component {
// Module Properties
this.title = "cbSSO";
this.author = "Ortus Solutions";
this.webURL = "https://www.ortussolutions.com";
this.description = "@MODULE_DESCRIPTION@";
this.version = "@build.version@+@build.number@";
// Model Namespace
this.modelNamespace = "cbsso";
this.autoMapModels = true;
// CF Mapping
this.cfmapping = "cbSSO";
this.entryPoint = "/cbsso";
// Dependencies
// cbjavaloader is load-order critical, not merely installed: onLoad() hands it this module's /lib so the
// bundled OpenSAML jar becomes resolvable. A module cannot place that jar on the classpath itself -
// this.javaSettings is an Application.cfc setting, read before any module registers, and ColdBox does
// not merge a module's copy of it - so without cbjavaloader every consuming app would have to add
// cbsso's own lib path to its Application.cfc.
this.dependencies = [ "hyper", "jwtcfml", "cbjavaloader" ];
routes = [
{
pattern : "/auth/:providerName/start",
handler : "Auth",
action : "start"
},
{
pattern : "/auth/:providerName",
handler : "Auth",
action : "authorize"
}
];
/**
* Configure Module
*/
function configure(){
settings = {
enableCBAuthIntegration : false,
errorRedirect : "",
successRedirect : "",
// Leave blank to create the module's bounded default cache. Set this to the name of an existing
// CacheBox cache to use a distributed provider such as Redis or a database-backed cache.
samlRequestCacheName : "",
providers : [
// Your google login API credentials
// "google": {
// clientId : getSystemSetting( key = "GOOGLE_CLIENT_ID", defaultValue = "" ),
// clientSecret : getSystemSetting( key = "GOOGLE_CLIENT_SECRET", defaultValue = "" ),
// authEndpoint : "https://accounts.google.com/o/oauth2/v2/auth",
// accessTokenEndpoint : "https://www.googleapis.com/oauth2/v4/token",
// redirectUri : getSystemSetting( key = "GOOGLE_REDIRECT_URI", defaultValue = "" )
// }
]
};
interceptorSettings = { customInterceptionPoints : [ "CBSSOMissingProvider", "CBSSOAuthorization" ] };
};
/**
* Fired when the module is registered and activated.
*/
function onLoad(){
ensureSAMLRequestCache();
// Must precede registerProviders(): a SAML provider resolves cbsso.opensaml.* out of this path.
// Guarded because /lib is a build artifact of the Gradle project in /java and is absent from a
// source checkout, where appendPaths would throw "Invalid library path". Skipping it there leaves a
// SAML provider to fail on first use with its own error rather than taking the application down.
var openSAMLLibPath = modulePath & "/lib";
if ( directoryExists( openSAMLLibPath ) ) {
wirebox.getInstance( "loader@cbjavaloader" ).appendPaths( openSAMLLibPath );
}
wirebox.getInstance( "ProviderService@cbsso" ).registerProviders();
if ( settings.enableCBAuthIntegration ) {
controller
.getInterceptorService()
.registerInterceptor(
interceptorClass = "cbsso.interceptors.cbAuth",
interceptorProperties = settings,
interceptorName = "cbsso@global"
);
}
}
/**
* Fired when the module is unregistered and unloaded
*/
function onUnload(){
}
private void function ensureSAMLRequestCache(){
var configuredCacheName = settings.samlRequestCacheName;
if ( !len( trim( configuredCacheName ) ) ) {
configuredCacheName = "cbssoSAMLRequests";
settings.samlRequestCacheName = configuredCacheName;
if ( !cachebox.cacheExists( configuredCacheName ) ) {
cachebox.createCache(
name = configuredCacheName,
provider = "coldbox.system.cache.providers.CacheBoxProvider",
properties = {
objectDefaultTimeout : 10,
objectDefaultLastAccessTimeout : 0,
useLastAccessTimeouts : false,
reapFrequency : 1,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 10000,
objectStore : "ConcurrentStore"
}
);
}
} else if ( !cachebox.cacheExists( configuredCacheName ) ) {
throw(
type = "cbSSO.SAMLRequestCacheNotFound",
message = "The configured SAML request cache '#configuredCacheName#' is not registered with CacheBox.",
detail = "Register the cache in config/CacheBox.cfc or clear samlRequestCacheName to use the default cbSSO cache."
);
}
}
}