Well I created my own UsernamePasswordLoginModule and then extended it in same
DatabaseServerLoginModule. Everything works fine, but it does not pull entity
bean inside.
Please look at my code in the end of login() function:
| public boolean login() throws LoginException
| {
| // See if shared credentials exist
| if( super.login() == true )
| {
| // Setup our view of the user
| Object username =
sharedState.get("javax.security.auth.login.name");
| if( username instanceof Principal )
| identity = (Principal) username;
| else
| {
| String name = username.toString();
| try
| {
| identity = createIdentity(name);
| }
| catch(Exception e)
| {
| log.debug("Failed to create principal", e);
| throw new LoginException("Failed to create principal: "+
e.getMessage());
| }
| }
| Object password =
sharedState.get("javax.security.auth.login.password");
| if( password instanceof char[] )
| credential = (char[]) password;
| else if( password != null )
| {
| String tmp = password.toString();
| credential = tmp.toCharArray();
| }
| return true;
| }
|
| super.loginOk = false;
| String[] info = getUsernameAndPassword();
| String username = info[0];
| String password = info[1];
| if( username == null && password == null )
| {
| identity = unauthenticatedIdentity;
| super.log.trace("Authenticating as
unauthenticatedIdentity="+identity);
| }
|
| if( identity == null )
| {
| try
| {
| identity = createIdentity(username);
| }
| catch(Exception e)
| {
| log.debug("Failed to create principal", e);
| throw new LoginException("Failed to create principal: "+
e.getMessage());
| }
|
| // Hash the user entered password if password hashing is in use
| if( hashAlgorithm != null )
| password = createPasswordHash(username, password);
| // Validate the password supplied by the subclass
| String expectedPassword = getUsersPassword();
| if( validatePassword(password, expectedPassword) == false )
| {
| super.log.debug("Bad password for username="+username);
| throw new FailedLoginException("Password Incorrect/Password
Required");
| }
| }
|
| if( getUseFirstPass() == true )
| { // Add the username and password to the shared state map
| sharedState.put("javax.security.auth.login.name", username);
| sharedState.put("javax.security.auth.login.password", credential);
| }
| super.loginOk = true;
| // Start of my ugly code
| // Pull Entity bean in right place
| try {
| InitialContext ctx = new InitialContext();
| em = (EntityManager) ctx.lookup("digizoneDatabase");
| String query = new String("FROM " +
| PortalUser.class.getName() +
| " where login='" + username +
| "'");
| //
| // get user from db
| //
| List list = em.createQuery(query).getResultList();
| if ( list != null && list.size() > 0 ) {
| Object obj = list.get(0);
| if ( obj instanceof PortalUser ){
| PortalUser portalUser = (PortalUser) obj;
| HttpServletRequest request = (HttpServletRequest)
PolicyContext.getContext(WEB_REQUEST_KEY);
| HttpSession session = request.getSession();
| session.setAttribute("user",portalUser);
| }
| }
| } catch (Exception e) {
| e.printStackTrace();
| }
| // End of my ugly code
| super.log.trace("User '" + identity + "' authenticated,
loginOk="+loginOk);
| return true;
| }
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3932934#3932934
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3932934
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user