コード例 #1
0
  protected void updateExpandoAttributes(User user, LDAPUser ldapUser) throws Exception {

    ExpandoBridge userExpandoBridge = user.getExpandoBridge();

    populateExpandoAttributes(userExpandoBridge, ldapUser.getUserExpandoAttributes());

    Contact contact = user.getContact();

    ExpandoBridge contactExpandoBridge = contact.getExpandoBridge();

    populateExpandoAttributes(contactExpandoBridge, ldapUser.getContactExpandoAttributes());
  }
コード例 #2
0
  protected User getUser(long companyId, LDAPUser ldapUser) throws Exception {
    User user = null;

    try {
      String authType =
          PrefsPropsUtil.getString(
              companyId,
              PropsKeys.COMPANY_SECURITY_AUTH_TYPE,
              PropsValues.COMPANY_SECURITY_AUTH_TYPE);

      if (authType.equals(CompanyConstants.AUTH_TYPE_SN) && !ldapUser.isAutoScreenName()) {

        user = UserLocalServiceUtil.getUserByScreenName(companyId, ldapUser.getScreenName());
      } else {
        user = UserLocalServiceUtil.getUserByEmailAddress(companyId, ldapUser.getEmailAddress());
      }
    } catch (NoSuchUserException nsue) {
    }

    return user;
  }
コード例 #3
0
ファイル: LDAPManager.java プロジェクト: e-admin/allocalgis
  public Vector<LDAPUser> getUserListLDAP() throws LDAPException {

    LDAPConnection connection = connectionPool.getConnection();

    /*patron para la busqueda de todos los usuarios*/
    String attb = "(" + atributoRol + "=" + rol + ")";

    /*buequeda de todos los usuarios que cumplan el patron*/
    LDAPSearchResults results = connection.search(base, LDAPv3.SCOPE_SUB, attb, null, false);

    LDAPAttribute ldapAttribute = null;
    LDAPUser usuario = null;
    LDAPEntry ldapEntry = null;

    Vector<LDAPUser> listUsers = new Vector<LDAPUser>();

    /*guardamos los usuarios en un array de usuarios con la información que nos interesa*/
    while (results.hasMoreElements()) {
      usuario = new LDAPUser();
      usuario = inicilizaUsuario(usuario);
      ldapEntry = (LDAPEntry) results.next();
      ldapAttribute = ldapEntry.getAttribute("uid");
      usuario.setName(ldapAttribute.getStringValues().nextElement().toString().toUpperCase());
      ldapAttribute = ldapEntry.getAttribute("cn");
      usuario.setNombreCompleto(ldapAttribute.getStringValues().nextElement().toString());
      ldapAttribute = ldapEntry.getAttribute("sn");
      usuario.setNombre(ldapAttribute.getStringValues().nextElement().toString());
      ldapAttribute = ldapEntry.getAttribute("mail");
      if (ldapAttribute != null) {
        usuario.setMail(ldapAttribute.getStringValues().nextElement().toString());
      }

      listUsers.add(usuario);
    }

    connectionPool.close(connection);

    return listUsers;
  }
