Search in sources :

Example 41 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class OpenfireExporter method exportUsers.

/* (non-Javadoc)
   * @see org.jivesoftware.openfire.plugin.Exporter#exportUsers()
   */
@Override
public Document exportUsers() {
    Log.debug("exportUsers");
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("Openfire");
    Collection<User> users = userManager.getUsers();
    for (User user : users) {
        Element userElement = root.addElement("User");
        String userName = user.getUsername();
        userElement.addElement("Username").addText(userName);
        try {
            String pw = AuthFactory.getPassword(user.getUsername());
            userElement.addElement("Password").addText(pw);
        } catch (UserNotFoundException e) {
            Log.info("User " + userName + " not found, setting their password to their username");
            userElement.addElement("Password").addText(userName);
        } catch (UnsupportedOperationException e) {
            Log.info("Unable to retrieve " + userName + " password, setting their password to their username");
            userElement.addElement("Password").addText(userName);
        }
        userElement.addElement("Email").addText(user.getEmail() == null ? "" : user.getEmail());
        String name = user.getName();
        userElement.addElement("Name").addText(name == null ? "" : name);
        //creation and modified date are not used as part of the import process but are exported
        //for historical purposes, should they be formatted differently?
        userElement.addElement("CreationDate").addText(String.valueOf(user.getCreationDate().getTime()));
        userElement.addElement("ModifiedDate").addText(String.valueOf(user.getModificationDate().getTime()));
        Element rosterElement = userElement.addElement("Roster");
        Collection<RosterItem> roster = user.getRoster().getRosterItems();
        for (RosterItem ri : roster) {
            Element itemElement = rosterElement.addElement("Item");
            itemElement.addAttribute("jid", ri.getJid().toBareJID());
            itemElement.addAttribute("askstatus", String.valueOf(ri.getAskStatus().getValue()));
            itemElement.addAttribute("recvstatus", String.valueOf(ri.getRecvStatus().getValue()));
            itemElement.addAttribute("substatus", String.valueOf(ri.getSubStatus().getValue()));
            itemElement.addAttribute("name", ri.getNickname());
            List<String> groups = ri.getGroups();
            for (String group : groups) {
                if (group != null && group.trim().length() > 0) {
                    itemElement.addElement("Group").addText(group);
                }
            }
        }
    }
    return document;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) User(org.jivesoftware.openfire.user.User) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 42 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class Xep227ExporterTest method setUp.

/**
   * @throws java.lang.Exception
   */
@Before
public void setUp() throws Exception {
    URL url = this.getClass().getResource("test-openfire.xml");
    File f = new File(url.getFile());
    JiveGlobals.setConfigName(f.getName());
    JiveGlobals.setHomeDirectory(f.getParent());
    JiveGlobals.setProperty("provider.user.className", "org.jivesoftware.openfire.plugin.TestUserProvider");
    offlineMessagesStore = new TestOfflineMessageStore();
    vCardManager = new TestVCardManager();
    privateStorage = null;
    userManager = UserManager.getInstance();
    rosterItemProvider = new TestRosterItemProvider();
    //Empty users
    List<User> l = new ArrayList<>(userManager.getUsers());
    for (User user : l) {
        userManager.deleteUser(user);
    }
}
Also used : User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 43 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class Xep227ExporterTest method testImportXInclude.

/**
   * Test if XInclude is working
   * 
   * @throws IOException 
   * @throws DocumentException 
   * 
   */
@Test
public void testImportXInclude() throws DocumentException, IOException {
    logger.finest("testImportIncludeUser");
    InExporter testobject = new Xep227Exporter("serverName", offlineMessagesStore, vCardManager, privateStorage, userManager, rosterItemProvider);
    String IMPORT_FILE_NAME = "/test-export-xinclude/xep227.xml";
    URL streamurl = this.getClass().getResource(IMPORT_FILE_NAME);
    assertNotNull(streamurl);
    logger.fine("testImportIncludeUser:" + streamurl.getFile());
    InputStream stream = new FileInputStream(streamurl.getFile());
    assertTrue("Invalid input", testobject.validate(stream));
    stream.close();
    String previousDomain = null;
    boolean isUserProviderReadOnly = false;
    stream = this.getClass().getResourceAsStream(IMPORT_FILE_NAME);
    List<String> res = testobject.importUsers(stream, previousDomain, isUserProviderReadOnly);
    assertNotNull(res);
    assertEquals(0, res.size());
    stream.close();
    Collection<User> users = userManager.getUsers();
    assertEquals(2, users.size());
}
Also used : User(org.jivesoftware.openfire.user.User) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URL(java.net.URL) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 44 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserServicePlugin method deleteUser.

public void deleteUser(String username) throws UserNotFoundException, SharedGroupException {
    User user = getUser(username);
    userManager.deleteUser(user);
    rosterManager.deleteRoster(server.createJID(username, null));
}
Also used : User(org.jivesoftware.openfire.user.User)

Example 45 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserServicePlugin method getUserGroups.

/**
	 * Returns all group names or an empty collection for specific user
	 * 
	 */
public Collection<String> getUserGroups(String username) throws UserNotFoundException {
    User user = getUser(username);
    Collection<Group> groups = GroupManager.getInstance().getGroups(user);
    Collection<String> groupNames = new ArrayList<String>();
    for (Group group : groups) {
        groupNames.add(group.getName());
    }
    return groupNames;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList)

Aggregations

User (org.jivesoftware.openfire.user.User)58 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)17 UserManager (org.jivesoftware.openfire.user.UserManager)10 ArrayList (java.util.ArrayList)9 Group (org.jivesoftware.openfire.group.Group)9 IQ (org.xmpp.packet.IQ)7 List (java.util.List)6 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)6 RosterItem (org.jivesoftware.openfire.roster.RosterItem)5 Date (java.util.Date)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 Message (org.xmpp.packet.Message)4 Presence (org.xmpp.packet.Presence)4 HashSet (java.util.HashSet)3 StringTokenizer (java.util.StringTokenizer)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2