Skip to content

Commit

Permalink
Add: GUID Transformation Callable
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubDolba committed Jun 12, 2019
1 parent 5d1ea13 commit 293a588
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions _config/saml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SilverStripe\SAML\Services\SAMLConfiguration:
debug: false
expect_binary_nameid: true
allow_insecure_email_linking: false
guid_transformation_callable: null
Security:
# Algorithm that the toolkit will use on signing process. Options:
# - 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
Expand Down
13 changes: 13 additions & 0 deletions docs/en/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ We assume ADFS 2.0 or greater is used as an IdP.
- [Service Provider (SP)](#service-provider-sp)
- [Identity Provider (IdP)](#identity-provider-idp)
- [Additional configuration for Azure AD](#additional-configuration-for-azure-ad)
- [GUID Transformation Callable](#guid-transformation-callable)
- [Establish trust](#establish-trust)
- [Configure SilverStripe Authenticators](#configure-silverstripe-authenticators)
- [Show the SAML Login button on login form](#show-the-saml-login-button-on-login-form)
Expand Down Expand Up @@ -149,6 +150,18 @@ SilverStripe\SAML\Extensions\SAMLMemberExtension:
- 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Email'
```

### GUID Transformation Callable

If you prefer received GUID in lower-case or upper-case format you can use option `guid_transformation_callable`
to change GUID format. This option is `null` by default - no change will be applied.

For example to change received GUID to upper-case just define callable (as string) in yaml configuration:
```yaml
SilverStripe\SAML\Services\SAMLConfiguration:
guid_transformation_callable: 'strtoupper'
```
`$guid` will be passed as first argument to any given callable

## Establish trust

At this stage the SilverStripe site trusts the IdP, but the IdP does not have any way to establish the identity of the SilverStripe site.
Expand Down
5 changes: 5 additions & 0 deletions src/Control/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public function acs()
$guid = $auth->getNameId();
}

$guidTransformation = Config::inst()->get(SAMLConfiguration::class, 'guid_transformation_callable');
if ($guidTransformation !== null) {
$guid = $guidTransformation($guid);
}

$attributes = $auth->getAttributes();

$fieldToClaimMap = array_flip(Member::config()->claims_field_mappings);
Expand Down
19 changes: 19 additions & 0 deletions src/Services/SAMLConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ class SAMLConfiguration
*/
private static $allow_insecure_email_linking = false;

/**
* @config
* @var null|string|callable transform received GUID by given callable, if null
*
* defaults to null - no change is applied on received guid
*/
private static $guid_transformation_callable;

/**
* @return array
*/
Expand Down Expand Up @@ -184,6 +192,17 @@ public function asArray()
'wantXMLValidation' => true,
];

$guidTransformationCallback = $this->config()->get('guid_transformation_callable');
if ($guidTransformationCallback !== null && !is_callable($guidTransformationCallback)) {
throw new \InvalidArgumentException(
sprintf(
'%s::guid_transformation_callback must be null or callable, `%s` given',
static::class,
var_export($guidTransformationCallback, true)
)
);
}

return $conf;
}
}

0 comments on commit 293a588

Please sign in to comment.