Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.appbasics.security.password;
 
 
 
 
Central class for all password related elements.

Author(s):
Philip Helger
 
 public final class GlobalPasswordSettings
 {
   private static final Logger s_aLogger = LoggerFactory.getLogger (GlobalPasswordSettings.class);
   private static final ReadWriteLock s_aRWLock = new ReentrantReadWriteLock ();
 
   @GuardedBy ("s_aRWLock")
 
   private static final PasswordHashCreatorManager s_aPHCMgr = new PasswordHashCreatorManager ();
 
   static
   {
     // Register default implementation so that something is present
 
     // Register all custom SPI implementations
     for (final IPasswordHashCreatorRegistrarSPI aSPI : ServiceLoaderUtils.getAllSPIImplementations (IPasswordHashCreatorRegistrarSPI.class))
   }
 
   @SuppressWarnings ("unused")
   private static final GlobalPasswordSettings s_aInstance = new GlobalPasswordSettings ();
 
   private GlobalPasswordSettings ()
   {}

  

Returns:
The current password constraint list. Never null but maybe empty.
 
   @Nonnull
   {
     .readLock ().lock ();
     try
     {
       return .getClone ();
     }
     finally
     {
       .readLock ().unlock ();
     }
   }

  
Set the global password constraint list.

Parameters:
aPasswordConstraintList The list to be set. May not be null.
  public static void setPasswordConstraintList (@Nonnull final IPasswordConstraintList aPasswordConstraintList)
  {
    ValueEnforcer.notNull (aPasswordConstraintList"PasswordConstraintList");
    // Create a copy
    final IPasswordConstraintList aRealPasswordConstraints = aPasswordConstraintList.getClone ();
    .writeLock ().lock ();
    try
    {
       = aRealPasswordConstraints;
    }
    finally
    {
      .writeLock ().unlock ();
    }
    .info ("Set global password constraints to " + aRealPasswordConstraints);
  }

  

Returns:
true if any password constraint is defined, false if not.
  public static boolean isAnyPasswordConstraintDefined ()
  {
  }

  
  {
    return ;
  }

  
Create the password hash from the passed plain text password, using the default password hash creator.

Parameters:
sPlainTextPassword Plain text password. May not be null.
Returns:
The password hash. Never null.
  public static PasswordHash createUserDefaultPasswordHash (@Nonnull final String sPlainTextPassword)
  {
    ValueEnforcer.notNull (sPlainTextPassword"PlainTextPassword");
    final String sPasswordHash = aPHC.createPasswordHash (sPlainTextPassword);
    return new PasswordHash (aPHC.getAlgorithmName (), sPasswordHash);
  }

  
Create the password hash from the passed plain text password, using the default password hash creator.

Parameters:
sAlgorithmName The password hash creator algorithm name to query. May neither be null nor empty.
sPlainTextPassword Plain text password. May not be null.
Returns:
The password hash. Never null.
  public static PasswordHash createUserPasswordHash (@Nonnull @Nonempty final String sAlgorithmName,
                                                     @Nonnull final String sPlainTextPassword)
  {
    ValueEnforcer.notEmpty (sAlgorithmName"AlgorithmName");
    ValueEnforcer.notNull (sPlainTextPassword"PlainTextPassword");
    final IPasswordHashCreator aPHC = .getPasswordHashCreatorOfAlgorithm (sAlgorithmName);
    if (aPHC == null)
      throw new IllegalArgumentException ("No password hash creator for algorithm '" + sAlgorithmName + "' registered!");
    final String sPasswordHash = aPHC.createPasswordHash (sPlainTextPassword);
    return new PasswordHash (sAlgorithmNamesPasswordHash);
  }
New to GrepCode? Check out our FAQ X