diff --git a/example/includes/config.yml b/example/includes/config.yml index 697ef8d..e383984 100644 --- a/example/includes/config.yml +++ b/example/includes/config.yml @@ -158,6 +158,8 @@ auth: # User backends backends: - db + #- ldap + #- casuser # # Login form @@ -231,6 +233,28 @@ auth: # CAS Fake authenticated user #fake_authenticated_user: 'myusername' + + # CAS user attributes to retreive with their properties: + # [attr name]: + # # CAS attribute name (optional, default: [attr name]) + # cas_name: [CAS attr name] + # # Alternative CAS attribute name to retrieve if the first one is not defined (optional) + # alt_cas_name: [alternative CAS attr name] + # # Type of value (optional, default: 'string', possible values: string, bool, int, float) + # type: [type of value] + # # Default attribute value (optional, default: null) + # default: null + # Note: only used by casuser auth backend. + user_attributes: + login: + cas_name: 'uid' + default: null + name: + cas_name: 'displayName' + cas_ldap_name: 'cn' + default: null + mail: + type: 'string' # # Database user backend diff --git a/skel/config.yml b/skel/config.yml index 2b4bfab..17e28d3 100644 --- a/skel/config.yml +++ b/skel/config.yml @@ -158,6 +158,8 @@ auth: # User backends backends: #- ldap + #- db + #- casuser # # Login form @@ -232,6 +234,28 @@ auth: # CAS Fake authenticated user #fake_authenticated_user: 'myusername' + # CAS user attributes to retreive with their properties: + # [attr name]: + # # CAS attribute name (optional, default: [attr name]) + # cas_name: [CAS attr name] + # # Alternative CAS attribute name to retrieve if the first one is not defined (optional) + # alt_cas_name: [alternative CAS attr name] + # # Type of value (optional, default: 'string', possible values: string, bool, int, float) + # type: [type of value] + # # Default attribute value (optional, default: null) + # default: null + # Note: only used by casuser auth backend. + user_attributes: + login: + cas_name: 'uid' + default: null + name: + cas_name: 'displayName' + cas_ldap_name: 'cn' + default: null + mail: + type: 'string' + # # Database user backend # diff --git a/src/Auth/Cas.php b/src/Auth/Cas.php index b5d47ec..0a38af1 100644 --- a/src/Auth/Cas.php +++ b/src/Auth/Cas.php @@ -37,6 +37,26 @@ class Cas extends Method { 'fake_authenticated_user' => null, 'debug_log_file' => null, 'ca_cert_certificate_path' => null, + 'user_attributes' => array( + 'login' => array( + 'cas_name' => 'uid', + 'type' => 'string', + 'multivalued' => false, + 'default' => null, + ), + 'mail' => array( + 'type' => 'string', + 'multivalued' => false, + 'default' => null, + ), + 'name' => array( + 'cas_name' => 'displayName', + 'alt_cas_name' => 'cn', + 'type' => 'string', + 'multivalued' => false, + 'default' => null, + ), + ), ) ); self :: $fake_authenticated_user = App :: get( diff --git a/src/Auth/Casuser.php b/src/Auth/Casuser.php new file mode 100644 index 0000000..0dc9804 --- /dev/null +++ b/src/Auth/Casuser.php @@ -0,0 +1,55 @@ + $attr_config) { + $cas_name = Config::get("cas_name", null, 'string', false, $attr_config); + $alt_cas_name = Config::get("alt_cas_name", $name, 'string', false, $attr_config); + if (!$cas_name || is_null(self :: get_attr($cas_name))) + $cas_name = $alt_cas_name; + $info[$name] = self :: get_attr( + $cas_name?$cas_name:$name, + Config::get("default", null, null, false, $attr_config) + ); + } + Log::debug('User "%s" info computed from CAS attributes:\n%s', $username, vardump($info)); + return new User($username, '\\EesyPHP\\Auth\\Casuser', $info); + } + +}