コード例 #4
0
 public LDAPUser login(String aUserName, String aPassword) throws InvalidLoginException {
   LDAPUser onlineUser = null;
   try {
     connection.connect(ldapHost, ldapPort);
     System.out.println("Connect Successfull");
     System.out.println(aUserName);
     LDAPSearchQueue searchResults =
         connection.search(
             "o=Aerothai",
             LDAPConnection.SCOPE_SUB,
             "cn=" + aUserName,
             new String[] {LDAPConnection.NO_ATTRS},
             true,
             (LDAPSearchQueue) null);
     LDAPMessage message;
     message = searchResults.getResponse();
     if (message instanceof LDAPSearchResult) {
       LDAPEntry entry = ((LDAPSearchResult) message).getEntry();
       String dn = entry.getDN();
       String[] userDn = dn.split(",");
       String fullDn = userDn[0] + "," + userDn[1] + "," + userDn[2] + ",o=Aerothai";
       connection.bind(ldapVersion, fullDn, aPassword.getBytes("UTF8"));
       System.out.println("Bind Successfull");
       onlineUser = new LDAPUser();
       try {
         onlineUser.setFirstName((String) getAttribute(fullDn, "givenName").elementAt(0));
         onlineUser.setLastName((String) getAttribute(fullDn, "sn").elementAt(0));
         try {
           Integer.parseInt((String) getAttribute(fullDn, "cn").elementAt(1));
           onlineUser.setEmployeeCode((String) getAttribute(fullDn, "cn").elementAt(1));
         } catch (NumberFormatException e) {
           onlineUser.setEmployeeCode((String) getAttribute(fullDn, "cn").elementAt(0));
         }
         onlineUser.setDepartment((String) getAttribute(fullDn, "ou").elementAt(0));
         onlineUser.setLocation((userDn[2].split("="))[1]);
       } catch (ArrayIndexOutOfBoundsException e1) {
         e1.printStackTrace();
         onlineUser = null;
         throw new InvalidLoginException(
             "à¡Ô´¤ÇÒÁ¼Ô´¾ÅÒ´ÃÐËÇèÒ§¡Òô֧¢éÍÁÙÅ ¡ÃØ³Ò Login ãËÁèÍÕ¡¤ÃÑé§");
       }
     } else {
       disconnect();
       throw new InvalidLoginException(
           "äÁ辺¼Ùéãªé§Ò¹ª×èÍ "
               + aUserName
               + " ¡ÃسÒÅͧÍÕ¡¤ÃÑé§ ËÃ×Í µÔ´µèÍà¨éÒ˹éÒ·Õè¡Í§Ç¤.¾Ç. à¾×è͵ÃǨÊͺ¢éÍÁÙŢͧ·èÒ¹");
     }
     disconnect();
   } catch (LDAPException e) {
     e.printStackTrace();
     throw new InvalidLoginException(
         "ÃËÑʼèÒ¹äÁè¶Ù¡µéͧ ¡ÃسÒÅͧÍÕ¡¤ÃÑé§ ËÃ×Í µÔ´µèÍà¨éÒ˹éÒ·Õè¡Í§Ç¤.¾Ç. à¾×è͵ÃǨÊͺ¢éÍÁÙŢͧ·èÒ¹");
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
     throw new InvalidLoginException(e);
   } finally {
     disconnect();
   }
   return onlineUser;
 }
