Top Description Inners Fields Constructors Methods
org.h2.security.auth.impl

public Class JaasCredentialsValidator

extends Object
implements CredentialsValidator
Class Inheritance
All Implemented Interfaces
org.h2.api.CredentialsValidator, org.h2.security.auth.Configurable
Imports
java.io.IOException, javax.security.auth.callback.Callback, .CallbackHandler, .NameCallback, .PasswordCallback, .UnsupportedCallbackException, javax.security.auth.login.LoginContext, org.h2.api.CredentialsValidator, org.h2.security.auth.AuthenticationInfo, .ConfigProperties

Validate credentials by using standard Java Authentication and Authorization Service

Configuration parameters:

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private String
public static final String

Constructor Summary

AccessConstructor and Description
public
public
JaasCredentialsValidator(String
= name of JAAS configuration
appName
)

Create the validator with the given name of JAAS configuration

Method Summary

Modifier and TypeMethod and Description
public void
configure(ConfigProperties
= configuration properties
configProperties
)

Implements org.h2.security.auth.Configurable.configure.

configure the component

public boolean
validateCredentials(AuthenticationInfo
= authentication info
authenticationInfo
)

Implements org.h2.api.CredentialsValidator.validateCredentials.

Validate user credential.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

appNameback to summary
private String appName
DEFAULT_APPNAMEback to summary
public static final String DEFAULT_APPNAME

Constructor Detail

JaasCredentialsValidatorback to summary
public JaasCredentialsValidator()
JaasCredentialsValidatorback to summary
public JaasCredentialsValidator(String appName)

Create the validator with the given name of JAAS configuration

Parameters
appName:String

= name of JAAS configuration

Method Detail

configureback to summary
public void configure(ConfigProperties configProperties)

Implements org.h2.security.auth.Configurable.configure.

Doc from org.h2.security.auth.Configurable.configure.

configure the component

Parameters
configProperties:ConfigProperties

= configuration properties

Annotations
@Override
validateCredentialsback to summary
public boolean validateCredentials(AuthenticationInfo authenticationInfo) throws Exception

Implements org.h2.api.CredentialsValidator.validateCredentials.

Doc from org.h2.api.CredentialsValidator.validateCredentials.

Validate user credential.

Parameters
authenticationInfo:AuthenticationInfo

= authentication info

Returns:boolean

true if credentials are valid, otherwise false

Annotations
@Override
Exceptions
Exception:
any exception occurred (invalid credentials or internal issue) prevent user login
org.h2.security.auth.impl back to summary

pack-priv Class JaasCredentialsValidator.AuthenticationInfoCallbackHandler

extends Object
implements CallbackHandler
Class Inheritance
  • java.lang.Object
  • org.h2.security.auth.impl.JaasCredentialsValidator.AuthenticationInfoCallbackHandler
All Implemented Interfaces
javax.security.auth.callback.CallbackHandler

Field Summary

Modifier and TypeField and Description
pack-priv AuthenticationInfo

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
handle(Callback[]
an array of Callback objects provided by an underlying security service which contains the information requested to be retrieved or displayed.
callbacks
)

Implements javax.security.auth.callback.CallbackHandler.handle.

Retrieve or display the information requested in the provided Callbacks.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authenticationInfoback to summary
pack-priv AuthenticationInfo authenticationInfo

Constructor Detail

AuthenticationInfoCallbackHandlerback to summary
pack-priv AuthenticationInfoCallbackHandler(AuthenticationInfo authenticationInfo)

Method Detail

handleback to summary
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException

Implements javax.security.auth.callback.CallbackHandler.handle.

Doc from javax.security.auth.callback.CallbackHandler.handle.

Retrieve or display the information requested in the provided Callbacks.

The handle method implementation checks the instance(s) of the Callback object(s) passed in to retrieve or display the requested information. The following example is provided to help demonstrate what an handle method implementation might look like. This example code is for guidance only. Many details, including proper error handling, are left out for simplicity.

public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {

  for (int i = 0; i < callbacks.length; i++) {
     if (callbacks[i] instanceof TextOutputCallback) {

         // display the message according to the specified type
         TextOutputCallback toc = (TextOutputCallback)callbacks[i];
         switch (toc.getMessageType()) {
         case TextOutputCallback.INFORMATION:
             System.out.println(toc.getMessage());
             break;
         case TextOutputCallback.ERROR:
             System.out.println("ERROR: " + toc.getMessage());
             break;
         case TextOutputCallback.WARNING:
             System.out.println("WARNING: " + toc.getMessage());
             break;
         default:
             throw new IOException("Unsupported message type: " +
                                 toc.getMessageType());
         }

     } else if (callbacks[i] instanceof NameCallback) {

         // prompt the user for a username
         NameCallback nc = (NameCallback)callbacks[i];

         // ignore the provided defaultName
         System.err.print(nc.getPrompt());
         System.err.flush();
         nc.setName((new BufferedReader
                 (new InputStreamReader(System.in))).readLine());

     } else if (callbacks[i] instanceof PasswordCallback) {

         // prompt the user for sensitive information
         PasswordCallback pc = (PasswordCallback)callbacks[i];
         System.err.print(pc.getPrompt());
         System.err.flush();
         pc.setPassword(readPassword(System.in));

     } else {
         throw new UnsupportedCallbackException
                 (callbacks[i], "Unrecognized Callback");
     }
  }
}

// Reads user password from given input stream.
private char[] readPassword(InputStream in) throws IOException {
   // insert code to read a user password from the input stream
}
Parameters
callbacks:Callback[]

an array of Callback objects provided by an underlying security service which contains the information requested to be retrieved or displayed.

Annotations
@Override
Exceptions
IOException:
if an input or output error occurs.
UnsupportedCallbackException:
if the implementation of this method does not support one or more of the Callbacks specified in the callbacks parameter.