private LDAPRealm getLdapRealm(SecurityManager sm) throws XPathException {
try {
Method mFindRealm = sm.getClass().getDeclaredMethod("findRealmForRealmId", String.class);
mFindRealm.setAccessible(true);
Realm realm = (Realm)mFindRealm.invoke(sm, LDAPRealm.ID);
if(realm == null) {
throw new XPathException("The LDAP Realm is not in use!");
}
return (LDAPRealm)realm;