コード例 #5
0
  protected User addUser(long companyId, LDAPUser ldapUser, String password) throws Exception {

    if (_log.isDebugEnabled()) {
      _log.debug("Adding user " + ldapUser.getEmailAddress());
    }

    boolean autoPassword = ldapUser.isAutoPassword();

    if (!PropsValues.LDAP_IMPORT_USER_PASSWORD_ENABLED) {
      autoPassword = PropsValues.LDAP_IMPORT_USER_PASSWORD_AUTOGENERATED;

      if (!autoPassword) {
        String defaultPassword = PropsValues.LDAP_IMPORT_USER_PASSWORD_DEFAULT;

        if (defaultPassword.equalsIgnoreCase(_USER_PASSWORD_SCREEN_NAME)) {

          defaultPassword = ldapUser.getScreenName();
        }

        password = defaultPassword;
      }
    }

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(ldapUser.getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    User user =
        UserLocalServiceUtil.addUser(
            ldapUser.getCreatorUserId(),
            companyId,
            autoPassword,
            password,
            password,
            ldapUser.isAutoScreenName(),
            ldapUser.getScreenName(),
            ldapUser.getEmailAddress(),
            0,
            StringPool.BLANK,
            ldapUser.getLocale(),
            ldapUser.getFirstName(),
            ldapUser.getMiddleName(),
            ldapUser.getLastName(),
            0,
            0,
            ldapUser.isMale(),
            birthdayMonth,
            birthdayDay,
            birthdayYear,
            StringPool.BLANK,
            ldapUser.getGroupIds(),
            ldapUser.getOrganizationIds(),
            ldapUser.getRoleIds(),
            ldapUser.getUserGroupIds(),
            ldapUser.isSendEmail(),
            ldapUser.getServiceContext());

    if (ldapUser.isUpdatePortrait()) {
      byte[] portraitBytes = ldapUser.getPortraitBytes();

      if ((portraitBytes != null) && (portraitBytes.length > 0)) {
        user = UserLocalServiceUtil.updatePortrait(user.getUserId(), portraitBytes);
      }
    }

    return user;
  }
コード例 #6
0
  protected User updateUser(
      long companyId, LDAPUser ldapUser, User user, String password, String modifiedDate)
      throws Exception {

    Date ldapUserModifiedDate = null;

    try {
      if (Validator.isNull(modifiedDate)) {
        if (_log.isInfoEnabled()) {
          _log.info("LDAP entry never modified, skipping user " + user.getEmailAddress());
        }

        return user;
      } else {
        ldapUserModifiedDate = LDAPUtil.parseDate(modifiedDate);
      }

      if (ldapUserModifiedDate.equals(user.getModifiedDate()) && ldapUser.isAutoPassword()) {

        if (_log.isDebugEnabled()) {
          _log.debug("User is already synchronized, skipping user " + user.getEmailAddress());
        }

        return user;
      }
    } catch (ParseException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug("Unable to parse LDAP modify timestamp " + modifiedDate, pe);
      }
    }

    boolean passwordReset = ldapUser.isPasswordReset();

    if (PrefsPropsUtil.getBoolean(
        companyId, PropsKeys.LDAP_EXPORT_ENABLED, PropsValues.LDAP_EXPORT_ENABLED)) {

      passwordReset = user.isPasswordReset();
    }

    if (!PropsValues.LDAP_IMPORT_USER_PASSWORD_ENABLED) {
      password = PropsValues.LDAP_IMPORT_USER_PASSWORD_DEFAULT;

      if (password.equalsIgnoreCase(_USER_PASSWORD_SCREEN_NAME)) {
        password = ldapUser.getScreenName();
      }
    }

    if (Validator.isNull(ldapUser.getScreenName())) {
      ldapUser.setAutoScreenName(true);
    }

    if (ldapUser.isAutoScreenName()) {
      ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

      ldapUser.setScreenName(
          screenNameGenerator.generate(companyId, user.getUserId(), ldapUser.getEmailAddress()));
    }

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(user.getContact().getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    if (ldapUser.isUpdatePassword()) {
      UserLocalServiceUtil.updatePassword(
          user.getUserId(), password, password, passwordReset, true);
    }

    Contact contact = user.getContact();

    Set<String> ldapIgnoreAttributes = SetUtil.fromArray(PropsValues.LDAP_USER_IGNORE_ATTRIBUTES);

    for (String attribute : ldapIgnoreAttributes) {
      Object value = BeanPropertiesUtil.getObjectSilent(user, attribute);

      if (value == null) {
        value = BeanPropertiesUtil.getObjectSilent(contact, attribute);
      }

      if (value != null) {
        BeanPropertiesUtil.setProperty(ldapUser, attribute, value);
      }
    }

    updateLDAPUser(ldapUser.getUser(), ldapUser.getContact(), user);

    user =
        UserLocalServiceUtil.updateUser(
            user.getUserId(),
            password,
            StringPool.BLANK,
            StringPool.BLANK,
            passwordReset,
            ldapUser.getReminderQueryQuestion(),
            ldapUser.getReminderQueryAnswer(),
            ldapUser.getScreenName(),
            ldapUser.getEmailAddress(),
            ldapUser.getFacebookId(),
            ldapUser.getOpenId(),
            ldapUser.getLanguageId(),
            ldapUser.getTimeZoneId(),
            ldapUser.getGreeting(),
            ldapUser.getComments(),
            ldapUser.getFirstName(),
            ldapUser.getMiddleName(),
            ldapUser.getLastName(),
            ldapUser.getPrefixId(),
            ldapUser.getSuffixId(),
            ldapUser.isMale(),
            birthdayMonth,
            birthdayDay,
            birthdayYear,
            ldapUser.getSmsSn(),
            ldapUser.getAimSn(),
            ldapUser.getFacebookSn(),
            ldapUser.getIcqSn(),
            ldapUser.getJabberSn(),
            ldapUser.getMsnSn(),
            ldapUser.getMySpaceSn(),
            ldapUser.getSkypeSn(),
            ldapUser.getTwitterSn(),
            ldapUser.getYmSn(),
            ldapUser.getJobTitle(),
            ldapUser.getGroupIds(),
            ldapUser.getOrganizationIds(),
            ldapUser.getRoleIds(),
            ldapUser.getUserGroupRoles(),
            ldapUser.getUserGroupIds(),
            ldapUser.getServiceContext());

    if (ldapUserModifiedDate != null) {
      user = UserLocalServiceUtil.updateModifiedDate(user.getUserId(), ldapUserModifiedDate);
    }

    if (ldapUser.isUpdatePortrait()) {
      byte[] portraitBytes = ldapUser.getPortraitBytes();

      if ((portraitBytes != null) && (portraitBytes.length > 0)) {
        UserLocalServiceUtil.updatePortrait(user.getUserId(), portraitBytes);
      } else {
        UserLocalServiceUtil.deletePortrait(user.getUserId());
      }
    }

    return user;
  }