public final Subject authenticate(final String domain, final String userName, final char[] password,
                                      final PasswordValidator passwordValidator)
            throws LoginException {

        // make sure the credentials are not null
        if (domain == null) {
            throw new LoginException("The domain cannot be null");
        }
        if (userName == null) {
            throw new LoginException("The username cannot be null");
        }
        if (password == null) {
            throw new LoginException("The password cannot be null");
        }

        // no need for defensive copies of Strings, but create a defensive copy of the password
        final char[] myPassword = password.clone();

        // convert the username string to a char array
        final char[] myCredential = userName.toCharArray();

        // perform the password validation
        if (!passwordValidator.validate(myPassword, myCredential)) {
            final String error = "Invalid password for username '" + userName + "'";
            LOG.info(error);
            throw new FailedLoginException(error);
        }

        // The authentication was successful!
        // Create the subject and clean up confidential data as far as possible.

        // clear the char representation of the credential
        Cleanser.wipe(myCredential);

        // clear the defensive copy of the password created earlier
        Cleanser.wipe(myPassword);

        // create a principal that includes the username and domain name that were used to authenticate the user
        final UserPrincipal userPrincipal = new UserPrincipal("ID:" + userName, domain, userName);

        // wrap the principal in a Subject
        final Subject subject = new Subject();
        subject.getPrincipals().add(userPrincipal);

        return subject;
    }
public final Subject authenticate(final String domain, final String userName, final char[] password,
                                      final PasswordValidator passwordValidator)
            throws LoginException {

        
        if (domain == null) {
            throw new LoginException("The domain cannot be null");
        }
        if (userName == null) {
            throw new LoginException("The username cannot be null");
        }
        if (password == null) {
            throw new LoginException("The password cannot be null");
        }

        
        final char[] myPassword = password.clone();

        
        final char[] myCredential = userName.toCharArray();

        
        if (!passwordValidator.validate(myPassword, myCredential)) {
            final String error = "Invalid password for username '" + userName + "'";
            LOG.info(error);
            throw new FailedLoginException(error);
        }

        
        

        
        Cleanser.wipe(myCredential);

        
        Cleanser.wipe(myPassword);

        
        final UserPrincipal userPrincipal = new UserPrincipal("ID:" + userName, domain, userName);

        
        final Subject subject = new Subject();
        subject.getPrincipals().add(userPrincipal);

        return subject;
    }
public final Subject authenticate ( final String domain , final String userName , final char [ ] password , final PasswordValidator passwordValidator ) throws LoginException { // make sure the credentials are not null if ( domain == null ) { throw new LoginException ( "The domain cannot be null" ) ; } if ( userName == null ) { throw new LoginException ( "The username cannot be null" ) ; } if ( password == null ) { throw new LoginException ( "The password cannot be null" ) ; } // no need for defensive copies of Strings, but create a defensive copy of the password final char [ ] myPassword = password . clone ( ) ; // convert the username string to a char array final char [ ] myCredential = userName . toCharArray ( ) ; // perform the password validation if ( ! passwordValidator . validate ( myPassword , myCredential ) ) { final String error = "Invalid password for username '" + userName + "'" ; LOG . info ( error ) ; throw new FailedLoginException ( error ) ; } // The authentication was successful! // Create the subject and clean up confidential data as far as possible. // clear the char representation of the credential Cleanser . wipe ( myCredential ) ; // clear the defensive copy of the password created earlier Cleanser . wipe ( myPassword ) ; // create a principal that includes the username and domain name that were used to authenticate the user final UserPrincipal userPrincipal = new UserPrincipal ( "ID:" + userName , domain , userName ) ; // wrap the principal in a Subject final Subject subject = new Subject ( ) ; subject . getPrincipals ( ) . add ( userPrincipal ) ; return subject ; }
Authenticate a user by validating the user's password, returning a Subject with one or more {@code Principal}s
set (if validation was successful), or throw a {@code LoginException} (if validation fails)
<p/>
This method checks whether the provided username matches the provided password. This requires a suitable plain
text password validator to work, as the actual validation is performed by the provided
{@code PasswordValidator}). The method also checks that the domain is not {@code null} (but it does allow an
empty String value).
<p/>
If the validation is successful, a {@code Subject} is populated with three principals is returned: The
user's ID as a concatenation of the username with the string "ID:", and both the user provided domain and the
user provided principal (i.e. the the identifiers used to authenticate the users).

@param domain            The white label domain in which the username is located
@param userName          The username to authenticate with
@param password          The password to authenticate with
@param passwordValidator The validator to use for the password
@return a callback for querying subject attributes.
@throws LoginException when this {@code LoginModule} is unable to perform the authentication. Catch a
{@link javax.security.auth.login.FailedLoginException} to determine if the authentication
failed due to an incorrect password
Authenticate a user by validating the user s password returning a Subject with one or more { @code Principal } s set ( if validation was successful ) or throw a { @code LoginException } ( if validation fails ) <p / > This method checks whether the provided username matches the provided password . This requires a suitable plain text password validator to work as the actual validation is performed by the provided { @code PasswordValidator } ) . The method also checks that the domain is not { @code null } ( but it does allow an empty String value ) . <p / > If the validation is successful a { @code Subject } is populated with three principals is returned : The user s ID as a concatenation of the username with the string ID : and both the user provided domain and the user provided principal ( i . e . the the identifiers used to authenticate the users ) .