Commits

David Carr committed 9bb4567

windows-provider: fix initialization

Group enumeration wasn't initializing in the Active Directory user source, which resulted in trying to get groups from the null server, which didn't work as desired. Just calling initialize wasn't enough, as getProvider also calls initialize, and it was used in the afterInitialize, resulting in a StackOverflowException. Thus, it needed to be passed the provider as an argument.

Comments (0)

Files changed (2)

windows-provider/src/main/java/us/carrclan/david/authc4j/windows/provider/ActiveDirectoryUserInformationSource.java

 import us.carrclan.david.authc4j.api.ImmutableGroupInformation;
 import us.carrclan.david.authc4j.api.Password;
 import us.carrclan.david.authc4j.api.UserInformation;
+import waffle.windows.auth.IWindowsAuthProvider;
 import waffle.windows.auth.IWindowsIdentity;
 
 import java.util.LinkedHashSet;
 
     @Override
     public UserInformation authenticate(String principal, Password password) {
+        initialize();
         IWindowsIdentity identity = null;
         try {
             // TODO: handle UPN and SAM formats to specify domain
 
     @Override
     public Set<? extends GroupInformation> getAllGroupInformation() {
+        initialize();
         Set<GroupInformation> allGroupInformation = new LinkedHashSet<>();
         for (Netapi32Util.Group group : Netapi32Util.getGlobalGroups(serverName)) {
             allGroupInformation.add(new ImmutableGroupInformation(this, group.name));
 
     @Override
     public Set<? extends UserInformation> getAllUserInformation(boolean includeMemberGroupInformation) {
+        initialize();
         UserInformationCollector collector = includeMemberGroupInformation ?
                 new UserWithGlobalGroupInformationCollector(this, serverName) :
                 new UserInformationCollector(this);
     }
 
     @Override
-    protected void afterInitialize() {
-        serverName = getProvider().getCurrentComputer().getMemberOf();
+    protected void afterInitialize(IWindowsAuthProvider provider) {
+        serverName = provider.getCurrentComputer().getMemberOf();
     }
 
     private boolean isMachineDomainMember() {

windows-provider/src/main/java/us/carrclan/david/authc4j/windows/provider/WindowsUserInformationSource.java

         }
     }
 
-    private synchronized void initialize() {
+    protected synchronized void initialize() {
         if (initialized) return;
         provider = new WindowsAuthProviderImpl();
-        afterInitialize();
+        afterInitialize(provider);
         initialized = true;
     }
 
-    protected void afterInitialize() {
+    protected void afterInitialize(IWindowsAuthProvider provider) {
     }
 }