Top Description Fields Constructors Methods
jakarta.security.auth.message.callback

public Class PasswordValidationCallback

extends Object
implements Callback
Class Inheritance
All Implemented Interfaces
javax.security.auth.callback.Callback
Imports
java.util.Arrays, javax.security.auth.Subject, javax.security.auth.callback.Callback

Callback for PasswordValidation.

This callback may be used by an authentication module to employ the password validation facilities of its containing runtime. This Callback would typically be called by a ServerAuthModule during validateRequest processing.

This callback causes the following actions to be done:

  1. Validate the credentials
  2. If validated set caller principal (conceptually just like CallerPrincipalCallback does)
  3. If validated and groups available set groups (conceptually just like GroupPrincipalCallback does)
The code below shows a hypothetical example of how a PasswordValidationCallback could be implemented by a Jakarta Authentication implementation provided CallbackHandler:
protected void processPasswordValidation(PasswordValidationCallback pwdCallback) {

   // 1. Validate the credentials
   Caller caller = ContainerSpecificStore.validate(pwdCallback.getUsername(), getPassword(pwdCallback));

   if (caller != null) {
       // 2. If validated set caller principal, just like CallerPrincipalCallback does
       processCallerPrincipal(new CallerPrincipalCallback(pwdCallback.getSubject(), caller.getCallerPrincipal()));

       if (!caller.getGroups().isEmpty()) {
           // 3. If validated and groups available set groups, just like GroupPrincipalCallback does
           processGroupPrincipal(new GroupPrincipalCallback(pwdCallback.getSubject(), caller.getGroupsAsArray()));
       }

       pwdCallback.setResult(true);
   }
}

Note that in this example:

Field Summary

Modifier and TypeField and Description
private char[]
private boolean
private Subject
private String

Constructor Summary

AccessConstructor and Description
public
PasswordValidationCallback(Subject
The subject for authentication
subject
,
String
The username to authenticate
username
,
char[]
The user's password, which may be null.
password
)

Create a PasswordValidationCallback.

Method Summary

Modifier and TypeMethod and Description
public void
clearPassword()

Clear the password.

public char[]

Returns:

The password, which may be null.
getPassword
()

Get the password.

public boolean

Returns:

True if authentication succeeded, false otherwise
getResult
()

Get the authentication result.

public Subject

Returns:

The subject.
getSubject
()

Get the subject.

public String

Returns:

The username.
getUsername
()

Get the username.

public void
setResult(boolean
True if authentication succeeded, false otherwise
result
)

Set the authentication result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

passwordback to summary
private char[] password
resultback to summary
private boolean result
subjectback to summary
private Subject subject
usernameback to summary
private String username

Constructor Detail

PasswordValidationCallbackback to summary
public PasswordValidationCallback(Subject subject, String username, char[] password)

Create a PasswordValidationCallback.

Parameters
subject:Subject

The subject for authentication

username:String

The username to authenticate

password:char[]

The user's password, which may be null.

Method Detail

clearPasswordback to summary
public void clearPassword()

Clear the password.

getPasswordback to summary
public char[] getPassword()

Get the password.

Note that this method returns a reference to the password. If a clone of the array is created it is the caller's responsibility to zero out the password information after it is no longer needed.

Returns:char[]

The password, which may be null.

getResultback to summary
public boolean getResult()

Get the authentication result.

Returns:boolean

True if authentication succeeded, false otherwise

getSubjectback to summary
public Subject getSubject()

Get the subject.

Returns:Subject

The subject.

getUsernameback to summary
public String getUsername()

Get the username.

Returns:String

The username.

setResultback to summary
public void setResult(boolean result)

Set the authentication result.

Parameters
result:boolean

True if authentication succeeded, false otherwise