<tfoot id='OFJ1T'></tfoot>
    <i id='OFJ1T'><tr id='OFJ1T'><dt id='OFJ1T'><q id='OFJ1T'><span id='OFJ1T'><b id='OFJ1T'><form id='OFJ1T'><ins id='OFJ1T'></ins><ul id='OFJ1T'></ul><sub id='OFJ1T'></sub></form><legend id='OFJ1T'></legend><bdo id='OFJ1T'><pre id='OFJ1T'><center id='OFJ1T'></center></pre></bdo></b><th id='OFJ1T'></th></span></q></dt></tr></i><div id='OFJ1T'><tfoot id='OFJ1T'></tfoot><dl id='OFJ1T'><fieldset id='OFJ1T'></fieldset></dl></div>

      • <bdo id='OFJ1T'></bdo><ul id='OFJ1T'></ul>

        <small id='OFJ1T'></small><noframes id='OFJ1T'>

        <legend id='OFJ1T'><style id='OFJ1T'><dir id='OFJ1T'><q id='OFJ1T'></q></dir></style></legend>
      1. 使用 JSF 2,1 和 LDAP 登录阿帕奇雄猫

        Login with LDAP using JSF 2,1 amp; Apache Tomcat(使用 JSF 2,1 和 LDAP 登录阿帕奇雄猫)

        <small id='mvPiH'></small><noframes id='mvPiH'>

          <legend id='mvPiH'><style id='mvPiH'><dir id='mvPiH'><q id='mvPiH'></q></dir></style></legend>
            <bdo id='mvPiH'></bdo><ul id='mvPiH'></ul>
            <tfoot id='mvPiH'></tfoot>
          • <i id='mvPiH'><tr id='mvPiH'><dt id='mvPiH'><q id='mvPiH'><span id='mvPiH'><b id='mvPiH'><form id='mvPiH'><ins id='mvPiH'></ins><ul id='mvPiH'></ul><sub id='mvPiH'></sub></form><legend id='mvPiH'></legend><bdo id='mvPiH'><pre id='mvPiH'><center id='mvPiH'></center></pre></bdo></b><th id='mvPiH'></th></span></q></dt></tr></i><div id='mvPiH'><tfoot id='mvPiH'></tfoot><dl id='mvPiH'><fieldset id='mvPiH'></fieldset></dl></div>

              <tbody id='mvPiH'></tbody>
                • 本文介绍了使用 JSF 2,1 和 LDAP 登录阿帕奇雄猫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  不仅仅是一个问题,我需要使用 jsf 执行身份验证.我开发了一个登录,它接收存储在 MySQL 中的用户名和密码.从 Active Directory 登录时,这应该使用 AD 的用户名和密码,我想应该与 MySQL 的相同.

                  More than a problem, I need to perform authentication using jsf. I have developed a login, which receives a username and password that are stored in MySQL. Upon login from the Active Directory, this should take the username and password of AD, which, I suppose, should be the same as that of MySQL.

                  然后,进入系统,你不再看到登录,而是直接看到主页或主页.

                  Then, to enter the system, you no longer see the login, but directly the main or home page.

                  希望您的帮助和提前感谢.

                  I hope your help and thanks in advance.

                  您好.

                  推荐答案

                  这是我的解决方案,它对我有用:编辑 faces-config.xml:

                  This my solution, it worked for me: Edit faces-config.xml:

                  <lifecycle>
                          <phase-listener>
                              com.xxx.admin.security.Login
                          </phase-listener>
                      </lifecycle>
                  

                  类登录:

                      public class Login implements PhaseListener {
                      private static final String USER_LOGIN_OUTCOME = "login";
                       @Override
                          public void afterPhase(PhaseEvent event) {
                              FacesContext context = event.getFacesContext();
                              if (userExists(context)) {
                                  // 1. Update last login
                                  // 2. may be expired ???
                                  ExternalContext extContext = context.getExternalContext();
                                  try {
                                      ETT_UserDTL tmpUser = (ETT_UserDTL) extContext.getSessionMap().get(User.USER_SESSION_KEY);
                                      if (!Authenticator.authenticateUser(tmpUser, context)) {
                                          // send the user to the login view
                                          reLogin(context);
                                      } else {
                                          ;
                                      }
                                      // allow processing of the requested view
                                  } catch (Exception ex) {
                                      SystemLogger.getLogger().error(ex);
                                      ClientMessage.logErr(ex.toString());
                                      reLogin(context);
                                  }
                              } else {
                                  // send the user to the login view
                                  reLogin(context);
                              }
                          }
                      private boolean userExists(FacesContext context) {
                      // Need re-check authenticator here.
                      // Check user exist
                      ExternalContext extContext = context.getExternalContext();
                      return (extContext.getSessionMap().containsKey(User.USER_SESSION_KEY));
                  }
                  private void reLogin(FacesContext context) {
                          // send the user to the login view
                          if (requestingSecureView(context)) {
                              context.responseComplete();
                              context.getApplication().
                                      getNavigationHandler().handleNavigation(context,
                                      null,
                                      USER_LOGIN_OUTCOME);
                          } else {
                              ;
                          }
                      }
                      }
                  

                  LDAP认证:

                  public class LDAPAuthentication {
                  
                      static String ATTRIBUTE_FOR_USER = "sAMAccountName";
                  
                      @SuppressWarnings("unchecked")
                      public Attributes authenticateUser(String username, String password, String strDomain, String strHost, String dn) throws NamingException {
                  
                          String searchFilter = "(&(objectClass=user)(" + ATTRIBUTE_FOR_USER + "=" + username + "))";
                          // Create the search controls
                  
                          SearchControls searchCtls = new SearchControls();
                          // searchCtls.setReturningAttributes(returnedAtts);
                          // Specify the search scope
                          searchCtls.setSearchScope(SearchControls.OBJECT_SCOPE);
                          String searchBase = dn;
                          Hashtable environment = new Hashtable();
                          environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                          // Using starndard Port, check your instalation
                          environment.put(Context.PROVIDER_URL, "ldap://" + strHost);
                          environment.put(Context.SECURITY_AUTHENTICATION, "simple");
                  
                          environment.put(Context.SECURITY_PRINCIPAL, username + "@" + strDomain);
                          environment.put(Context.SECURITY_CREDENTIALS, password);
                  
                          LdapContext ctxGC = null;
                          try {
                              ctxGC = new InitialLdapContext(environment, null);
                              // Search for objects in the GC using the filter
                              NamingEnumeration answer = ctxGC.search(searchBase, searchFilter, searchCtls);
                              while (answer.hasMoreElements()) {
                                  SearchResult sr = (SearchResult) answer.next();
                                  Attributes attrs = sr.getAttributes();
                                  if (attrs != null) {
                                      return attrs;
                                  }
                              }
                          } catch (Exception e) {
                              SystemLogger.getLogger().error(e);
                          }
                          return null;
                      }
                  }
                  

                  身份验证:

                  public static boolean authenticateLDAPUser(String strUser, String strPass, String strDomain, String strHost) throws NamingException, Exception {
                          LDAPAuthentication ldap = new LDAPAuthentication();
                          Attributes att = ldap.authenticateUser(strUser, strPass, strDomain, strHost, "");
                          if (att != null) {
                              try {
                                  ETT_UserDTL tmpUser = (ETT_UserDTL) DataUtil.performAction(DATA_UserGUI.class, "getInfByUserName", strUser);
                                  tmpUser.setPassword(strPass);
                                  if (!otherAuthenticate(tmpUser)) {
                                      Authenticator.removeUser();
                                      return false;
                                  } else {
                                      ;
                                  }
                                  pushUser(tmpUser);
                                  return true;
                              } catch (TelsoftException ex) {
                                  SystemLogger.getLogger().error(ex);
                                  return false;
                              }
                          } else {
                              updateLoginFail();
                              return false;
                          }
                      }
                  

                  这篇关于使用 JSF 2,1 和 LDAP 登录阿帕奇雄猫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Slf4j LoggerFactory.getLogger and sonarqube(Slf4j LoggerFactory.getLogger 和 sonarqube)
                  Security - Array is stored directly(安全性 - 数组直接存储)
                  SonarQube quot;Class Not Foundquot; during Main AST Scan(SonarQube“找不到类在主 AST 扫描期间)
                  Integrate Spock#39;s test with Sonar(将 Spock 的测试与声纳集成)
                  How do I make Hudson/Jenkins fail if Sonar thresholds are breached?(如果违反声纳阈值,我如何让 Hudson/Jenkins 失败?)
                  automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)

                • <tfoot id='RuZwy'></tfoot>

                  <i id='RuZwy'><tr id='RuZwy'><dt id='RuZwy'><q id='RuZwy'><span id='RuZwy'><b id='RuZwy'><form id='RuZwy'><ins id='RuZwy'></ins><ul id='RuZwy'></ul><sub id='RuZwy'></sub></form><legend id='RuZwy'></legend><bdo id='RuZwy'><pre id='RuZwy'><center id='RuZwy'></center></pre></bdo></b><th id='RuZwy'></th></span></q></dt></tr></i><div id='RuZwy'><tfoot id='RuZwy'></tfoot><dl id='RuZwy'><fieldset id='RuZwy'></fieldset></dl></div>

                      <bdo id='RuZwy'></bdo><ul id='RuZwy'></ul>

                          <tbody id='RuZwy'></tbody>

                          1. <legend id='RuZwy'><style id='RuZwy'><dir id='RuZwy'><q id='RuZwy'></q></dir></style></legend>
                          2. <small id='RuZwy'></small><noframes id='RuZwy'>