org.jasypt.hibernate.encryptor
Class HibernatePBEEncryptorRegistry

Object
  extended by org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry

public final class HibernatePBEEncryptorRegistry
extends Object

Registry for all the PBE*Encryptor which are eligible for use from Hibernate.

This class is intended to be directly used in applications where an IoC container (like Spring Framework) is not present. If it is, it is better to use the HibernatePBE*Encryptor classes directly, instead.

This registry is a singleton which maintains a registry of PBE*Encryptor objects which can be used from Hibernate, by using its registeredName to reference them from mappings.

The steps would be:

  1. Obtain the registry instance (getInstance()).
  2. Register the encryptor, giving it a registered name (registerPBE*Encryptor(String, PBE*Encryptor).
  3. Declare a typedef in a Hibernate mapping giving its encryptorRegisteredName parameter the same value specified when registering the encryptor.

This is, first register the encryptor (example with a String encryptor):

  StandardPBEStringEncryptor myEncryptor = new StandardPBEStringEncryptor();
  ...
  HibernatePBEEncryptorRegistry registry =
      HibernatePBEEncryptorRegistry.getInstance();
  registry.registerPBEStringEncryptor("myHibernateEncryptor", myEncryptor);
 

And then, reference it from a Hibernate mapping file:

    <typedef name="encryptedString" class="org.jasypt.hibernate.type.EncryptedStringType">
      <param name="encryptorRegisteredName">myHibernateEncryptor</param>
    </typedef>
 

Since:
1.2 (class existed as org.jasypt.hibernate.HibernatePBEEncryptorRegistry since 1.0)
Author:
Daniel Fernández

Method Summary
static HibernatePBEEncryptorRegistry getInstance()
          Returns the singleton instance of the registry.
 PBEBigDecimalEncryptor getPBEBigDecimalEncryptor(String registeredName)
          Returns the PBEBigDecimalEncryptor registered with the specified name (if exists).
 PBEBigIntegerEncryptor getPBEBigIntegerEncryptor(String registeredName)
          Returns the PBEBigIntegerEncryptor registered with the specified name (if exists).
 PBEByteEncryptor getPBEByteEncryptor(String registeredName)
          Returns the PBEByteEncryptor registered with the specified name (if exists).
 PBEStringEncryptor getPBEStringEncryptor(String registeredName)
          Returns the PBEStringEncryptor registered with the specified name (if exists).
 void registerPBEBigDecimalEncryptor(String registeredName, PBEBigDecimalEncryptor encryptor)
          Registers a PBEBigDecimalEncryptor object with the specified name.
 void registerPBEBigIntegerEncryptor(String registeredName, PBEBigIntegerEncryptor encryptor)
          Registers a PBEBigIntegerEncryptor object with the specified name.
 void registerPBEByteEncryptor(String registeredName, PBEByteEncryptor encryptor)
          Registers a PBEByteEncryptor object with the specified name.
 void registerPBEStringEncryptor(String registeredName, PBEStringEncryptor encryptor)
          Registers a PBEStringEncryptor object with the specified name.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static HibernatePBEEncryptorRegistry getInstance()
Returns the singleton instance of the registry.

Returns:
the registry.

registerPBEStringEncryptor

public void registerPBEStringEncryptor(String registeredName,
                                       PBEStringEncryptor encryptor)
Registers a PBEStringEncryptor object with the specified name.

Parameters:
registeredName - the registered name.
encryptor - the encryptor to be registered.

getPBEStringEncryptor

public PBEStringEncryptor getPBEStringEncryptor(String registeredName)
Returns the PBEStringEncryptor registered with the specified name (if exists).

Parameters:
registeredName - the name with which the desired encryptor was registered.
Returns:
the encryptor, or null if no encryptor has been registered with that name.

registerPBEBigIntegerEncryptor

public void registerPBEBigIntegerEncryptor(String registeredName,
                                           PBEBigIntegerEncryptor encryptor)
Registers a PBEBigIntegerEncryptor object with the specified name.

Parameters:
registeredName - the registered name.
encryptor - the encryptor to be registered.
Since:
1.6

getPBEBigIntegerEncryptor

public PBEBigIntegerEncryptor getPBEBigIntegerEncryptor(String registeredName)
Returns the PBEBigIntegerEncryptor registered with the specified name (if exists).

Parameters:
registeredName - the name with which the desired encryptor was registered.
Returns:
the encryptor, or null if no encryptor has been registered with that name.

registerPBEBigDecimalEncryptor

public void registerPBEBigDecimalEncryptor(String registeredName,
                                           PBEBigDecimalEncryptor encryptor)
Registers a PBEBigDecimalEncryptor object with the specified name.

Parameters:
registeredName - the registered name.
encryptor - the encryptor to be registered.
Since:
1.6

getPBEBigDecimalEncryptor

public PBEBigDecimalEncryptor getPBEBigDecimalEncryptor(String registeredName)
Returns the PBEBigDecimalEncryptor registered with the specified name (if exists).

Parameters:
registeredName - the name with which the desired encryptor was registered.
Returns:
the encryptor, or null if no encryptor has been registered with that name.

registerPBEByteEncryptor

public void registerPBEByteEncryptor(String registeredName,
                                     PBEByteEncryptor encryptor)
Registers a PBEByteEncryptor object with the specified name.

Parameters:
registeredName - the registered name.
encryptor - the encryptor to be registered.
Since:
1.6

getPBEByteEncryptor

public PBEByteEncryptor getPBEByteEncryptor(String registeredName)
Returns the PBEByteEncryptor registered with the specified name (if exists).

Parameters:
registeredName - the name with which the desired encryptor was registered.
Returns:
the encryptor, or null if no encryptor has been registered with that name.


Copyright © 2011 The JASYPT team. All Rights Reserved.