> For the complete documentation index, see [llms.txt](https://coldbox-security.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-security.ortusbooks.com/get-started/quickstart.md).

# Quickstart

Secure your first route in five minutes.

This takes you from install to a secured route with a passing test.

## 1. Install

```bash
install cbsecurity
```

This also installs `cbauth` (login state) and `cbcsrf`. See [Installation](https://coldbox-security.ortusbooks.com/get-started/installation.md) for the supported engines.

## 2. Configure

Tell cbauth where your users live and tell the firewall where to send people who are not logged in:

```javascript
// config/ColdBox.cfc
moduleSettings = {
    cbauth     : { userServiceClass : "models.UserService" },
    cbsecurity : {
        firewall : { invalidAuthenticationEvent : "security.login" }
    }
}
```

## 3. Provide Your Users

Your user service must implement `isValidCredentials()`, `retrieveUserByUsername()` and `retrieveUserById()` (`cbsecurity.interfaces.IUserService`). The user it returns must implement `getId()`, `hasPermission()` and `hasRole()` (`IAuthUser`). You can start from the bundled [`User`](https://coldbox-security.ortusbooks.com/authentication/auth-user.md) object.

## 4. Secure a Route

With route middleware (ColdBox 8.2+), next to the route:

```javascript
// config/Router.cfc
route( "/account" ).middleware( "Authenticated@cbsecurity" ).to( "account.index" )

route( "/admin" )
    .middleware( "Authorized@cbsecurity" )
    .meta( { permissions : "ADMIN" } )
    .to( "admin.index" )
```

Or with an annotation on the handler, which works on any ColdBox version:

```javascript
component secured="ADMIN" {
    function index( event, rc, prc ){}
}
```

Prefer a central list? Use [security rules](https://coldbox-security.ortusbooks.com/secure-your-app/security-rules.md) instead. See [Overview](https://coldbox-security.ortusbooks.com/get-started/overview.md) to choose.

## 5. Test It

```javascript
it( "sends guests to the login", () => {
    var event = get( "/account" )
    expect( event.getValue( "relocate_event" ) ).toBe( "security.login" )
} )
```

Running middleware in `get()` and `post()` needs ColdBox 8.3+. Annotations and rules are tested the same way on any version.

## Where Next

* [How the Firewall Works](https://coldbox-security.ortusbooks.com/get-started/how-the-firewall-works.md): what happens when access is denied.
* [Route Middleware](https://coldbox-security.ortusbooks.com/secure-your-app/route-middleware.md): throttling, API keys, IP filtering and more.
* [JWT](https://coldbox-security.ortusbooks.com/jwt/jwt-services.md): securing a REST API.
* [Full Configuration](https://coldbox-security.ortusbooks.com/get-started/configuration/full-configuration.md): every setting.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-security.ortusbooks.com/get-started/quickstart.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
