[[Caching_Migration]] = Caching Migration Where a PicketBox based security domain is defined it is possible to enable caching for that security domain, this enables subsequent hits to the identity store to be avoided as an in memory cache can be used instead, this example demonstrates how caching can be used with a WildFly Elytron based configuration. The purpose of this chapter is to highlight the migration of a configuration with caching enabled, this example is based in the previous LDAP example but with caching enabled. == PicketBox Example A PicketBox based security domain can be defined with the following commands. [source, ruby] ---- ./subsystem=security/security-domain=application-security:add(cache-type=default) ./subsystem=security/security-domain=application-security/authentication=classic:add(login-modules=[{code=LdapExtended, flag=Required, module-options={ \ java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory, \ java.naming.provider.url=ldap://localhost:10389, \ java.naming.security.authentication=simple, \ bindDN="uid=admin,ou=system", \ bindCredential=secret, \ baseCtxDN="ou=users,dc=group-to-principal,dc=wildfly,dc=org", \ baseFilter="(uid={0})", \ rolesCtxDN="ou=groups,dc=group-to-principal,dc=wildfly,dc=org",\ roleFilter="(uniqueMember={1})", \ roleAttributeID="uid" \ }}]) ---- Resulting in the following security domain definition: [source, xml] ---- ... ---- == Migrated Example When using WildFly Elytron where caching is required the individual security realm is wrapped using a cache, a migrated configuration can be defined with the following commands: [source, ruby] ---- ./subsystem=elytron/dir-context=ldap-connection:add(url=ldap://localhost:10389, principal="uid=admin,ou=system", credential-reference={clear-text=secret}) ./subsystem=elytron/ldap-realm=ldap-realm:add(dir-context=ldap-connection, \ direct-verification=true, \ identity-mapping={search-base-dn="ou=users,dc=group-to-principal,dc=wildfly,dc=org", \ rdn-identifier="uid", \ attribute-mapping=[{filter-base-dn="ou=groups,dc=group-to-principal,dc=wildfly,dc=org",filter="(uniqueMember={1})",from="uid",to="Roles"}]}) ./subsystem=elytron/caching-realm=cached-ldap:add(realm=ldap-realm) ---- These can then be used in a security domain and subsequently an authentication factory. [source, ruby] ---- ./subsystem=elytron/security-domain=application-security:add(realms=[{realm=cached-ldap}], default-realm=cached-ldap, permission-mapper=default-permission-mapper) ./subsystem=elytron/http-authentication-factory=application-security-http:add(http-server-mechanism-factory=global, security-domain=application-security, mechanism-configurations=[{mechanism-name=BASIC}]) ---- In this final step it is very important that the caching-realm is referenced rather than the original realm otherwise caching will be bypassed. This results in the following definitions: [source, xml] ---- ... ... ... ... ... ... ... ----