Sfoglia il codice sorgente

fix newuser profile password policy not honoring new user ldap profile bug

Jason Rivard 5 anni fa
parent
commit
5ad6f46f07

+ 9 - 10
server/src/main/java/password/pwm/config/profile/NewUserProfile.java

@@ -72,7 +72,6 @@ public class NewUserProfile extends AbstractProfile implements Profile
     public PwmPasswordPolicy getNewUserPasswordPolicy( final PwmApplication pwmApplication, final Locale userLocale )
             throws PwmUnrecoverableException
     {
-        final Configuration config = pwmApplication.getConfig();
         final long maxNewUserCacheMS = Long.parseLong( pwmApplication.getConfig().readAppProperty( AppProperty.CONFIG_NEWUSER_PASSWORD_POLICY_CACHE_MS ) );
         if ( newUserPasswordPolicyCacheTime != null && TimeDuration.fromCurrent( newUserPasswordPolicyCacheTime ).isLongerThan( maxNewUserCacheMS ) )
         {
@@ -87,25 +86,25 @@ public class NewUserProfile extends AbstractProfile implements Profile
         }
 
         final PwmPasswordPolicy thePolicy;
-        final LdapProfile defaultLdapProfile = config.getDefaultLdapProfile();
+        final LdapProfile ldapProfile = getLdapProfile();
         final String configuredNewUserPasswordDN = readSettingAsString( PwmSetting.NEWUSER_PASSWORD_POLICY_USER );
-        if ( configuredNewUserPasswordDN == null || configuredNewUserPasswordDN.length() < 1 )
+        if ( StringUtil.isEmpty( configuredNewUserPasswordDN ) )
         {
-            final String errorMsg = "the setting " + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug( this.getIdentifier(), PwmConstants.DEFAULT_LOCALE )
+            final String errorMsg = "the setting "
+                    + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug( this.getIdentifier(), PwmConstants.DEFAULT_LOCALE )
                     + " must have a value";
             throw new PwmUnrecoverableException( new ErrorInformation( PwmError.ERROR_INVALID_CONFIG, errorMsg ) );
         }
         else
         {
-
             final String lookupDN;
             if ( TEST_USER_CONFIG_VALUE.equalsIgnoreCase( configuredNewUserPasswordDN ) )
             {
-                lookupDN = defaultLdapProfile.readSettingAsString( PwmSetting.LDAP_TEST_USER_DN );
-                if ( lookupDN == null || lookupDN.isEmpty() )
+                lookupDN = ldapProfile.readSettingAsString( PwmSetting.LDAP_TEST_USER_DN );
+                if ( StringUtil.isEmpty( lookupDN ) )
                 {
                     final String errorMsg = "setting "
-                            + PwmSetting.LDAP_TEST_USER_DN.toMenuLocationDebug( defaultLdapProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE )
+                            + PwmSetting.LDAP_TEST_USER_DN.toMenuLocationDebug( ldapProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE )
                             + " must be configured since setting "
                             + PwmSetting.NEWUSER_PASSWORD_POLICY_USER.toMenuLocationDebug( this.getIdentifier(), PwmConstants.DEFAULT_LOCALE )
                             + " is set to " + TEST_USER_CONFIG_VALUE;
@@ -130,9 +129,9 @@ public class NewUserProfile extends AbstractProfile implements Profile
             {
                 try
                 {
-                    final ChaiProvider chaiProvider = pwmApplication.getProxyChaiProvider( defaultLdapProfile.getIdentifier() );
+                    final ChaiProvider chaiProvider = pwmApplication.getProxyChaiProvider( ldapProfile.getIdentifier() );
                     final ChaiUser chaiUser = chaiProvider.getEntryFactory().newChaiUser( lookupDN );
-                    final UserIdentity userIdentity = new UserIdentity( lookupDN, defaultLdapProfile.getIdentifier() );
+                    final UserIdentity userIdentity = new UserIdentity( lookupDN, ldapProfile.getIdentifier() );
                     thePolicy = PasswordUtility.readPasswordPolicyForUser( pwmApplication, null, userIdentity, chaiUser, userLocale );
                 }
                 catch ( final ChaiUnavailableException e )

+ 1 - 0
server/src/main/java/password/pwm/health/HealthMessage.java

@@ -78,6 +78,7 @@ public enum HealthMessage
 
     LDAP_VendorsNotSame( HealthStatus.CONFIG, HealthTopic.LDAP ),
     LDAP_OK( HealthStatus.GOOD, HealthTopic.LDAP ),
+    EMail_OK( HealthStatus.GOOD, HealthTopic.Email ),
     LDAP_RecentlyUnreachable( HealthStatus.CAUTION, HealthTopic.LDAP ),
     LDAP_SearchFailure( HealthStatus.WARN, HealthTopic.LDAP ),
     CryptoTokenWithNewUserVerification( HealthStatus.CAUTION, HealthTopic.Configuration ),

+ 2 - 1
server/src/main/java/password/pwm/health/HealthMonitor.java

@@ -82,6 +82,7 @@ public class HealthMonitor implements PwmService
     private HealthMonitorSettings settings;
 
     private final Map<HealthMonitorFlag, Serializable> healthProperties = new ConcurrentHashMap<>();
+    private final AtomicInteger healthCheckCount = new AtomicInteger( 0 );
 
     private STATUS status = STATUS.CLOSED;
     private PwmApplication pwmApplication;
@@ -100,6 +101,7 @@ public class HealthMonitor implements PwmService
     public void init( final PwmApplication pwmApplication ) throws PwmException
     {
         this.pwmApplication = pwmApplication;
+        this.healthData = emptyHealthData();
         settings = HealthMonitorSettings.fromConfiguration( pwmApplication.getConfig() );
 
         if ( !Boolean.parseBoolean( pwmApplication.getConfig().readAppProperty( AppProperty.HEALTHCHECK_ENABLED ) ) )
@@ -227,7 +229,6 @@ public class HealthMonitor implements PwmService
         return Collections.emptyList();
     }
 
-    private AtomicInteger healthCheckCount = new AtomicInteger( 0 );
 
     private void doHealthChecks( )
     {

+ 4 - 4
server/src/main/java/password/pwm/http/servlet/resource/MemoryFileResource.java

@@ -29,24 +29,24 @@ import java.io.InputStream;
 class MemoryFileResource implements FileResource
 {
     private final String name;
-    private final ImmutableByteArray contents;
+    private final byte[] contents;
     private final long lastModified;
 
     MemoryFileResource( final String name, final ImmutableByteArray contents, final long lastModified )
     {
         this.name = name;
-        this.contents = contents;
+        this.contents = contents.copyOf();
         this.lastModified = lastModified;
     }
 
     public InputStream getInputStream( ) throws IOException
     {
-        return new ByteArrayInputStream( contents.copyOf() );
+        return new ByteArrayInputStream( contents );
     }
 
     public long length( )
     {
-        return contents.copyOf().length;
+        return contents.length;
     }
 
     public long lastModified( )

+ 5 - 0
server/src/main/java/password/pwm/svc/email/EmailServerUtil.java

@@ -444,6 +444,11 @@ public class EmailServerUtil
             }
         }
 
+        if ( records.isEmpty() )
+        {
+            records.add( HealthRecord.forMessage( HealthMessage.EMail_OK ) );
+        }
+
         return Collections.unmodifiableList( records );
     }
 }

+ 3 - 2
server/src/main/java/password/pwm/svc/report/ReportService.java

@@ -494,7 +494,8 @@ public class ReportService implements PwmService
             try
             {
                 LOGGER.trace( SessionLabel.REPORTING_SESSION_LABEL, () -> "about to begin ldap processing with thread count of " + threadCount );
-                final BlockingThreadPool threadService = new BlockingThreadPool( threadCount, "reporting-thread" );
+                final String threadName = PwmScheduler.makeThreadName( pwmApplication, this.getClass() );
+                final BlockingThreadPool threadService = new BlockingThreadPool( threadCount, threadName );
                 while ( status == STATUS.OPEN && !dnQueue.isEmpty() && !cancelFlag )
                 {
                     final UserIdentity userIdentity = UserIdentity.fromDelimitedKey( dnQueue.poll() );
@@ -540,7 +541,7 @@ public class ReportService implements PwmService
                         }
                         catch ( final PwmUnrecoverableException e )
                         {
-
+                            LOGGER.debug( () -> "unexpected error reading report data: " + e.getMessage() );
                         }
                         catch ( final Exception e )
                         {

+ 1 - 0
server/src/main/resources/password/pwm/i18n/Health.properties

@@ -21,6 +21,7 @@
 
 HealthMessage_NoData=Health data is not currently available.  Please check again in a moment.
 HealthMessage_LDAP_OK=All configured LDAP servers are reachable
+HealthMessage_EMail_OK=All configured Email servers are reachable
 HealthMessage_LDAP_No_Connection=Unable to connect to LDAP server %1%, error: %2%
 HealthMessage_LDAP_ProxyTestSameUser=%1% setting is the same value as the %2% setting
 HealthMessage_LDAP_ProxyUserPwExpired=Proxy user %1% password will expire within %2%.  The proxy user password should never expire.