InitialContext ctx = new InitialContext();
ctx.bind("java:policyRegistration", new SimplePolicyRegistration());
JBossSecurityContext context = new JBossSecurityContext("TestApp");
JBossAuthenticationManager authenticationManager = (JBossAuthenticationManager) context.getAuthenticationManager();
TimedCachePolicy domainCache = new TimedCachePolicy();
domainCache.create();
domainCache.start();
authenticationManager.setCachePolicy(domainCache);
NonSerializableFactory.rebind(ctx, "java:AuthenticationManager", authenticationManager);
}