Perhaps you're right I will test that in the next hours. To be complete, this 
is my LoginFacade:

  | /**
  |  * 
  |  */
  | package vwg.audi.cancard.business;
  | 
  | import javax.naming.AuthenticationException;
  | import javax.security.auth.login.LoginContext;
  | import javax.security.auth.login.LoginException;
  | 
  | import org.apache.log4j.Logger;
  | import org.jboss.security.auth.callback.UsernamePasswordHandler;
  | 
  | import vwg.audi.cancard.JAASLoginException;
  | import vwg.audi.cancard.ui.JAASConstants;
  | 
  | /**
  |  * LoginFacade
  |  * 
  |  * @author Michael Obster (michael.obs...@epos-cat.de)
  |  */
  | public class LoginFacade {
  |     private Logger log = Logger.getLogger(this.getClass());
  |     
  |     private LoginContext lc = null;
  |     private String loginContext = "";
  |     private String clientContext = "";
  | 
  |     public LoginFacade(String loginContext, String clientContext) {
  |             this.loginContext = loginContext;
  |             this.clientContext = clientContext;
  |     }
  |     
  |     /**
  |      * Real login, used by GUI.
  |      * 
  |      * @param username
  |      * @param strPassword
  |      * @throws Exception
  |      */
  |     public void login(String username, String strPassword) throws Exception{
  |             char[] password  = strPassword != null ? 
strPassword.toCharArray() : "".toCharArray() ;
  |         UsernamePasswordHandler handler = new 
UsernamePasswordHandler(username, password);
  |         
  |         lc = null;
  |             try {
  |                     //Login for usercheck
  |                     lc = new LoginContext(loginContext, handler);
  |                     lc.login();
  |                     
  |             } catch (Exception e) {
  |                     Throwable t = e;
  |                     while (t.getCause() != null) {
  |                             
  |                             if (t instanceof AuthenticationException) {
  |                                     break;
  |                             }
  |                             t = t.getCause();
  |                     }
  |                                     
  |                     //Analyse AuthenticationException
  |                     if (t instanceof AuthenticationException) {
  |                             AuthenticationException ex = 
(AuthenticationException)t;
  |                             String emsg = ex.getExplanation();
  |                 if (!hasValue(emsg)) {
  |                     emsg = "";
  |                 }
  |                 String errorhint = JAASConstants.USER_NOT_AUTHENTICATED;
  |                 if (emsg.indexOf("password expired") > 0) {
  |                     errorhint = JAASConstants.PASSWORD_EXPIRED;
  |                 } else if (emsg.indexOf("error code 49") > 0) {
  |                     errorhint = JAASConstants.PASSWORD_INVALID;
  |                 } else if (emsg.indexOf("error code 19") > 0) {
  |                     errorhint = JAASConstants.USER_REVOKED;
  |                 } else if (emsg.indexOf("error code 32") > 0) {
  |                     errorhint = JAASConstants.USER_INVALID;
  |                 }
  |                 log.debug(username + " " + ex.getExplanation() + " hint: " 
+ errorhint);
  |                 throw new JAASLoginException(errorhint, ex);
  |                             
  |                     } else if (t instanceof LoginException) {
  |                             LoginException ex = (LoginException)t;
  |                             String emsg = ex.getMessage();
  |                 if (!hasValue(emsg)) {
  |                     emsg = "";
  |                 }
  |                 String errorhint = JAASConstants.USER_NOT_AUTHENTICATED;
  |                 if (emsg.indexOf("Password Required") > 0) {
  |                     errorhint = JAASConstants.PASSWORD_INVALID;
  |                 }
  |                 log.debug(username + " " + emsg + " " + errorhint);
  |                 throw new JAASLoginException(errorhint, ex);
  |                     } else {
  |                             log.debug(username + " " + t.getMessage() + " " 
+ JAASConstants.UNEXPECTED_ERROR);
  |                             throw new 
JAASLoginException(JAASConstants.UNEXPECTED_ERROR, t);
  |                     }
  |             }
  |     }
  |     
  |     /**
  |      * Background Login, set user and password from filter. 
  |      */
  |     public void clientLogin(String username, String strPassword) throws 
JAASLoginException {
  |         char[] password  = strPassword != null ? strPassword.toCharArray() 
: "".toCharArray() ;
  |         UsernamePasswordHandler handler = new 
UsernamePasswordHandler(username, password);
  |             try {
  |                     lc = new LoginContext(clientContext, handler);
  |                     lc.login();
  |             } catch (LoginException e) {
  |                     
  |                     throw new 
JAASLoginException(JAASConstants.UNEXPECTED_ERROR);
  |             }
  |     }
  |     
  |     public void logout() throws JAASLoginException {
  |             if (lc == null)
  |                     return;
  |             
  |         try {
  |                     lc.logout();
  |             } catch (LoginException e) {
  |                     log.error("JAAS-Logout failed!", e);
  |                     throw new 
JAASLoginException(JAASConstants.UNEXPECTED_ERROR);
  |             }
  |     }
  |     
  |     /**
  |      * Helper function tests if Strings have a value.
  |      *
  |      * @param s - the String to test.
  |      * @return true or false
  |      */
  |     boolean hasValue(String s) {
  |         return s != null && s.trim().length() != 0 ? true : false;
  |     }
  | }
  | 
  | 

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4258333#4258333

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4258333
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to