<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    custom login module and admin-console
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/simkam">Martin Simka</a> in <i>Beginner's Corner</i> - <a href="http://community.jboss.org/message/579061#579061">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My custom login module authenticates user against active directory and assigns roles from database. It works great with jmx-console but I can't get it work with admin-console. No error, no exception, just&#160; HTTP Status 404 - /admin-console/loggedIn.seam after succesfull authentication</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Login Module</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> LdapDBLoginModule <font color="navy"><b>implements</b></font> LoginModule <font color="navy">{</font>
&#160;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String LDAP_URL = <font color="red">"ldap-url"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String LDAP_DOMAIN = <font color="red">"ldap-domain"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String LDAP_BASE_DN = <font color="red">"ldap-base-dn"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String APPLICATION_NAME = <font color="red">"application-name"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String DS_JNDI_NAME = <font color="red">"ds-jndi-name"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String QRY_PARAM_UZIVATEL = <font color="red">"uzivatel"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String QRY_PARAM_SKUPINA = <font color="red">"skupina"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String ROLE_QUERY = <font color="red">"SELECT nazev_role as role, uzivatel as uziv "</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + <font color="red">"FROM jbosslogin_pristupy pristup "</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + <font color="red">"LEFT JOIN jbosslogin_role role on pristup.role=role.id "</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + <font color="red">"LEFT JOIN jbosslogin_uzivatele uziv on uziv.username=pristup.uzivatel "</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + <font color="red">"WHERE role.aplikace=? and uziv.typ=?"</font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> Subject subject;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> CallbackHandler callbackHandler;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> Map sharedState;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> Map options;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>boolean</b></font> success = <font color="navy"><b>false</b></font>;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> MyPrincipal userPrincipal;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> Set&lt;String&gt; roles;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> String ldapUrl;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> String ldapBaseDn;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> String dsJndiName;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> String applicationName;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> String ldapDomain;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> Logger logger = Logger.getLogger(LdapDBLoginModule.class.getName());
&#160;
&#160;&#160;&#160; <font color="darkgreen">/**
&#160;&#160;&#160;&#160; * Incializace
&#160;&#160;&#160;&#160; * @param subject
&#160;&#160;&#160;&#160; * @param callbackHandler
&#160;&#160;&#160;&#160; * @param sharedState
&#160;&#160;&#160;&#160; * @param options
&#160;&#160;&#160;&#160; */</font>
&#160;&#160;&#160; @Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"initialize login"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.subject = subject;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.callbackHandler = callbackHandler;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.sharedState = sharedState;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.options = options;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.ldapUrl = (String) options.get(LDAP_URL);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.ldapBaseDn = (String) options.get(LDAP_BASE_DN);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.dsJndiName = (String) options.get(DS_JNDI_NAME);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (dsJndiName == <font color="navy"><b>null</b></font>) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dsJndiName = <font color="red">"java:/DefaultDS"</font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.applicationName = (String) options.get(APPLICATION_NAME);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.ldapDomain = (String) options.get(LDAP_DOMAIN);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; roles = <font color="navy"><b>new</b></font> HashSet&lt;String&gt;();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"application {0}"</font>, applicationName);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"dsJndiName {0}"</font>, dsJndiName);
&#160;
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160; @Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>boolean</b></font> login() <font color="navy"><b>throws</b></font> LoginException <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"initialize login"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (callbackHandler == <font color="navy"><b>null</b></font>) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Chyba prihlaseni. Neni dostupny CallbackHandler"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> LoginException(<font color="red">"Chyba prihlaseni. Neni dostupny CallbackHandler"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; NameCallback nc = <font color="navy"><b>new</b></font> NameCallback(<font color="red">"User name: "</font>, <font color="red">"guest"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; PasswordCallback pc = <font color="navy"><b>new</b></font> PasswordCallback(<font color="red">"Password: "</font>, <font color="navy"><b>false</b></font>);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Callback[] callbacks = <font color="navy">{</font>nc, pc<font color="navy">}</font>;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; String username = <font color="navy"><b>null</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; String password = <font color="navy"><b>null</b></font>;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callbackHandler.handle(callbacks);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; username = nc.getName();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; password = <font color="navy"><b>new</b></font> String(pc.getPassword());
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"uzivatel {0}"</font>, username);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"heslo {0}"</font>, password);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LdapControl ldapControl = <font color="navy"><b>new</b></font> LdapControl(ldapUrl, username + <font color="red">"@"</font> + ldapDomain, password, ldapBaseDn);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ADUser adUser = ldapControl.getUserByUsername(username, ZdasFilters.ZDAS_USER_BY_USERNAME);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; userPrincipal = parseAdUser(adUser);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; roles = getDataZDb(username, adUser.getMemberOf());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (roles.isEmpty()) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Prihlaseni uzivatele {0} se nezdarilo, overeni proti databazi pristupu."</font>, username);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> FailedLoginException(<font color="red">"Prihlaseni uzivatele "</font> + username + <font color="red">" se nezdarilo, overeni proti databazi pristupu."</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (AdZaznamNenalezenException azne) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; userPrincipal = <font color="navy"><b>new</b></font> MyPrincipal(username, <font color="red">""</font>, <font color="red">""</font>, username, <font color="red">""</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; success = <font color="navy"><b>true</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Uzivatel {0}prihlasenen. LoginOk: {1}"</font>, <font color="navy"><b>new</b></font> Object[]<font color="navy">{</font>username, success<font color="navy">}</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (AuthenticationException ae) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Prihlaseni uzivatele {0} se nezdarilo, overeni proti domene."</font>, username);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> <font color="navy"><b>new</b></font> FailedLoginException(<font color="red">"Prihlaseni uzivatele "</font> + username + <font color="red">" se nezdarilo, overeni proti domene."</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (NamingException ne) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Chyba prihlaseni. Chyba spojeni s LDAP"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginException le = <font color="navy"><b>new</b></font> LoginException(<font color="red">"Chyba prihlaseni. Chyba spojeni s LDAP"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; le.initCause(ne);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> le;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (IOException ioe) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Chyba prihlaseni. Nepodarilo se precist username/password"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginException le = <font color="navy"><b>new</b></font> LoginException(<font color="red">"Chyba prihlaseni. Nepodarilo se precist username/password"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; le.initCause(ioe);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> le;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (UnsupportedCallbackException uce) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"CallbackHandler nepodporuje: {0}"</font>, uce.getCallback());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginException le = <font color="navy"><b>new</b></font> LoginException(<font color="red">"CallbackHandler nepodporuje: "</font> + uce.getCallback());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; le.initCause(uce);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> le;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160; @Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>boolean</b></font> commit() <font color="navy"><b>throws</b></font> LoginException <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"commit, loginOk: {0}"</font>, success);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (!success) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>false</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set principals = subject.getPrincipals();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; principals.add(userPrincipal);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyGroup group = <font color="navy"><b>new</b></font> MyGroup(<font color="red">"Roles"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Role: {0}"</font>, roles);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font> (String str : roles) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyGroup g = <font color="navy"><b>new</b></font> MyGroup(str);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; g.addMember(group);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; principals.add(g);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; group.addMember(g);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; principals.add(group);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160; @Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>boolean</b></font> abort() <font color="navy"><b>throws</b></font> LoginException <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"abort login"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; success = <font color="navy"><b>false</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logout();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160; @Override
&#160;&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>boolean</b></font> logout() <font color="navy"><b>throws</b></font> LoginException <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"logout"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set principals = subject.getPrincipals();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; principals.remove(userPrincipal);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyGroup group = <font color="navy"><b>new</b></font> MyGroup(<font color="red">"Roles"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font> (String str : roles) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyGroup myGroup = <font color="navy"><b>new</b></font> MyGroup(str);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; principals.remove(myGroup);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; group.addMember(myGroup);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; principals.remove(group);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>true</b></font>;
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> MyPrincipal parseAdUser(ADUser adUser) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; String desc = adUser.getDescription();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; String osobniCislo = <font color="navy"><b>null</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (desc != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (desc.contains(<font color="red">";"</font>)) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; osobniCislo = desc.split(<font color="red">";"</font>)[0];
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>else</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; osobniCislo = desc;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>new</b></font> MyPrincipal(adUser.getsAMAccountName(), adUser.getName(), adUser.getSn(), adUser.getDisplayName(), osobniCislo);
&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160; <font color="navy"><b>private</b></font> Set&lt;String&gt; getDataZDb(String username, List&lt;String&gt; skupiny) <font color="navy"><b>throws</b></font> LoginException <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Connection conn = <font color="navy"><b>null</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; PreparedStatement ps = <font color="navy"><b>null</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ResultSet rs = <font color="navy"><b>null</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitialContext ic = <font color="navy"><b>new</b></font> InitialContext();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DataSource ds = (DataSource) ic.lookup(dsJndiName);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; conn = ds.getConnection();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ps = conn.prepareStatement(ROLE_QUERY);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ps.setString(1, applicationName);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ps.setString(2, QRY_PARAM_UZIVATEL);
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rs = ps.executeQuery();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set&lt;String&gt; set = <font color="navy"><b>new</b></font> HashSet&lt;String&gt;();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>while</b></font> (rs.next()) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String u = rs.getString(<font color="red">"uziv"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (u.trim().equals(username)) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set.add(rs.getString(<font color="red">"role"</font>));
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ps.setString(2, QRY_PARAM_SKUPINA);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rs = ps.executeQuery();
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>while</b></font> (rs.next()) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String u = rs.getString(<font color="red">"uziv"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font> (String skup : skupiny) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (u.trim().equals(skup)) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set.add(rs.getString(<font color="red">"role"</font>));
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>break</b></font>;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> set;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (NamingException ne) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Chyba prihlasni. Chyba datasource."</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginException le = <font color="navy"><b>new</b></font> LoginException(<font color="red">"Chyba prihlasni. Chyba datasource."</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; le.initCause(ne);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> le;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (SQLException sqle) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; logger.log(Level.INFO, <font color="red">"Chyba prihlasni. Chyba query."</font>, sqle);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LoginException le = <font color="navy"><b>new</b></font> LoginException(<font color="red">"Chyba prihlasni. Chyba query."</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; le.initCause(sqle);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>throw</b></font> le;
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>finally</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (rs != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rs.close();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (SQLException e) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (ps != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ps.close();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (SQLException e) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (conn != <font color="navy"><b>null</b></font>) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>try</b></font> <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; conn.close();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font> <font color="navy"><b>catch</b></font> (SQLException ex) <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160; <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any idea?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Also I'm not sure about commit method. Maybe there is a mistake.</p><p>(jboss-6.0.0.Final)</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/579061#579061">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>