users@glassfish.java.net

Re: Get a session object after login with Realm

From: <glassfish_at_javadesktop.org>
Date: Wed, 11 Mar 2009 05:47:29 PDT

public class ActivitesPasswordLoginModule extends AppservPasswordLoginModule {

...

protected void authenticateUser() throws LoginException {
                _logger.info("ActivitesPasswordLoginModule: username = " + _username + " password = " + _password + " current_realm = " + _currentRealm);
                ActivitesRealm activitesRealm = null;
                Enumeration<String> grpList = null;
                Utilisateur utilisateur = null;
                String[] grpArray = null;
                ArrayList<String> grpArrayList = new ArrayList<String>();
                String grpStr = "";
                if (!(_currentRealm instanceof ActivitesRealm)) {
                        throw new LoginException(_currentRealm + " : bad realm");
                } else {
                        activitesRealm = (ActivitesRealm)_currentRealm;
                }
                if (activitesRealm.loginUser(_username, _password)) {
                        _logger.info("loginUser OK");
                        try {
                                grpList = activitesRealm.getGroupNames(_username);
                                utilisateur = activitesRealm.getUtilisateur();
                                _logger.info("récupération des groupes");
                        } catch(InvalidOperationException e) {
                                throw new LoginException(e.getMessage());
                        } catch(NoSuchUserException e) {
                                throw new LoginException(e.getMessage());
                        }
                        while (grpList.hasMoreElements()) {
                                String elt = grpList.nextElement();
                                _logger.info("Ajout de " + elt);
                                grpArrayList.add(elt);
                        }
                        Iterator<String> it = grpArrayList.iterator();
                        grpArray = new String[grpArrayList.size()];
                        int i = 0;
                        while (it.hasNext()) {
                                grpArray[i] = it.next();
                                grpStr += grpArray[i] + " , ";
                                i++;
                        }
                } else {
                        throw new LoginException();
                }
                //SecurityContext.getCurrent().getSubject().getPublicCredentials().add(utilisateur);
                commitUserAuthentication(grpArray);
        }

...

}
[Message sent by forum member 'tominfo' (tominfo)]

http://forums.java.net/jive/thread.jspa?messageID=336347