Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
cbsecurity = {
// By default all rules are evulated as regular expressions
useRegex = true,
// Verify queries that they have all required columns, by default it is relaxed
queryChecks = false,
// Will verify rules of execute before ANY event. Be careful, can be intensive, usually the preProcess is enough.
preEventSecurity = false,
// The class path of a CFC that will validate rules, optional
validator = "class.path",
// The WireBox ID of the object to validate rules, optional
validatorModel = "wireboxID",
// The bean ID of the object in the ioc module that will validate the rules, optional
validatorIOC = "beanID.from.ioc.module",
// Where to look for security rules
rulesSource = "xml,json,db,model,ioc,ocm",
// The location of a rules file, aplies to XML and JSON only
rulesFile = "path.to.file",
// Rules DB Properties
rulesDSN = "datasource",
rulesTable = "table",
rulesSQL = "select * from rulesTable",
rulesOrderBy = "",
// Model Rule Properties
rulesModel = "wirebox.id",
rulesModelMethod = "method",
rulesModelArgs = "comma-delimmited list of args",
// IOC properties
rulesBean = "bean.id",
rulesBeanMethod = "method",
rulesBeanArgs = "comma-delimmited list of args",
// Cache key that has rules in the 'default' provider
rulesOCMKey = "key.from.default.provider"
}// Security Interceptor declaration.
interceptors = [
{ class="cbsecurity.interceptors.Security",
name="CBSecurity",
properties={
// please add the properties you want here to configure the security interceptor
rulesFile = "/cbsecurity/config/security.json.cfm",
rulesSource = "json"
} }
];<cflogin>
Your login logic here
<--- Log in the user with appropriate credentials --->
<cfloginuser name="name" password="password" roles="ROLES HERE">
</cflogin>
<--- Some Real sample --->
<cflogin>
<cfif getUserService().authenticate(rc.username,rc.password)>
<cfloginuser name="#rc.username#" password="#rc.password#" roles="#getUserService().getRoles(rc.username)#" />
</cfif>
</cflogin>interceptors = [
{class="cbsecurity.interceptors.Security", name="ApplicationSecurity", properties={
useRegex = true, rulesSource = "xml", validatorModel = "SecurityService",
rulesFile = "config/security.xml.cfm"
}}
];interceptors = [
{class="cbsecurity.interceptors.Security", name="ApplicationSecurity", properties={
useRegex = true, rulesSource = "ocm", validatorModel = "SecurityService",
rulesOCMKey = "qSecurityRules"
}}
];interceptors = [
{class="cbsecurity.interceptors.Security", name="ApplicationSecurity", properties={
useRegex = true, rulesSource = "json", validatorModel = "SecurityService",
rulesFile = "config/security.json.cfm"
}}
];[
{
"whitelist": "user\\.login,user\\.logout,^main.*",
"securelist": "^user\\.*, ^admin",
"match": "event",
"roles": "admin",
"permissions": "",
"redirect": "user.login",
"useSSL": false
},
{
"whitelist": "",
"securelist": "^shopping",
"match": "url",
"roles": "",
"permissions": "shop,checkout",
"redirect": "user.login",
"useSSL": true
}
]interceptors = [
{class="cbsecurity.interceptors.Security", name="ApplicationSecurity", properties={
useRegex = true, rulesSource = "db", validatorModel = "SecurityService",
rulesDSN = "myApp", rulesTable = "securityRules", rulesOrderBy = "order asc"
}}
];interceptors = [
{class="cbsecurity.interceptors.Security", name="ApplicationSecurity", properties={
useRegex = true, rulesSource = "ioc", validatorModel = "SecurityService",
rulesBean = "SecurityService", rulesBeanMethod = "getRules", rulesBeanArgs = "sorting=true"
}}
];<?xml version="1.0" encoding="ISO-8859-1"?>
<-- <
Declare as many rule elements as you want, order is important
Remember that the securelist can contain a list of regular
expressions if you want
ex: All events in the user handler
user\..*
ex: All events
.*
ex: All events that start with admin
^admin
If you are not using regular expressions, just write the text
that can be found in an event.
-->
<rules>
<rule>
<match>event</match>
<whitelist>user\.login,user\.logout,^main.*</whitelist>
<securelist>^user\..*, ^admin</securelist>
<roles>admin</roles>
<permissions>read,write</permissions>
<redirect>user.login</redirect>
</rule>
<rule>
<match>event</match>
<whitelist></whitelist>
<securelist>^moderator</securelist>
<roles>admin,moderator</roles>
<permissions>read</permissions>
<redirect>user.login</redirect>
</rule>
<rule>
<match>url</match>
<whitelist></whitelist>
<securelist>/secured.*</securelist>
<roles>admin,paid_subscriber</roles>
<permissions></permissions>
<redirect>user.pay</redirect>
</rule>
</rules><match>event</match><whitelist>user\.login,user\.logout,^main.*</whitelist><securelist>^user\..*, ^admin</securelist><roles>admin</roles><permissions>read,write</permissions><redirect>user.login</redirect><match>event</match><whitelist></whitelist><securelist>^moderator</securelist><roles>admin,moderator</roles><permissions>read</permissions><redirect>user.login</redirect><match>URL</match><whitelist></whitelist><securelist>/secured.*</securelist><roles>admin,paid_subscriber</roles><permissions></permissions><redirect>user.pay</redirect>boolean userValidator( rule:struct, controller:coldbox.system.web.Controller )<!--- User Validator for security --->
<cffunction name="userValidator" access="public" returntype="boolean" output="false" hint="Verifies that the user is in any permission">
<!---************************************************************** --->
<cfargument name="rule" required="true" type="struct" hint="The rule to verify">
<cfargument name="controller" type="any" required="true" hint="The coldbox controller" />
<!---************************************************************** --->
<!--- Local call to get the user object from the session --->
<cfset var oUser = getUserSession()>
<!--- The results boolean variable I will return --->
<cfset var results = false>
<!--- The permission I am checkin --->
<cfset var thisPermission = "">
<!--- Authorized Check, if true, then see if user is valid. This column is an additional column in my query --->
<cfif arguments.rule['authorize_check'] and oUser.getisAuthorized()>
<!--- I first check if the user is authorized or not if set in the db rules --->
<cfset results = true>
</cfif>
<!--- Loop Over Permissions to see if my user is in any of them. --->
<cfloop list="#arguments.rule['permissions']#" index="thisPermission">
<!--- My user object has a method called check permission that I call with a permission to validate --->
<cfif oUser.checkPermission( thisPermission ) >
<!--- This permission existed, I only need one to match as per my business logic, so let's return and move on --->
<cfset results = true>
<cfbreak>
</cfif>
</cfloop>
<!--- I now return whether the user can view the incoming rule or not --->
<cfreturn results>
</cffunction>#html.startForm(action=prc.xehDoLogin,name="loginForm",novalidate="novalidate")#
<---< Secured URL --->
#html.hiddenField(name="_securedURL",value=event.getValue('_securedURL',''))#
#html.textfield(name="username",label="Username: ",size="40",required="required",class="textfield",value=prc.rememberMe)#
#html.passwordField(name="password",label="Password: ",size="40",required="required",class="textfield")#
<div id="loginButtonbar">
#html.checkBox(name="rememberMe",value=true,checked=(len(prc.rememberMe)))#
#html.label(field="rememberMe",content="Remember Me ",class="inline")#
#html.submitButton(value=" Log In ",class="buttonred")#
</div>
<br/>
<img src="#prc.cbRoot#/includes/images/lock.png" alt="lostPassword" />
<a href="#event.buildLink(prc.xehLostPassword)#">Lost your password?</a>
#html.endForm()#/**
* User Validator for security
*
* @hint Verifies that the user is in any permission
* @rule.hint The rule to verify
* @controller.hint The ColdBox controller
*/
public boolean function userValidator( required struct rule, required any controller ) {
// Local call to get the user object from the session
var user = getUserSession();
// Authorized Check, if true, then see if user is valid. This column is an additional column in my query
if ( arguments.rule['authorize_check'] and user.getIsAuthorized() ) {
return true;
}
// Loop Over Permissions to see if my user is in any of them.
var permissionsArray = ListToArray(arguments.rule['permissions']);
for (var permission in permissionsArray) {
// My user object has a method called check permission that I call with a permission to validate
if ( user.checkPermission( permission ) ) {
// This permission existed, I only need one to match as per my business logic, so let's return and move on
return true;
}
}
// If we got here, the user does not have permission
return false;
}