@@ -37,27 +37,27 @@ public boolean authorize(LbPrincipal principal,
37
37
{
38
38
switch (role ) {
39
39
case "ADMIN" :
40
- log .info ("User '%s' with memberOf(%s) was identified as ADMIN(%s)" ,
41
- principal .getName (), principal .getMemberOf (), configuration .getAdmin ());
42
- return principal .getMemberOf ()
43
- .filter (m -> m .matches (configuration .getAdmin ()))
44
- .isPresent ();
40
+ return hasRole (principal , role , configuration .getAdmin ());
45
41
case "USER" :
46
- log .info ("User '%s' with memberOf(%s) identified as USER(%s)" ,
47
- principal .getName (), principal .getMemberOf (), configuration .getUser ());
48
- return principal .getMemberOf ()
49
- .filter (m -> m .matches (configuration .getUser ()))
50
- .isPresent ();
42
+ return hasRole (principal , role , configuration .getUser ());
51
43
case "API" :
52
- log .info ("User '%s' with memberOf(%s) identified as API(%s)" ,
53
- principal .getName (), principal .getMemberOf (), configuration .getApi ());
54
- return principal .getMemberOf ()
55
- .filter (m -> m .matches (configuration .getApi ()))
56
- .isPresent ();
44
+ return hasRole (principal , role , configuration .getApi ());
57
45
default :
58
46
log .warn ("User '%s' with role %s has no regex match based on ldap search" ,
59
47
principal .getName (), role );
60
48
return false ;
61
49
}
62
50
}
51
+
52
+ private static boolean hasRole (LbPrincipal principal , String role , String regex )
53
+ {
54
+ boolean matched = principal .getMemberOf ()
55
+ .filter (m -> m .matches (regex ))
56
+ .isPresent ();
57
+ if (matched ) {
58
+ log .info ("User '%s' with memberOf(%s) is identified as %s(%s)" ,
59
+ principal .getName (), principal .getMemberOf (), role , regex );
60
+ }
61
+ return matched ;
62
+ }
63
63
}
0 commit comments