浏览代码

fix rest issue with check pwd requiring username
fix rest issue with authenticating against ad users when 'require new pw' is set to true on user

Jason Rivard 7 年之前
父节点
当前提交
284a110df2

+ 5 - 1
server/src/main/java/password/pwm/ldap/LdapConnectionService.java

@@ -56,7 +56,7 @@ public class LdapConnectionService implements PwmService
     private PwmApplication pwmApplication;
     private PwmApplication pwmApplication;
     private STATUS status = STATUS.NEW;
     private STATUS status = STATUS.NEW;
     private AtomicLoopIntIncrementer slotIncrementer;
     private AtomicLoopIntIncrementer slotIncrementer;
-    private final ThreadLocal<Map<LdapProfile, ChaiProvider>> threadLocalProvider = new ThreadLocal<>();
+    //private final ThreadLocal<Map<LdapProfile, ChaiProvider>> threadLocalProvider = new ThreadLocal<>();
     private ChaiProviderFactory chaiProviderFactory;
     private ChaiProviderFactory chaiProviderFactory;
 
 
     public STATUS status( )
     public STATUS status( )
@@ -135,18 +135,22 @@ public class LdapConnectionService implements PwmService
                 ? pwmApplication.getConfig().getDefaultLdapProfile()
                 ? pwmApplication.getConfig().getDefaultLdapProfile()
                 : ldapProfile;
                 : ldapProfile;
 
 
+        /*
         if ( threadLocalProvider.get() != null && threadLocalProvider.get().containsKey( effectiveProfile ) )
         if ( threadLocalProvider.get() != null && threadLocalProvider.get().containsKey( effectiveProfile ) )
         {
         {
             return threadLocalProvider.get().get( effectiveProfile );
             return threadLocalProvider.get().get( effectiveProfile );
         }
         }
+        */
 
 
         final ChaiProvider chaiProvider = getNewProxyChaiProvider( effectiveProfile );
         final ChaiProvider chaiProvider = getNewProxyChaiProvider( effectiveProfile );
 
 
+        /*
         if ( threadLocalProvider.get() == null )
         if ( threadLocalProvider.get() == null )
         {
         {
             threadLocalProvider.set( new ConcurrentHashMap<>() );
             threadLocalProvider.set( new ConcurrentHashMap<>() );
         }
         }
         threadLocalProvider.get().put( effectiveProfile, chaiProvider );
         threadLocalProvider.get().put( effectiveProfile, chaiProvider );
+        */
 
 
         return chaiProvider;
         return chaiProvider;
     }
     }

+ 22 - 3
server/src/main/java/password/pwm/ldap/auth/SimpleLdapAuthenticator.java

@@ -26,18 +26,32 @@ import com.novell.ldapchai.exception.ChaiUnavailableException;
 import password.pwm.PwmApplication;
 import password.pwm.PwmApplication;
 import password.pwm.bean.SessionLabel;
 import password.pwm.bean.SessionLabel;
 import password.pwm.bean.UserIdentity;
 import password.pwm.bean.UserIdentity;
+import password.pwm.error.ErrorInformation;
+import password.pwm.error.PwmError;
 import password.pwm.error.PwmOperationalException;
 import password.pwm.error.PwmOperationalException;
 import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.util.PasswordData;
 import password.pwm.util.PasswordData;
+import password.pwm.util.logging.PwmLogger;
+
+import java.util.Arrays;
+import java.util.Collection;
 
 
 public class SimpleLdapAuthenticator
 public class SimpleLdapAuthenticator
 {
 {
+    private static final PwmLogger LOGGER = PwmLogger.forClass( SimpleLdapAuthenticator.class );
+
+    private static final Collection ACCEPTABLE_AUTH_TYPES = Arrays.asList(
+                    AuthenticationType.AUTHENTICATED,
+                    AuthenticationType.AUTH_BIND_INHIBIT
+            );
+
     public static AuthenticationResult authenticateUser(
     public static AuthenticationResult authenticateUser(
             final PwmApplication pwmApplication,
             final PwmApplication pwmApplication,
             final SessionLabel sessionLabel,
             final SessionLabel sessionLabel,
             final UserIdentity userIdentity,
             final UserIdentity userIdentity,
             final PasswordData password
             final PasswordData password
-    ) throws PwmUnrecoverableException
+    )
+            throws PwmUnrecoverableException
     {
     {
         final AuthenticationRequest authEngine = LDAPAuthenticationRequest.createLDAPAuthenticationRequest(
         final AuthenticationRequest authEngine = LDAPAuthenticationRequest.createLDAPAuthenticationRequest(
                 pwmApplication,
                 pwmApplication,
@@ -61,11 +75,16 @@ public class SimpleLdapAuthenticator
             throw new PwmUnrecoverableException( e.getErrorInformation() );
             throw new PwmUnrecoverableException( e.getErrorInformation() );
         }
         }
 
 
-        if ( authResult.getAuthenticationType() == AuthenticationType.AUTHENTICATED )
+        if ( ACCEPTABLE_AUTH_TYPES.contains( authResult.getAuthenticationType() ) )
         {
         {
             return authResult;
             return authResult;
         }
         }
 
 
-        return null;
+        final ErrorInformation errorInformation = new ErrorInformation(
+                PwmError.ERROR_UNKNOWN,
+                "auth with unexpected auth type: " + authResult.getAuthenticationType()
+        );
+        LOGGER.error( errorInformation );
+        throw new PwmUnrecoverableException( errorInformation );
     }
     }
 }
 }

