Package org.jivesoftware.openfire.user

Examples of org.jivesoftware.openfire.user.UserManager


  }

  private List<String> importUsers(Document document, String previousDomain) {
    List<String> invalidUsers = new ArrayList<String>();

    UserManager userManager = UserManager.getInstance();
    RosterItemProvider rosterItemProvider = RosterItemProvider
        .getInstance();

    Element users = document.getRootElement();

    Iterator usersIter = users.elementIterator("User");
    while (usersIter.hasNext()) {
      Element user = (Element) usersIter.next();

      String userName = null;
      String password = null;
      String email = null;
      String name = null;
      List<RosterItem> rosterItems = new ArrayList<RosterItem>();

      Iterator userElements = user.elementIterator();
      while (userElements.hasNext()) {
        Element userElement = (Element) userElements.next();

        String nameElement = userElement.getName();
        if ("Username".equals(nameElement)) {
          userName = userElement.getText();
        } else if ("Password".equals(nameElement)) {
          password = userElement.getText();
        } else if ("Name".equals(nameElement)) {
          name = userElement.getText();
        } else if ("Email".equals(nameElement)) {
          email = userElement.getText();
        } else if ("Roster".equals(nameElement)) {
          Iterator rosterIter = userElement.elementIterator("Item");

          while (rosterIter.hasNext()) {
            Element rosterElement = (Element) rosterIter.next();

            String jid = rosterElement.attributeValue("jid");
            String askstatus = rosterElement
                .attributeValue("askstatus");
            String recvstatus = rosterElement
                .attributeValue("recvstatus");
            String substatus = rosterElement
                .attributeValue("substatus");
            String nickname = rosterElement.attributeValue("name");

            List<String> groups = new ArrayList<String>();
            Iterator groupIter = rosterElement
                .elementIterator("Group");
            while (groupIter.hasNext()) {
              Element group = (Element) groupIter.next();
              groups.add(group.getText());
            }

            // used for migration
            if (previousDomain != null) {
              jid = jid.replace(previousDomain, serverName);
            }

            rosterItems.add(new RosterItem(new JID(jid),
                RosterItem.SubType.getTypeFromInt(Integer
                    .parseInt(substatus)),
                RosterItem.AskType.getTypeFromInt(Integer
                    .parseInt(askstatus)),
                RosterItem.RecvType.getTypeFromInt(Integer
                    .parseInt(recvstatus)), nickname,
                groups));
          }
        }
      }

      if ((userName != null) && (password != null)) {
        try {
          userName = Stringprep.nodeprep(userName);

          if (!isUserProviderReadOnly()) {
            userManager.createUser(userName, password, name, email);
          }

          // Check to see user exists before adding their roster, this
          // is for read-only user providers.
          userManager.getUser(userName);
          for (RosterItem ri : rosterItems) {
            rosterItemProvider.createItem(userName, ri);
          }
        } catch (StringprepException se) {
          Log.info("Invalid username " + userName);
View Full Code Here


        if (authCache != null) {
            authCache.put(username, StringUtils.hash(password));
        }

        // See if the user exists in the database. If not, automatically create them.
        UserManager userManager = UserManager.getInstance();
        try {
            userManager.getUser(username);
        }
        catch (UserNotFoundException unfe) {
            String email = username + "@" + (domain!=null?domain:host);
            try {
                Log.debug("POP3AuthProvider: Automatically creating new user account for " + username);
View Full Code Here

        catch (Exception e) {
            throw new UnauthorizedException(e);
        }

        // See if the user exists in the database. If not, automatically create them.
        UserManager userManager = UserManager.getInstance();
        try {
            userManager.getUser(username);
        }
        catch (UserNotFoundException unfe) {
            try {
                Log.debug("Automatically creating new user account for " + username);
                // Create user; use a random password for better safety in the future.
View Full Code Here

        emailField.setVariable("email");

        FormField nameField = form.addField();
        nameField.setVariable("name");

        UserManager manager = UserManager.getInstance();
        for(String account : accounts) {
            User user;
            try {
                JID jid = new JID(account);
                user = manager.getUser(jid.getNode());
            }
            catch (Exception ex) {
                continue;
            }
View Full Code Here

    }
   
    private List<String> importUsers(Document document, String previousDomain) {
        List<String> invalidUsers = new ArrayList<String>();
       
        UserManager userManager = UserManager.getInstance();
        RosterItemProvider rosterItemProvider = RosterItemProvider.getInstance();
       
        Element users = document.getRootElement();
       
        Iterator<Element> usersIter = users.elementIterator("User");
        while (usersIter.hasNext()) {
            Element user = usersIter.next();
           
            String userName = null;
            String password = null;
            String email = null;
            String name = null;
            List<RosterItem> rosterItems = new ArrayList<RosterItem>();
           
            Iterator<Element> userElements = user.elementIterator();
            while (userElements.hasNext()) {
                Element userElement = userElements.next();
               
                String nameElement = userElement.getName();
                if ("Username".equals(nameElement)) {
                    userName = userElement.getText();
                }
                else if ("Password".equals(nameElement)) {
                    password = userElement.getText();
                }
                else if ("Name".equals(nameElement)) {
                    name = userElement.getText();
                }
                else if ("Email".equals(nameElement)) {
                    email = userElement.getText();
                }
                else if ("Roster".equals(nameElement)) {
                    Iterator<Element> rosterIter = userElement.elementIterator("Item");
                   
                    while (rosterIter.hasNext()) {
                        Element rosterElement = rosterIter.next();
                       
                        String jid = rosterElement.attributeValue("jid");
                        String askstatus = rosterElement.attributeValue("askstatus");
                        String recvstatus = rosterElement.attributeValue("recvstatus");
                        String substatus = rosterElement.attributeValue("substatus");
                        String nickname = rosterElement.attributeValue("name");
                       
                        List<String> groups = new ArrayList<String>();
                        Iterator<Element> groupIter = rosterElement.elementIterator("Group");
                        while (groupIter.hasNext()) {
                            Element group = groupIter.next();
                            String groupName = group.getText();
                            if (groupName != null && groupName.trim().length() > 0) {
                                groups.add(groupName);
                            }
                        }
                       
                        //used for migration
                        if (previousDomain != null) {
                            jid = jid.replace(previousDomain, serverName);
                        }
                       
                        rosterItems.add(new RosterItem(new JID(jid),
                                        RosterItem.SubType.getTypeFromInt(Integer.parseInt(substatus)),
                                        RosterItem.AskType.getTypeFromInt(Integer.parseInt(askstatus)),
                                        RosterItem.RecvType.getTypeFromInt(Integer.parseInt(recvstatus)),
                                        nickname,
                                        groups));
                    }
                }
            }
           
            if ((userName != null) && (password != null)) {
                try {
                    userName = Stringprep.nodeprep(userName);
                   
                    if (!isUserProviderReadOnly()) {
                       userManager.createUser(userName, password, name, email);
                    }
                   
                    //Check to see user exists before adding their roster, this is for read-only user providers.
                    userManager.getUser(userName);
                    for (RosterItem ri : rosterItems) {
                       rosterItemProvider.createItem(userName, ri);
                    }
                }
                catch (StringprepException se) {
View Full Code Here

     * @param jid      the users jid.
     * @param bookmark the bookmark to be added.
     * @param element  the storage element to append to.
     */
    private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
        final UserManager userManager = UserManager.getInstance();

        try {
            userManager.getUser(jid.getNode());
        }
        catch (UserNotFoundException e) {
            return;
        }

View Full Code Here

     *
     * @param username the username.
     */
    private static void createUser(String username) {
        // See if the user exists in the database. If not, automatically create them.
        UserManager userManager = UserManager.getInstance();
        try {
            userManager.getUser(username);
        }
        catch (UserNotFoundException unfe) {
            try {
                Log.debug("JDBCAuthProvider: Automatically creating new user account for " + username);
                UserManager.getUserProvider().createUser(username, StringUtils.randomString(8),
View Full Code Here

        // Do nothing
    }

    public void createUsers(String userPrefix, int from, int total) {
        // Create users
        UserManager userManager = XMPPServer.getInstance().getUserManager();
        System.out.println("Creating users accounts: " + total);
        int created = 0;
        for (int i = from; i < from + total; i++) {
            try {
                String username = userPrefix + i;
                userManager.createUser(username, username, username, username + "@" + username);
                created++;
            } catch (UserAlreadyExistsException e) {
                // Ignore
            }
        }
View Full Code Here

        // NOTE: Do not sent to the customer. They will receive a prompt for a seperate chat transcript
        // that does not contain agent information.

        // Send to Agents
        UserManager um = UserManager.getInstance();
        for (Iterator<AgentChatSession> iterator = chatSession.getAgents(); iterator.hasNext();) {
            AgentChatSession agentSession = iterator.next();
            try {
                User user = um.getUser(new JID(agentSession.getAgentJID()).getNode());
                emailService.sendMessage("Chat Transcript", user.getEmail(), "Chat Transcript", from, subject, builder.toString(), null);
                Log.debug("Transcript sent to agent " + agentSession.getAgentJID());
            }
            catch (UserNotFoundException e) {
                Log.error("Email Transcript Not Sent:" +
View Full Code Here

        Element iq = packet.getChildElement();
        Attribute attr = iq.attribute("jid");
        if (attr != null && ModelUtil.hasLength(iq.attribute("jid").getText())) {
            String jid = iq.attribute("jid").getText();
            UserManager userManager = UserManager.getInstance();
            try {
                User user = userManager.getUser(new JID(jid).getNode());
                String email = user.getEmail();
                String fullName = user.getName();
                returnPacket.addElement("email").setText(email);
                returnPacket.addElement("name").setText(fullName);
            }
View Full Code Here

TOP

Related Classes of org.jivesoftware.openfire.user.UserManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.