66 * This filter extracts group names from cached groups from PerunIdentity filter and save them into attribute defined by attrName.
77 * By default attribute value will be filled with the groupNamePrefix + groupName.
88 *
9+ * If groupNameAARC is enabled for SP or it is enabled globaly in perun_module.conf, then use groupNamePrefix
10+ * and groupNameAuthority to construct group name according to the
11+ * https://aarc-project.eu/wp-content/uploads/2017/11/AARC-JRA1.4A-201710.pdf
12+ *
913 * It is also capable of translation of (renames) group names using 'groupMapping' attribute in SP metadata.
1014 *
1115 * @author Ondrej Velisek <[email protected] > 1418class sspmod_perun_Auth_Process_PerunGroups extends SimpleSAML_Auth_ProcessingFilter
1519{
1620
21+ const CONFIG_FILE_NAME = 'module_perun.php ' ;
22+
1723 const GROUPNAMEPREFIX_ATTR = 'groupNamePrefix ' ;
24+ const GROUPNAMEAARC_ATTR = 'groupNameAARC ' ;
25+ const GROUPNAMEAUTHORITY_ATTR = 'groupNameAuthority ' ;
1826
1927 private $ attrName ;
2028 private $ groupNamePrefix ;
29+ private $ groupNameAARC ;
30+ private $ groupNameAuthority ;
2131
2232 public function __construct ($ config , $ reserved )
2333 {
2434 parent ::__construct ($ config , $ reserved );
2535
36+ $ conf = SimpleSAML_Configuration::getConfig (self ::CONFIG_FILE_NAME );
37+
38+ $ this ->groupNamePrefix = $ conf ->getString (self ::GROUPNAMEPREFIX_ATTR , '' );
39+ $ this ->groupNameAuthority = $ conf ->getString (self ::GROUPNAMEAUTHORITY_ATTR , '' );
40+ $ this ->groupNameAARC = $ conf ->getBoolean (self ::GROUPNAMEAARC_ATTR , false );
41+
42+ if ($ this ->groupNameAARC && (empty ($ this ->groupNameAuthority ) || empty ($ this ->groupNamePrefix ))) {
43+ throw new SimpleSAML_Error_Exception ("perun:PerunGroups: 'groupNameAARC' has been set, 'groupNameAuthority' and 'groupNamePrefix' options must be set as well " );
44+ }
45+
2646 assert ('is_array($config) ' );
2747
2848 if (!isset ($ config ['attrName ' ])) {
2949 throw new SimpleSAML_Error_Exception ("perun:PerunGroups: missing mandatory configuration option 'attrName'. " );
3050 }
3151 $ this ->attrName = (string ) $ config ['attrName ' ];
3252
33- if (!isset ($ config [self ::GROUPNAMEPREFIX_ATTR ])) {
34- SimpleSAML \Logger::warning ("perun:PerunGroups: optional attribute ' " . self ::GROUPNAMEPREFIX_ATTR . "' is missing, assuming empty prefix " );
35- $ this ->groupNamePrefix = '' ;
36- } else {
37- $ this ->groupNamePrefix = (string ) $ config [self ::GROUPNAMEPREFIX_ATTR ];
38- }
3953 }
4054
4155
@@ -55,7 +69,17 @@ public function process(&$request)
5569
5670 $ request ['Attributes ' ][$ this ->attrName ] = array ();
5771 foreach ($ groups as $ group ) {
58- $ groupName = $ this ->mapGroupName ($ request , $ group ->getName ());
72+ if (isset ($ request ["SPMetadata " ]["groupNameAARC " ]) || $ this ->groupNameAARC ) {
73+ # https://aarc-project.eu/wp-content/uploads/2017/11/AARC-JRA1.4A-201710.pdf
74+ # Example: urn:geant:einfra.cesnet.cz:perun.cesnet.cz:group:einfra:<groupName>:<subGroupName>#perun.cesnet.cz
75+ if (empty ($ this ->groupNameAuthority ) || empty ($ this ->groupNamePrefix )) {
76+ throw new SimpleSAML_Error_Exception ("perun:PerunGroups: missing mandatory configuration options 'groupNameAuthority' or 'groupNamePrefix'. " );
77+ }
78+
79+ $ groupName = $ this ->groupNamePrefix . $ group ->getName () . '# ' . $ this ->groupNameAuthority ;
80+ } else {
81+ $ groupName = $ this ->mapGroupName ($ request , $ group ->getName ());
82+ }
5983 array_push ($ request ['Attributes ' ][$ this ->attrName ], $ groupName );
6084 }
6185 }
0 commit comments