franta-hg@7: package cz.frantovo.jaas.sql; franta-hg@7: franta-hg@7: import com.sun.appserv.security.AppservRealm; franta-hg@7: import com.sun.enterprise.security.auth.realm.BadRealmException; franta-hg@7: import com.sun.enterprise.security.auth.realm.NoSuchRealmException; franta-hg@7: import java.util.Properties; franta-hg@7: franta-hg@7: /** franta-hg@7: * franta-hg@7: * @author Ing. František Kučera (frantovo.cz) franta-hg@7: */ franta-hg@7: public abstract class ParametrizovanýRealm extends AppservRealm { franta-hg@7: franta-hg@7: @Override franta-hg@7: protected void init(Properties parametry) throws BadRealmException, NoSuchRealmException { franta-hg@7: super.init(parametry); franta-hg@7: getProperties().putAll(parametry); franta-hg@7: parametrizuj(); franta-hg@7: } franta-hg@7: franta-hg@7: @Override franta-hg@7: public synchronized void setProperty(String název, String hodnota) { franta-hg@7: super.setProperty(název, hodnota); franta-hg@7: try { franta-hg@7: parametrizuj(); franta-hg@7: } catch (BadRealmException e) { franta-hg@7: throw new IllegalArgumentException("Tento parametr nelze nastavit: " + název + " = " + hodnota, e); franta-hg@7: } franta-hg@7: } franta-hg@7: franta-hg@7: /** franta-hg@7: * @param názevParametru který hledáme franta-hg@7: * @param popis pokud dojde k výjimce, tento popis se v ní objeví franta-hg@7: * @return hodnota parametru nebo… franta-hg@7: * @throws BadRealmException … pokud byl parametr nulový nebo po měl oříznutí nulovou délku franta-hg@7: */ franta-hg@7: protected String najdiParametr(String názevParametru, String popis) throws BadRealmException { franta-hg@7: String hodnotaParametru = getProperty(názevParametru); franta-hg@7: franta-hg@7: if (hodnotaParametru == null || hodnotaParametru.trim().length() < 1) { franta-hg@7: throw new BadRealmException("Chybí " + popis + " – parametr: " + názevParametru); franta-hg@7: } else { franta-hg@7: return hodnotaParametru; franta-hg@7: } franta-hg@7: } franta-hg@7: franta-hg@7: protected abstract void parametrizuj() throws BadRealmException; franta-hg@7: }