+ 5 - 0
server/src/main/java/password/pwm/util/logging/PwmLogger.java

@@ -387,6 +387,11 @@ public class PwmLogger
         doLogEvent( PwmLogLevel.ERROR, sessionLabel, convertErrorInformation( errorInformation ), null );
         doLogEvent( PwmLogLevel.ERROR, sessionLabel, convertErrorInformation( errorInformation ), null );
     }
     }
 
 
+    public void error( final SessionLabel sessionLabel, final ErrorInformation errorInformation, final Throwable exception )
+    {
+        doLogEvent( PwmLogLevel.ERROR, sessionLabel, convertErrorInformation( errorInformation ), exception );
+    }
+
     public void error( final CharSequence message, final Throwable exception )
     public void error( final CharSequence message, final Throwable exception )
     {
     {
         doLogEvent( PwmLogLevel.ERROR, null, message, exception );
         doLogEvent( PwmLogLevel.ERROR, null, message, exception );

+ 1 - 1
server/src/main/java/password/pwm/ws/server/RestServlet.java

@@ -172,7 +172,7 @@ public abstract class RestServlet extends HttpServlet
             final String errorMsg = "internal error during rest service invocation: " + e.getMessage();
             final String errorMsg = "internal error during rest service invocation: " + e.getMessage();
             final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_UNKNOWN, errorMsg );
             final ErrorInformation errorInformation = new ErrorInformation( PwmError.ERROR_UNKNOWN, errorMsg );
             restResultBean = RestResultBean.fromError( errorInformation, pwmApplication, locale, pwmApplication.getConfig(), pwmApplication.determineIfDetailErrorMsgShown() );
             restResultBean = RestResultBean.fromError( errorInformation, pwmApplication, locale, pwmApplication.getConfig(), pwmApplication.determineIfDetailErrorMsgShown() );
-            LOGGER.error( sessionLabel, errorInformation );
+            LOGGER.error( sessionLabel, errorInformation, e );
         }
         }
 
 
         outputRestResultBean( restResultBean, req, resp );
         outputRestResultBean( restResultBean, req, resp );

+ 5 - 1
server/src/main/java/password/pwm/ws/server/rest/RestCheckPasswordServer.java

@@ -133,6 +133,9 @@ public class RestCheckPasswordServer extends RestServlet
 
 
         final JsonInput jsonInput;
         final JsonInput jsonInput;
         {
         {
+
+
+
             final JsonInput jsonBody = RestUtility.deserializeJsonBody( restRequest, JsonInput.class, RestUtility.Flag.AllowNullReturn );
             final JsonInput jsonBody = RestUtility.deserializeJsonBody( restRequest, JsonInput.class, RestUtility.Flag.AllowNullReturn );
 
 
             jsonInput = new JsonInput(
             jsonInput = new JsonInput(
@@ -149,7 +152,8 @@ public class RestCheckPasswordServer extends RestServlet
                     RestUtility.readValueFromJsonAndParam(
                     RestUtility.readValueFromJsonAndParam(
                             jsonBody == null ? null : jsonBody.getUsername(),
                             jsonBody == null ? null : jsonBody.getUsername(),
                             restRequest.readParameterAsString( FIELD_USERNAME ),
                             restRequest.readParameterAsString( FIELD_USERNAME ),
-                            FIELD_USERNAME
+                            FIELD_USERNAME,
+                            RestUtility.ReadValueFlag.optional
                     )
                     )
             );
             );
         }
         }