java/sql-java-prihlasovani/src/cz/frantovo/jaas/sql/SQLLoginModul.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 21 Jul 2011 23:40:45 +0200
changeset 4 c7d713d71ad3
parent 3 f08e57ab4480
child 6 aff44e80f418
permissions -rw-r--r--
Jde to zkompilovat a spustit. Umí přihlásit i nepřihlásit uživatele. K databázi se zatím nepřipojuje.
franta-hg@2
     1
package cz.frantovo.jaas.sql;
franta-hg@2
     2
franta-hg@2
     3
import com.sun.appserv.security.AppservPasswordLoginModule;
franta-hg@4
     4
import java.util.Arrays;
franta-hg@4
     5
import java.util.logging.Level;
franta-hg@4
     6
import java.util.logging.Logger;
franta-hg@4
     7
import javax.security.auth.login.LoginException;
franta-hg@2
     8
franta-hg@2
     9
/**
franta-hg@4
    10
 * Přihlašovací modul pro SQL doménu.
franta-hg@2
    11
 * TODO: později bude potomkem <code>com.sun.appserv.security.AbstractLoginModule</code>
franta-hg@2
    12
 * @author fiki
franta-hg@2
    13
 */
franta-hg@2
    14
public class SQLLoginModul extends AppservPasswordLoginModule {
franta-hg@4
    15
franta-hg@4
    16
	/** viz konfigurace v login.conf */
franta-hg@4
    17
	public static final String VÝCHOZÍ_JAAS_KONTEXT = "sqlRealm";
franta-hg@4
    18
	private static final Logger log = Logger.getLogger(SQLLoginModul.class.getName());
franta-hg@4
    19
franta-hg@4
    20
	@Override
franta-hg@4
    21
	protected void authenticateUser() throws LoginException {
franta-hg@4
    22
franta-hg@4
    23
		if (_currentRealm instanceof SQLRealm) {			
franta-hg@4
    24
		
franta-hg@4
    25
			SQLRealm sqlRealm = (SQLRealm)_currentRealm;			
franta-hg@4
    26
			String skupiny[] = sqlRealm.ověřUživatele(_username, _passwd);			
franta-hg@4
    27
			commitUserAuthentication(skupiny);
franta-hg@4
    28
			
franta-hg@4
    29
		} else {
franta-hg@4
    30
			throw new LoginException("Špatný realm: " + _currentRealm + " Očekávám: SQLRealm.");
franta-hg@4
    31
		}
franta-hg@4
    32
	}
franta-hg@2
    33
}