@@ -22,7 +22,10 @@ class PerunAttributes extends \SimpleSAML\Auth\ProcessingFilter
2222{
2323 private $ attrMap ;
2424 private $ interface ;
25+ private $ mode ;
2526
27+ const MODE_FULL = 'FULL ' ;
28+ const MODE_PARTIAL = 'PARTIAL ' ;
2629 /**
2730 * @var Adapter
2831 */
@@ -43,8 +46,16 @@ public function __construct($config, $reserved)
4346 $ config ['interface ' ] = Adapter::RPC ;
4447 }
4548
49+ if (!isset ($ config ['mode ' ])) {
50+ $ config ['mode ' ] = self ::MODE_FULL ;
51+ }
52+
4653 $ this ->attrMap = (array )$ config ['attrMap ' ];
4754 $ this ->interface = (string )$ config ['interface ' ];
55+ $ this ->mode = (string )$ config ['mode ' ];
56+ if (!in_array ($ this ->mode , [self ::MODE_FULL , self ::MODE_PARTIAL ])) {
57+ $ this ->mode = self ::MODE_FULL ;
58+ }
4859 $ this ->adapter = Adapter::getInstance ($ this ->interface );
4960 }
5061
@@ -62,7 +73,25 @@ public function process(&$request)
6273 );
6374 }
6475
65- $ attrs = $ this ->adapter ->getUserAttributes ($ user , array_keys ($ this ->attrMap ));
76+ $ attributes = [];
77+ if ($ this ->mode === self ::MODE_FULL ) {
78+ $ attributes = array_keys ($ this ->attrMap );
79+ } else if ($ this ->mode === self ::MODE_PARTIAL ) {
80+ // Check if attribute has some value
81+ foreach ($ this ->attrMap as $ attrName => $ attrValue ) {
82+ if (isset ($ request ['Attributes ' ][$ attrValue ])) {
83+ $ attr = $ request ['Attributes ' ][$ attrValue ];
84+ if ($ attr === null || empty ($ attr )) {
85+ array_push ($ attributes , $ attrName );
86+ }
87+ } else {
88+ array_push ($ attributes , $ attrName );
89+ }
90+ }
91+ }
92+
93+
94+ $ attrs = $ this ->adapter ->getUserAttributes ($ user , $ attributes );
6695
6796 foreach ($ attrs as $ attrName => $ attrValue ) {
6897 $ sspAttr = $ this ->attrMap [$ attrName ];
0 commit comments