author | František Kučera <franta-hg@frantovo.cz> |
Tue, 07 Feb 2012 18:03:31 +0100 | |
changeset 7 | 46bb283a674d |
permissions | -rw-r--r-- |
franta-hg@7 | 1 |
package cz.frantovo.jaas.sql; |
franta-hg@7 | 2 |
|
franta-hg@7 | 3 |
import com.sun.appserv.security.AppservRealm; |
franta-hg@7 | 4 |
import com.sun.enterprise.security.auth.realm.BadRealmException; |
franta-hg@7 | 5 |
import com.sun.enterprise.security.auth.realm.NoSuchRealmException; |
franta-hg@7 | 6 |
import java.util.Properties; |
franta-hg@7 | 7 |
|
franta-hg@7 | 8 |
/** |
franta-hg@7 | 9 |
* |
franta-hg@7 | 10 |
* @author Ing. František Kučera (frantovo.cz) |
franta-hg@7 | 11 |
*/ |
franta-hg@7 | 12 |
public abstract class ParametrizovanýRealm extends AppservRealm { |
franta-hg@7 | 13 |
|
franta-hg@7 | 14 |
@Override |
franta-hg@7 | 15 |
protected void init(Properties parametry) throws BadRealmException, NoSuchRealmException { |
franta-hg@7 | 16 |
super.init(parametry); |
franta-hg@7 | 17 |
getProperties().putAll(parametry); |
franta-hg@7 | 18 |
parametrizuj(); |
franta-hg@7 | 19 |
} |
franta-hg@7 | 20 |
|
franta-hg@7 | 21 |
@Override |
franta-hg@7 | 22 |
public synchronized void setProperty(String název, String hodnota) { |
franta-hg@7 | 23 |
super.setProperty(název, hodnota); |
franta-hg@7 | 24 |
try { |
franta-hg@7 | 25 |
parametrizuj(); |
franta-hg@7 | 26 |
} catch (BadRealmException e) { |
franta-hg@7 | 27 |
throw new IllegalArgumentException("Tento parametr nelze nastavit: " + název + " = " + hodnota, e); |
franta-hg@7 | 28 |
} |
franta-hg@7 | 29 |
} |
franta-hg@7 | 30 |
|
franta-hg@7 | 31 |
/** |
franta-hg@7 | 32 |
* @param názevParametru který hledáme |
franta-hg@7 | 33 |
* @param popis pokud dojde k výjimce, tento popis se v ní objeví |
franta-hg@7 | 34 |
* @return hodnota parametru nebo… |
franta-hg@7 | 35 |
* @throws BadRealmException … pokud byl parametr nulový nebo po měl oříznutí nulovou délku |
franta-hg@7 | 36 |
*/ |
franta-hg@7 | 37 |
protected String najdiParametr(String názevParametru, String popis) throws BadRealmException { |
franta-hg@7 | 38 |
String hodnotaParametru = getProperty(názevParametru); |
franta-hg@7 | 39 |
|
franta-hg@7 | 40 |
if (hodnotaParametru == null || hodnotaParametru.trim().length() < 1) { |
franta-hg@7 | 41 |
throw new BadRealmException("Chybí " + popis + " – parametr: " + názevParametru); |
franta-hg@7 | 42 |
} else { |
franta-hg@7 | 43 |
return hodnotaParametru; |
franta-hg@7 | 44 |
} |
franta-hg@7 | 45 |
} |
franta-hg@7 | 46 |
|
franta-hg@7 | 47 |
protected abstract void parametrizuj() throws BadRealmException; |
franta-hg@7 | 48 |
} |