4848import org .springframework .web .context .request .RequestContextHolder ;
4949import org .springframework .web .context .request .ServletRequestAttributes ;
5050
51+ import javax .annotation .PostConstruct ;
5152import javax .inject .Inject ;
5253import javax .servlet .http .HttpSession ;
5354import java .util .ArrayList ;
@@ -80,23 +81,18 @@ public class UserService {
8081 @ Lazy
8182 private ProxyAccessControlService accessControlService ;
8283
83- public Authentication getCurrentAuth () {
84- return SecurityContextHolder .getContext ().getAuthentication ();
85- }
86-
87- public String getCurrentUserId () {
88- return getUserId (getCurrentAuth ());
89- }
90-
91- public Set <String > getAdminGroups () {
92- Set <String > adminGroups = new HashSet <>();
93-
84+ private final Set <String > adminGroups = new HashSet <>();
85+ private final Set <String > adminUsers = new HashSet <>();
86+
87+ @ PostConstruct
88+ public void init () {
89+ // load admin groups
9490 // Support for old, non-array notation
9591 String singleGroup = environment .getProperty ("proxy.admin-groups" );
9692 if (singleGroup != null && !singleGroup .isEmpty ()) {
9793 adminGroups .add (singleGroup .toUpperCase ());
9894 }
99-
95+
10096 for (int i =0 ;; i ++) {
10197 String groupName = environment .getProperty (String .format ("proxy.admin-groups[%s]" , i ));
10298 if (groupName == null || groupName .isEmpty ()) {
@@ -105,12 +101,7 @@ public Set<String> getAdminGroups() {
105101 adminGroups .add (groupName .toUpperCase ());
106102 }
107103
108- return adminGroups ;
109- }
110-
111- public Set <String > getAdminUsers () {
112- Set <String > adminUsers = new HashSet <>();
113-
104+ // load admin users
114105 // Support for old, non-array notation
115106 String singleUser = environment .getProperty ("proxy.admin-users" );
116107 if (singleUser != null && !singleUser .isEmpty ()) {
@@ -124,7 +115,21 @@ public Set<String> getAdminUsers() {
124115 }
125116 adminUsers .add (userName );
126117 }
118+ }
119+
120+ public Set <String > getAdminGroups () {
121+ return adminGroups ;
122+ }
127123
124+ public Authentication getCurrentAuth () {
125+ return SecurityContextHolder .getContext ().getAuthentication ();
126+ }
127+
128+ public String getCurrentUserId () {
129+ return getUserId (getCurrentAuth ());
130+ }
131+
132+ public Set <String > getAdminUsers () {
128133 return adminUsers ;
129134 }
130135
0 commit comments