# SAMLSSO with LDAP roles

A SAML provider says who somebody is. Often it does not say which groups they are in, and the groups are what decides their folders. The directory knows the groups.

This page joins the two: [SAMLSSO](Plugin-SAMLSSO.md) signs the person in, and then hands the name to [CrushLDAPGroup](Plugin-CrushLDAPGroup.md), which looks up the groups and builds the user, with everything that plugin can do: roles with template users, home folders from the directory, key mappings.

SAMLSSO has a directory lookup of its own in the lower half of its screen. For plain "which groups is this person in", that is enough, and simpler. Use the linking described here when you want the full directory plugin, or when the same directory rules should serve SAML logins and password logins alike.

## How plugins are linked

A plugin can be told to pass an accepted login on to another plugin. The link is made by the **name of a configuration**.

Every plugin has a first configuration, which carries the plugin's own name, and can have more, each with a name you give: see [several configurations](Prefs-Plugins.md#several-configurations-of-one-plugin).

A configuration whose name is the name of another plugin, a tilde, and the name of one of that plugin's configurations, calls it:

| Name of the SAMLSSO configuration | Calls |
|---|---|
| `CrushLDAPGroup~` | the first configuration of CrushLDAPGroup |
| `CrushLDAPGroup~SAMLAuth` | the configuration of CrushLDAPGroup that is named `SAMLAuth` |

## Setting it up

### The directory side

1. In **CrushLDAPGroup**, **Add** a configuration and name it, say, `SAMLAuth`.
2. Set it up completely: the directory, the search, the roles, the home folder. Use its test buttons until **Validate User Login** shows the right result for a test name.
3. **Leave it not enabled.**

That last point is the heart of it. An enabled directory configuration answers every password login on the server. This one must answer only when SAMLSSO calls it. A configuration that is not enabled and is called by name still does its work.

### The SAML side

1. In **SAMLSSO**, untick **Enabled** on the first configuration, the one that cannot be renamed.
2. **Add** a configuration and name it `CrushLDAPGroup~SAMLAuth`.
3. Set up the provider in it, as on the [SAMLSSO page](Plugin-SAMLSSO.md). Tick **Enabled**.
4. Set **SAMLSSO Cache Time** to `-1`, so that SAMLSSO does not ask a directory itself.

### If you use "only used for Authentication"

When **SAMLSSO only used for Authentication** is ticked, the plugin keeps the lookup switched on behind it. To change the cache time: untick the box, set **SAMLSSO Cache Time** to `-1`, tick the box again, save. Otherwise nothing arrives from the directory plugin.

## What happens at a sign-in

1. The person signs in at the provider and comes back with the signed message.
2. SAMLSSO checks the message and takes the name.
3. It sees its own configuration's name and calls `CrushLDAPGroup`, configuration `SAMLAuth`, with that name.
4. CrushLDAPGroup finds the person in the directory, without a password, since the provider has vouched for them. It checks the roles and builds the user.
5. If the directory plugin refuses, because the person is in none of the roles, the sign-in is refused.

## Things to know

- **The names must fit.** The name the provider sends is the name the directory is searched for. If the provider sends `jdoe@example.com`, search by `userPrincipalName`; if `jdoe`, by `sAMAccountName`.
- **The link is by name.** Renaming either configuration breaks it silently: the SAML sign-in then finds no roles. After any rename, test.
- **The same pairing exists for Radius and CrushLDAPGroup**: RADIUS checks the password or the code, and the directory supplies the groups. The Radius configuration is named `CrushLDAPGroup~…` in the same way.
- **For folders from your own application** in place of a directory: [SAMLSSO with a web application](Plugin-SAMLSSO-WebApplication.md).

## Not tried for this page

Nothing was linked on the test server: it had no identity provider and no directory. The page follows the earlier documentation and the plugins' own messages.
