diff -r f08e57ab4480 -r c7d713d71ad3 java/sql-java-prihlasovani/src/cz/frantovo/jaas/sql/SQLRealm.java --- a/java/sql-java-prihlasovani/src/cz/frantovo/jaas/sql/SQLRealm.java Thu Jul 21 20:35:23 2011 +0200 +++ b/java/sql-java-prihlasovani/src/cz/frantovo/jaas/sql/SQLRealm.java Thu Jul 21 23:40:45 2011 +0200 @@ -1,22 +1,64 @@ package cz.frantovo.jaas.sql; import com.sun.appserv.security.AppservRealm; -import com.sun.enterprise.security.auth.realm.InvalidOperationException; +import com.sun.enterprise.security.auth.realm.BadRealmException; +import com.sun.enterprise.security.auth.realm.NoSuchRealmException; import com.sun.enterprise.security.auth.realm.NoSuchUserException; import java.util.Enumeration; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.security.auth.login.LoginException; /** + * Bezpečnostní doména. + * Uživatelé jsou uloženi v SQL databázi. * @author fiki */ public class SQLRealm extends AppservRealm { + private static final String AUTH_TYPE = "Ověřuje uživatele proti SQL databázi."; + private static final Logger log = Logger.getLogger(SQLRealm.class.getName()); + @Override - public String getAuthType() { - throw new UnsupportedOperationException("Not supported yet."); + public void init(Properties parametry) throws BadRealmException, NoSuchRealmException { + super.init(parametry); + + String jaasContext = parametry.getProperty(JAAS_CONTEXT_PARAM, SQLLoginModul.VÝCHOZÍ_JAAS_KONTEXT); + setProperty(JAAS_CONTEXT_PARAM, jaasContext); + + log.log(Level.INFO, "SQLRealm úspěšně vytvořen. JaasContext: {0}", jaasContext); } @Override - public Enumeration getGroupNames(String string) throws InvalidOperationException, NoSuchUserException { - throw new UnsupportedOperationException("Not supported yet."); + public String getAuthType() { + return AUTH_TYPE; + } + + /** + * @param uživatel přihlašovací jméno uživatele + * @return seznam skupin, ve kterých se daný uživatel nachází + * @throws NoSuchUserException když uživatel s tímto jménem neexistuje. + */ + @Override + public Enumeration getGroupNames(String uživatel) throws NoSuchUserException { + throw new NoSuchUserException("Metoda zatím není implementována. Uživatel: " + uživatel); + } + + /** + * + * @param jméno uživatelské jméno + * @param heslo heslo + * @return seznam skupin, do kterých uživatel patří + */ + public String[] ověřUživatele(String jméno, char[] heslo) throws LoginException { + + // TODO: skutečně ověřovat heslo proti databázi + + if (heslo != null && heslo.length == 3) { + return new String[]{"bezny"}; + } else { + throw new LoginException("Heslo musí mít tři znaky :-P"); + } } }