IdentityStore

There are two built-in IdentityStore implementations provided in Glassfish v5, Database or Ldap.

An example of using built-in @DatabaseIdentityStoreDefinition to setup database based IdentityStore.

@DatabaseIdentityStoreDefinition(
    dataSourceLookup = "${'java:global/MyDS'}",
    callerQuery = "#{'select password from caller where name = ?'}",
    groupsQuery = "select group_name from caller_groups where caller_name = ?",
    hashAlgorithm = Pbkdf2PasswordHash.class,
    priorityExpression = "#{100}",
    hashAlgorithmParameters = {
        "Pbkdf2PasswordHash.Iterations=3072",
        "${applicationConfig.dyna}"
    } // just for test / example
)
@ApplicationScoped
@Named
public class ApplicationConfig {

    public String[] getDyna() {
        return new String[]{"Pbkdf2PasswordHash.Algorithm=PBKDF2WithHmacSHA512", "Pbkdf2PasswordHash.SaltSizeBytes=64"};
    }

}

Initializes database with the initial users.

Note, we configure a Pbkdf2PasswordHash bean which is used to hash password.

Similar with @DatabaseIdentityStoreDefinition, there is a @LdapIdentityStoreDefinition for configuring users and groups in Ldap servers, such Microsoft Active Directory, Apache Directory.

You can also customize IdentityStore by implementing the IdentityStore interface.

Grab the source codes from my GitHub account, and have a try.

Last updated

Was this helpful?