code: public static SipPrincipal impersonatePrincipal(String username, Realm realm) {
  		Method getPrincipalMethod = null;
  		Class clazz = realm.getClass();
  		try {
  			if(!(realm instanceof RealmBase)) {
  				throw new RuntimeException("Only Realms extending RealmBase are supported. Report this error. Current realm class is " +
  						realm.getClass().getCanonicalName());
  			}
  			while(getPrincipalMethod == null) {
  				try {
  					getPrincipalMethod = clazz.getDeclaredMethod("getPrincipal", String.class);
  				} catch (NoSuchMethodException e) {
  					log.warn("unexpected exception while impersonatePrincipal", e);
  				}
  				clazz = clazz.getSuperclass();
  				if(clazz == null) break;
  			}
  			getPrincipalMethod.setAccessible(true);
  			Principal principal =  (Principal) getPrincipalMethod.invoke(realm, username);
  			return new CatalinaSipPrincipal(principal);
  		} catch (Throwable t) {
  			log.error("Could not impersonate user " + username, t);
  		} finally {
  			if(getPrincipalMethod != null) {
  				getPrincipalMethod.setAccessible(false);
  			}
  		}
  		return null;
  		
  	}
docs: /*
  This method attempts to obtain the Principal of a user from a realm without having to
  authenticate with a password or certificate. Not all realms support this, but we can use
  reflection to peek into Realms that extend RealmBase.